deno/ext/node/polyfills/sqlite.ts
Alex Yang cb4207efb6
feat(ext/node): add sqlite-type symbol for DatabaseSync (#30511)
Related:
d1eabcb044
Related: https://github.com/nodejs/node/pull/59405
Related: https://github.com/better-auth/better-auth/pull/3869
Related: https://github.com/oven-sh/bun/pull/22109

Nowadays, there are tons of database packages, like sqlite3, sqlite,
better-sqlite, bun:sqlite... Checking the difference from them is pretty
hard.
instanceof is not good, since the developer will still need to import
the module, which is costly.
I think we should provide a symbol to distinguish different SQLite
classes, at least nodejs could make the first step.

---------

Signed-off-by: Alex Yang <himself65@outlook.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2025-09-08 23:45:39 +00:00

37 lines
821 B
TypeScript

// Copyright 2018-2025 the Deno authors. MIT license.
import { primordials } from "ext:core/mod.js";
import { DatabaseSync, StatementSync } from "ext:core/ops";
const {
ObjectDefineProperty,
SymbolFor,
} = primordials;
export const constants = {
SQLITE_CHANGESET_OMIT: 0,
SQLITE_CHANGESET_REPLACE: 1,
SQLITE_CHANGESET_ABORT: 2,
SQLITE_CHANGESET_DATA: 1,
SQLITE_CHANGESET_NOTFOUND: 2,
SQLITE_CHANGESET_CONFLICT: 3,
SQLITE_CHANGESET_CONSTRAINT: 4,
SQLITE_CHANGESET_FOREIGN_KEY: 5,
};
const sqliteTypeSymbol = SymbolFor("sqlite-type");
ObjectDefineProperty(DatabaseSync.prototype, sqliteTypeSymbol, {
__proto__: null,
value: "node:sqlite",
enumerable: false,
configurable: true,
});
export { DatabaseSync, StatementSync };
export default {
constants,
DatabaseSync,
StatementSync,
};