Skip to content

Commit 36376d6

Browse files
committed
feat: add sqlite-type symbol property for type identification in DatabaseSync -- see nodejs/node#59405
1 parent 12c1d7e commit 36376d6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/sqlite_impl.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,17 @@ Napi::Object DatabaseSync::Init(Napi::Env env, Napi::Object exports) {
308308
}));
309309
}
310310

311+
// Add Symbol.for('sqlite-type') property for type identification
312+
// See: https://github.com/nodejs/node/pull/59405
313+
Napi::Object symbolConstructor =
314+
env.Global().Get("Symbol").As<Napi::Object>();
315+
Napi::Function symbolFor = symbolConstructor.Get("for").As<Napi::Function>();
316+
Napi::Value sqliteTypeSymbol = symbolFor.Call(
317+
symbolConstructor, {Napi::String::New(env, "sqlite-type")});
318+
func.Get("prototype")
319+
.As<Napi::Object>()
320+
.Set(sqliteTypeSymbol, Napi::String::New(env, "node:sqlite"));
321+
311322
exports.Set("DatabaseSync", func);
312323
return exports;
313324
}

test/database.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ describe("DatabaseSync Tests", () => {
154154
db.close();
155155
expect(db.isOpen).toBe(false);
156156
});
157+
158+
// See: https://github.com/nodejs/node/pull/59405
159+
test("has sqlite-type symbol property", () => {
160+
const db = new DatabaseSync(":memory:");
161+
162+
const sqliteTypeSymbol = Symbol.for("sqlite-type");
163+
expect((db as unknown as Record<symbol, string>)[sqliteTypeSymbol]).toBe(
164+
"node:sqlite",
165+
);
166+
167+
db.close();
168+
});
157169
});
158170

159171
describe("File-based Database Tests", () => {

0 commit comments

Comments
 (0)