Skip to content

docs: sqlite statement.setAllowBareNamedParameters() #61823

@mike-git374

Description

@mike-git374

Affected URL(s)

https://nodejs.org/docs/latest/api/sqlite.html#statementsetallowbarenamedparametersenabled

Description of the problem

For sqlite statement.setAllowBareNamedParameters() the docs say:

By default, node:sqlite requires that this prefix character is present when binding parameters .. To improve ergonomics, this method can be used to also allow bare named parameters

but this is not right, the default value for allowBareNamedParameters is true, see database.prepare(sql[, options]) and new DatabaseSync(path[, options]), which means the prefix is not required. This needs to be re-written to account for allowBareNamedParameters defaulting to true not false.

Example showing allowBareNamedParameters defaults to true:

import { DatabaseSync } from 'node:sqlite';
const db = new DatabaseSync(':memory:');

db.exec('CREATE TABLE t (c1, c2, c3)');

// named parameters $c1, $c2, $c3
const insert = db.prepare('INSERT INTO t VALUES ($c1, $c2, $c3)');

// bare named parameters, prefix not required by default
insert.run({ c1: 1, c2: 2, c3: 3 });

console.log(db.prepare('SELECT * FROM t').get());
// { c1: 1, c2: 2, c3: 3 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions