Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const { Database: NativeDb, connect: nativeConnect } = require("./index.js");
const SqliteError = require("./sqlite-error.js");
const Authorization = require("./auth");

/**
* @import {Options as NativeOptions, Statement as NativeStatement} from './index.js'
*/

function convertError(err) {
// Handle errors from Rust with JSON-encoded message
if (typeof err.message === 'string') {
Expand Down Expand Up @@ -32,7 +36,7 @@ function convertError(err) {
* Creates a new database connection.
*
* @param {string} path - Path to the database file.
* @param {object} opts - Options.
* @param {NativeOptions} opts - Options.
*/
const connect = async (path, opts) => {
const db = await nativeConnect(path, opts);
Expand All @@ -47,7 +51,7 @@ class Database {
* Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
*
* @constructor
* @param {string} path - Path to the database file.
* @param {NativeDb} db - Database object
*/
constructor(db) {
this.db = db;
Expand Down Expand Up @@ -124,6 +128,12 @@ class Database {
return properties.default.value;
}

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

/**
* Loads an extension into the database
* @param {Parameters<NativeDb['loadExtension']>} args - Arguments to pass to the underlying loadExtension method
*/
loadExtension(...args) {
try {
this.db.loadExtension(...args);
Expand Down Expand Up @@ -211,6 +225,7 @@ class Database {

/**
* Toggle 64-bit integer support.
* @param {boolean} [toggle] - Whether to use safe integers by default.
*/
defaultSafeIntegers(toggle) {
this.db.defaultSafeIntegers(toggle);
Expand All @@ -226,14 +241,17 @@ class Database {
* Statement represents a prepared SQL statement that can be executed.
*/
class Statement {
/**
* @param {NativeStatement} stmt
*/
constructor(stmt) {
this.stmt = stmt;
}

/**
* Toggle raw mode.
*
* @param raw Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
* @param {boolean} [raw] - Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
*/
raw(raw) {
this.stmt.raw(raw);
Expand All @@ -243,7 +261,7 @@ class Statement {
/**
* Toggle pluck mode.
*
* @param pluckMode Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
* @param {boolean} [pluckMode] - Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
*/
pluck(pluckMode) {
this.stmt.pluck(pluckMode);
Expand All @@ -253,7 +271,7 @@ class Statement {
/**
* Toggle query timing.
*
* @param timing Enable or disable query timing. If you don't pass the parameter, query timing is enabled.
* @param {boolean} [timingMode] - Enable or disable query timing. If you don't pass the parameter, query timing is enabled.
*/
timing(timingMode) {
this.stmt.timing(timingMode);
Expand Down
Loading