Skip to content

sqlite: add DatabaseSync.prototype.pragma() #62722

@thisalihassan

Description

@thisalihassan

What is the problem this feature will solve?

node:sqlite already supports PRAGMA statements through raw SQL but using them is more awkward than it needs to be.
Today users need to know which API shape to use for each case:

db.exec('PRAGMA foreign_keys = ON');
const mode = db.prepare('PRAGMA journal_mode').get().journal_mode;
const columns = db.prepare('PRAGMA table_info(users)').all();

This works, but it is not very discoverable and it forces users to switch between exec(), get() and all()

A dedicated pragma() helper would make common sqlite configuration and introspection easier to read, easier to teach and closer to what users may already expect from libraries like better-sqlite3.

What is the feature you are proposing to solve the problem?

Add a database.pragma() helper to node:sqlite, initially on DatabaseSync.
Example shape:

db.pragma('foreign_keys = ON');
const mode = db.pragma('journal_mode', { simple: true });
const columns = db.pragma('table_info(users)');

Possible behavior mimicking popular libraries:

  • accept a PRAGMA body string such as 'journal_mode = WAL' or 'table_info(users)'
  • return all rows by default
  • optionally support { simple: true } to return the first column of the first row for common scalar PRAGMAs

This would be an ergonomic wrapper over functionality that already exists via raw SQL, not a new SQLite capability.

What alternatives have you considered?

  1. Continue using raw SQL with exec() / prepare().get() / prepare().all().
    This works today but it is more verbose and requires users to remember which call shape matches each PRAGMA use case.
  2. Leave this entirely to userland helpers

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussIssues opened for discussions and feedbacks.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