Skip to content

Commit 0bd2a39

Browse files
committed
docs: fix and add jsdocs to promise.js for tsc inference
1 parent 31bed66 commit 0bd2a39

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

promise.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const { Database: NativeDb, connect: nativeConnect } = require("./index.js");
44
const SqliteError = require("./sqlite-error.js");
55
const Authorization = require("./auth");
66

7+
/**
8+
* @import {Options as NativeOptions, Statement as NativeStatement} from './index.js'
9+
*/
10+
711
function convertError(err) {
812
// Handle errors from Rust with JSON-encoded message
913
if (typeof err.message === 'string') {
@@ -32,7 +36,7 @@ function convertError(err) {
3236
* Creates a new database connection.
3337
*
3438
* @param {string} path - Path to the database file.
35-
* @param {object} opts - Options.
39+
* @param {NativeOptions} opts - Options.
3640
*/
3741
const connect = async (path, opts) => {
3842
const db = await nativeConnect(path, opts);
@@ -47,7 +51,7 @@ class Database {
4751
* Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
4852
*
4953
* @constructor
50-
* @param {string} path - Path to the database file.
54+
* @param {NativeDb} db - Database object
5155
*/
5256
constructor(db) {
5357
this.db = db;
@@ -124,6 +128,12 @@ class Database {
124128
return properties.default.value;
125129
}
126130

131+
/**
132+
* Execute a pragma statement
133+
* @param {string} source - The pragma statement to execute, without the `PRAGMA` prefix.
134+
* @param {object} [options] - Options object.
135+
* @param {boolean} [options.simple] - If true, return a single value for single-column results.
136+
*/
127137
async pragma(source, options) {
128138
if (options == null) options = {};
129139
if (typeof source !== 'string') throw new TypeError('Expected first argument to be a string');
@@ -161,6 +171,10 @@ class Database {
161171
}
162172
}
163173

174+
/**
175+
* Loads an extension into the database
176+
* @param {Parameters<NativeDb['loadExtension']>} args - Arguments to pass to the underlying loadExtension method
177+
*/
164178
loadExtension(...args) {
165179
try {
166180
this.db.loadExtension(...args);
@@ -211,6 +225,7 @@ class Database {
211225

212226
/**
213227
* Toggle 64-bit integer support.
228+
* @param {boolean} [toggle] - Whether to use safe integers by default.
214229
*/
215230
defaultSafeIntegers(toggle) {
216231
this.db.defaultSafeIntegers(toggle);
@@ -226,14 +241,17 @@ class Database {
226241
* Statement represents a prepared SQL statement that can be executed.
227242
*/
228243
class Statement {
244+
/**
245+
* @param {NativeStatement} stmt
246+
*/
229247
constructor(stmt) {
230248
this.stmt = stmt;
231249
}
232250

233251
/**
234252
* Toggle raw mode.
235253
*
236-
* @param raw Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
254+
* @param {boolean} [raw] - Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
237255
*/
238256
raw(raw) {
239257
this.stmt.raw(raw);
@@ -243,7 +261,7 @@ class Statement {
243261
/**
244262
* Toggle pluck mode.
245263
*
246-
* @param pluckMode Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
264+
* @param {boolean} [pluckMode] - Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
247265
*/
248266
pluck(pluckMode) {
249267
this.stmt.pluck(pluckMode);
@@ -253,7 +271,7 @@ class Statement {
253271
/**
254272
* Toggle query timing.
255273
*
256-
* @param timing Enable or disable query timing. If you don't pass the parameter, query timing is enabled.
274+
* @param {boolean} [timingMode] - Enable or disable query timing. If you don't pass the parameter, query timing is enabled.
257275
*/
258276
timing(timingMode) {
259277
this.stmt.timing(timingMode);

0 commit comments

Comments
 (0)