Skip to content

sqlite: db.prepare(sql, options) #61235

@mike-git374

Description

@mike-git374

Problem

Currently you need multiple js statements to declare a single SQLite statement with options like returnArrays, readBigInts etc. This requires multiple lines and can be inefficient to call c++ multiple times:

const q = db.prepare(sql);
q.setReturnArrays(true);
q.setReadBigInts(true);
q.setAllowBareNamedParameters(true);
q.setAllowUnknownNamedParameters(true);

Proposal 1

Allow chaining statement.set* functions by returning the sql statement instead of undefined. This allows declaring a sql statement with 1 JS statement. This still requires multiple function calls but is slightly better DX developer experience using the existing set* functions:

// before
const q = db.prepare(sql);
q.setReturnArrays(true);

// after
const q = db.prepare(sql).setReturnArrays(true);

// more example
const q = db.prepare(sql).setReturnArrays(true).setReadBigInts(true);

PR: #61263

Proposal 2

Add options argument: db.prepare(sql[, options])

// before
const q = db.prepare(sql);
q.setReturnArrays(true);

// after
const q = db.prepare(sql, { returnArrays: true });

// more example
const q = db.prepare(sql, { returnArrays: true, readBigInts: true });

In this case I recommend to remove the statement.set* functions to simplify the API, you only need db.prepare(sql[, options])

Proposal 3

Do both Proposal 1 and Proposal 2. Currently I am leaning towards Proposal 2 and removing set* functions

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.sqliteIssues and PRs related to the SQLite subsystem.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions