Skip to content

node:sqlite implementation does not understand named parameters #28134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jtoppine opened this issue Feb 16, 2025 · 1 comment
Closed

node:sqlite implementation does not understand named parameters #28134

jtoppine opened this issue Feb 16, 2025 · 1 comment
Labels
node compat node:sqlite Issues related to the `node:sqlite` module

Comments

@jtoppine
Copy link

jtoppine commented Feb 16, 2025

Version: Deno 2.1.10+56f67b5 (canary, release, x86_64-unknown-linux-gnu)

node:sqlite implementation does not understand named parameters.

If an option bag object is provided like so: preparedstatement.all({param1: value1}), Deno will treat the object like "first anonymous parameter", which then obviously results in Unsupported type since Object can not be bound as parameter value.

Tested with an sqlite copy of the northwind sample db:

const sqlite = require("node:sqlite"); // NODE RUNTIME
// import * as sqlite from "node:sqlite"; // DENO RUNTIME

const path = "northwind.sqlite3";
const db = new sqlite.DatabaseSync(path);

let query;
let result;

console.log("NO PARAM");
query = "SELECT FirstName, LastName FROM Employees WHERE FirstName='Nancy'";
result = db.prepare(query).all();
console.log(result);
// OK IN DENO AND NODE

console.log("ANONYMOUS PARAM");
query = "SELECT FirstName, LastName FROM Employees WHERE FirstName=?";
result = db.prepare(query).all("Nancy");
console.log(result);
// OK IN DENO AND NODE

console.log("NAMED PARAM");
query = "SELECT FirstName, LastName FROM Employees WHERE FirstName=:firstName";
result = db.prepare(query).all({ firstName: "Nancy" });
console.log(result);
// NODE CORRECTLY PRINTS { FirstName: 'Nancy', LastName: 'Davolio' }
// DENO THROWS WITH "UNSUPPORTED TYPE"

console.log("NAMED AND ANONYMOUS PARAM");
query = "SELECT FirstName, LastName FROM Employees WHERE FirstName=:firstName AND LastName=?";
result = db.prepare(query).all({ firstName: "Nancy" }, "Davolio");
console.log(result);
// NODE CORRECTLY PRINTS { FirstName: 'Nancy', LastName: 'Davolio' }
// DENO THROWS WITH "UNSUPPORTED TYPE"
@marvinhagemeister marvinhagemeister added node compat node:sqlite Issues related to the `node:sqlite` module labels Feb 16, 2025
littledivy pushed a commit that referenced this issue Feb 18, 2025
This PR introduces support for named parameters in SQLite queries, as
outlined in #28134
@bartlomieju
Copy link
Member

Fixed in #28154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node compat node:sqlite Issues related to the `node:sqlite` module
Projects
None yet
Development

No branches or pull requests

3 participants