Skip to content

feature: expanded sql api #1407

@smith-xyz

Description

@smith-xyz

With sqlite3_expanded_sql() you can retrieve the expanded version of the sql statement with the bindings. This is useful mostly for debugging purposes but could be useful if one has a disaster recovery process utilizing the prepared sql statements. Since its part of the sqlite api it seems to be a nice to have.

const db = new Database(':memory:');
db.exec('CREATE TABLE users (id INTEGER, name TEXT, email TEXT)');

const stmt = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)');
console.log(stmt.source); // "INSERT INTO users (name, email) VALUES (?, ?)"
console.log(stmt.expandedSQL); // "INSERT INTO users (name, email) VALUES (?, ?)" (no bindings yet)

stmt.bind('John Doe', '[email protected]');
console.log(stmt.expandedSQL); // "INSERT INTO users (name, email) VALUES ('John Doe', '[email protected]')"

I'm willing to work on this feature if it makes sense to add for better-sqlite3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions