SQLite null prototype
Hi,
SQLite returns [Object: null prototype] as it's not an object. What is the ideal way of dealing with this?
SQLite returns [Object: null prototype] as it's not an object. What is the ideal way of dealing with this?
import { DatabaseSync } from "node:sqlite";
// Create or open an in-memory SQLite database
const db = new DatabaseSync(":memory:");
// Execute multiple SQL statements:
// 1. Create a table named "users"
// 2. Insert two rows into the "users" table
db.exec(`
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT
);
INSERT INTO users (name) VALUES ('Alice');
INSERT INTO users (name) VALUES ('Bob');
`);
// Query to verify data insertion using .get()
const result = db.prepare(`SELECT * FROM users WHERE name = 'Alice'`)
.get();
console.log(result); // => [Object: null prototype] { id: 1, name: 'Alice' }
db.close();import { DatabaseSync } from "node:sqlite";
// Create or open an in-memory SQLite database
const db = new DatabaseSync(":memory:");
// Execute multiple SQL statements:
// 1. Create a table named "users"
// 2. Insert two rows into the "users" table
db.exec(`
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT
);
INSERT INTO users (name) VALUES ('Alice');
INSERT INTO users (name) VALUES ('Bob');
`);
// Query to verify data insertion using .get()
const result = db.prepare(`SELECT * FROM users WHERE name = 'Alice'`)
.get();
console.log(result); // => [Object: null prototype] { id: 1, name: 'Alice' }
db.close();