Skip to content

feature: expanded sql api #1407

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', 'john@example.com');
console.log(stmt.expandedSQL); // "INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com')"

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

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions