@b9g/zen 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +1044 -0
- package/chunk-2IEEEMRN.js +38 -0
- package/chunk-56M5Z3A6.js +1346 -0
- package/chunk-QXGEP5PB.js +310 -0
- package/ddl-NAJM37GQ.js +9 -0
- package/package.json +102 -0
- package/src/bun.d.ts +50 -0
- package/src/bun.js +906 -0
- package/src/mysql.d.ts +62 -0
- package/src/mysql.js +573 -0
- package/src/postgres.d.ts +62 -0
- package/src/postgres.js +555 -0
- package/src/sqlite.d.ts +43 -0
- package/src/sqlite.js +447 -0
- package/src/zen.d.ts +14 -0
- package/src/zen.js +2143 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createTemplate,
|
|
3
|
+
getTableMeta,
|
|
4
|
+
ident,
|
|
5
|
+
makeTemplate
|
|
6
|
+
} from "./chunk-56M5Z3A6.js";
|
|
7
|
+
|
|
8
|
+
// src/impl/ddl.ts
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
function unwrapType(schema) {
|
|
11
|
+
let core = schema;
|
|
12
|
+
let isOptional = false;
|
|
13
|
+
let isNullable = false;
|
|
14
|
+
let hasDefault = false;
|
|
15
|
+
let defaultValue = void 0;
|
|
16
|
+
isOptional = schema.isOptional();
|
|
17
|
+
isNullable = schema.isNullable();
|
|
18
|
+
while (true) {
|
|
19
|
+
if (typeof core.removeDefault === "function") {
|
|
20
|
+
hasDefault = true;
|
|
21
|
+
try {
|
|
22
|
+
defaultValue = core.parse(void 0);
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
core = core.removeDefault();
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (typeof core.unwrap === "function") {
|
|
29
|
+
core = core.unwrap();
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (typeof core.innerType === "function") {
|
|
33
|
+
core = core.innerType();
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
return { core, isOptional, isNullable, hasDefault, defaultValue };
|
|
39
|
+
}
|
|
40
|
+
function mapZodToSQL(schema, dialect, fieldMeta) {
|
|
41
|
+
const { core, hasDefault, defaultValue } = unwrapType(schema);
|
|
42
|
+
let sqlType;
|
|
43
|
+
let sqlDefault;
|
|
44
|
+
if (fieldMeta?.columnType) {
|
|
45
|
+
sqlType = fieldMeta.columnType;
|
|
46
|
+
if (hasDefault && defaultValue !== void 0) {
|
|
47
|
+
if (typeof defaultValue === "string") {
|
|
48
|
+
sqlDefault = `'${defaultValue.replace(/'/g, "''")}'`;
|
|
49
|
+
} else if (typeof defaultValue === "number" || typeof defaultValue === "boolean") {
|
|
50
|
+
sqlDefault = String(defaultValue);
|
|
51
|
+
} else {
|
|
52
|
+
sqlDefault = `'${JSON.stringify(defaultValue).replace(/'/g, "''")}'`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { sqlType, defaultValue: sqlDefault };
|
|
56
|
+
}
|
|
57
|
+
if (core instanceof z.ZodString) {
|
|
58
|
+
const maxLength = core.maxLength;
|
|
59
|
+
if (maxLength && maxLength <= 255 && dialect !== "sqlite") {
|
|
60
|
+
sqlType = `VARCHAR(${maxLength})`;
|
|
61
|
+
} else {
|
|
62
|
+
sqlType = "TEXT";
|
|
63
|
+
}
|
|
64
|
+
if (hasDefault && defaultValue !== void 0) {
|
|
65
|
+
sqlDefault = `'${String(defaultValue).replace(/'/g, "''")}'`;
|
|
66
|
+
}
|
|
67
|
+
} else if (core instanceof z.ZodNumber) {
|
|
68
|
+
const isInt = core.isInt;
|
|
69
|
+
if (isInt) {
|
|
70
|
+
sqlType = "INTEGER";
|
|
71
|
+
} else {
|
|
72
|
+
sqlType = dialect === "postgresql" ? "DOUBLE PRECISION" : "REAL";
|
|
73
|
+
}
|
|
74
|
+
if (hasDefault && defaultValue !== void 0) {
|
|
75
|
+
sqlDefault = String(defaultValue);
|
|
76
|
+
}
|
|
77
|
+
} else if (core instanceof z.ZodBoolean) {
|
|
78
|
+
sqlType = dialect === "sqlite" ? "INTEGER" : "BOOLEAN";
|
|
79
|
+
if (hasDefault && defaultValue !== void 0) {
|
|
80
|
+
if (dialect === "sqlite") {
|
|
81
|
+
sqlDefault = defaultValue ? "1" : "0";
|
|
82
|
+
} else {
|
|
83
|
+
sqlDefault = defaultValue ? "TRUE" : "FALSE";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
} else if (core instanceof z.ZodDate) {
|
|
87
|
+
if (dialect === "postgresql") {
|
|
88
|
+
sqlType = "TIMESTAMPTZ";
|
|
89
|
+
} else if (dialect === "mysql") {
|
|
90
|
+
sqlType = "DATETIME";
|
|
91
|
+
} else {
|
|
92
|
+
sqlType = "TEXT";
|
|
93
|
+
}
|
|
94
|
+
if (hasDefault) {
|
|
95
|
+
if (dialect === "sqlite") {
|
|
96
|
+
sqlDefault = "CURRENT_TIMESTAMP";
|
|
97
|
+
} else if (dialect === "postgresql") {
|
|
98
|
+
sqlDefault = "NOW()";
|
|
99
|
+
} else {
|
|
100
|
+
sqlDefault = "CURRENT_TIMESTAMP";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} else if (core instanceof z.ZodEnum) {
|
|
104
|
+
sqlType = "TEXT";
|
|
105
|
+
if (hasDefault && defaultValue !== void 0) {
|
|
106
|
+
sqlDefault = `'${String(defaultValue).replace(/'/g, "''")}'`;
|
|
107
|
+
}
|
|
108
|
+
} else if (core instanceof z.ZodArray || core instanceof z.ZodObject) {
|
|
109
|
+
if (dialect === "postgresql") {
|
|
110
|
+
sqlType = "JSONB";
|
|
111
|
+
} else {
|
|
112
|
+
sqlType = "TEXT";
|
|
113
|
+
}
|
|
114
|
+
if (hasDefault && defaultValue !== void 0) {
|
|
115
|
+
sqlDefault = `'${JSON.stringify(defaultValue).replace(/'/g, "''")}'`;
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
sqlType = "TEXT";
|
|
119
|
+
if (hasDefault && defaultValue !== void 0) {
|
|
120
|
+
sqlDefault = `'${String(defaultValue).replace(/'/g, "''")}'`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return { sqlType, defaultValue: sqlDefault };
|
|
124
|
+
}
|
|
125
|
+
function generateColumnDDL(fieldName, zodType, fieldMeta, dialect = "sqlite") {
|
|
126
|
+
const { isOptional, isNullable, hasDefault } = unwrapType(zodType);
|
|
127
|
+
const { sqlType, defaultValue: sqlDefault } = mapZodToSQL(
|
|
128
|
+
zodType,
|
|
129
|
+
dialect,
|
|
130
|
+
fieldMeta
|
|
131
|
+
);
|
|
132
|
+
const strings = [""];
|
|
133
|
+
const values = [ident(fieldName)];
|
|
134
|
+
let suffix = ` ${sqlType}`;
|
|
135
|
+
const nullable = isOptional || isNullable || hasDefault;
|
|
136
|
+
if (!nullable) {
|
|
137
|
+
suffix += " NOT NULL";
|
|
138
|
+
}
|
|
139
|
+
if (sqlDefault !== void 0) {
|
|
140
|
+
suffix += ` DEFAULT ${sqlDefault}`;
|
|
141
|
+
}
|
|
142
|
+
if (fieldMeta.unique === true) {
|
|
143
|
+
suffix += " UNIQUE";
|
|
144
|
+
}
|
|
145
|
+
strings.push(suffix);
|
|
146
|
+
return createTemplate(makeTemplate(strings), values);
|
|
147
|
+
}
|
|
148
|
+
function generateDDL(table, options = {}) {
|
|
149
|
+
const { dialect = "sqlite", ifNotExists = true } = options;
|
|
150
|
+
const shape = table.schema.shape;
|
|
151
|
+
const meta = getTableMeta(table);
|
|
152
|
+
const strings = [];
|
|
153
|
+
const values = [];
|
|
154
|
+
const tableExists = ifNotExists ? "IF NOT EXISTS " : "";
|
|
155
|
+
const indexExists = ifNotExists && dialect !== "mysql" ? "IF NOT EXISTS " : "";
|
|
156
|
+
strings.push(`CREATE TABLE ${tableExists}`);
|
|
157
|
+
values.push(ident(table.name));
|
|
158
|
+
strings.push(" (\n ");
|
|
159
|
+
let needsComma = false;
|
|
160
|
+
for (const [name, zodType] of Object.entries(shape)) {
|
|
161
|
+
const fieldMeta = meta.fields[name] || {};
|
|
162
|
+
const { isOptional, isNullable, hasDefault } = unwrapType(
|
|
163
|
+
zodType
|
|
164
|
+
);
|
|
165
|
+
const { sqlType, defaultValue: sqlDefault } = mapZodToSQL(
|
|
166
|
+
zodType,
|
|
167
|
+
dialect,
|
|
168
|
+
fieldMeta
|
|
169
|
+
);
|
|
170
|
+
if (needsComma) {
|
|
171
|
+
strings[strings.length - 1] += ",\n ";
|
|
172
|
+
}
|
|
173
|
+
needsComma = true;
|
|
174
|
+
values.push(ident(name));
|
|
175
|
+
let colDef = ` ${sqlType}`;
|
|
176
|
+
if (fieldMeta.autoIncrement) {
|
|
177
|
+
if (dialect === "sqlite") {
|
|
178
|
+
colDef += " PRIMARY KEY AUTOINCREMENT";
|
|
179
|
+
} else if (dialect === "postgresql") {
|
|
180
|
+
colDef += " GENERATED ALWAYS AS IDENTITY";
|
|
181
|
+
} else if (dialect === "mysql") {
|
|
182
|
+
colDef += " AUTO_INCREMENT";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const nullable = isOptional || isNullable || hasDefault;
|
|
186
|
+
if (!nullable && !fieldMeta.autoIncrement) {
|
|
187
|
+
colDef += " NOT NULL";
|
|
188
|
+
}
|
|
189
|
+
if (sqlDefault !== void 0 && !fieldMeta.autoIncrement) {
|
|
190
|
+
colDef += ` DEFAULT ${sqlDefault}`;
|
|
191
|
+
}
|
|
192
|
+
if (fieldMeta.primaryKey && dialect === "sqlite" && !fieldMeta.autoIncrement) {
|
|
193
|
+
colDef += " PRIMARY KEY";
|
|
194
|
+
}
|
|
195
|
+
if (fieldMeta.unique && !fieldMeta.primaryKey) {
|
|
196
|
+
colDef += " UNIQUE";
|
|
197
|
+
}
|
|
198
|
+
strings.push(colDef);
|
|
199
|
+
}
|
|
200
|
+
if (meta.primary && dialect !== "sqlite") {
|
|
201
|
+
if (needsComma) {
|
|
202
|
+
strings[strings.length - 1] += ",\n PRIMARY KEY (";
|
|
203
|
+
} else {
|
|
204
|
+
strings[strings.length - 1] += "PRIMARY KEY (";
|
|
205
|
+
needsComma = true;
|
|
206
|
+
}
|
|
207
|
+
values.push(ident(meta.primary));
|
|
208
|
+
strings.push(")");
|
|
209
|
+
}
|
|
210
|
+
for (const ref of meta.references) {
|
|
211
|
+
if (needsComma) {
|
|
212
|
+
strings[strings.length - 1] += ",\n FOREIGN KEY (";
|
|
213
|
+
} else {
|
|
214
|
+
strings[strings.length - 1] += "FOREIGN KEY (";
|
|
215
|
+
needsComma = true;
|
|
216
|
+
}
|
|
217
|
+
values.push(ident(ref.fieldName));
|
|
218
|
+
strings.push(") REFERENCES ");
|
|
219
|
+
values.push(ident(ref.table.name));
|
|
220
|
+
strings.push("(");
|
|
221
|
+
values.push(ident(ref.referencedField));
|
|
222
|
+
let fkSuffix = ")";
|
|
223
|
+
if (ref.onDelete) {
|
|
224
|
+
const onDeleteSQL = ref.onDelete === "set null" ? "SET NULL" : ref.onDelete.toUpperCase();
|
|
225
|
+
fkSuffix += ` ON DELETE ${onDeleteSQL}`;
|
|
226
|
+
}
|
|
227
|
+
strings.push(fkSuffix);
|
|
228
|
+
}
|
|
229
|
+
for (const ref of table.compoundReferences) {
|
|
230
|
+
if (needsComma) {
|
|
231
|
+
strings[strings.length - 1] += ",\n FOREIGN KEY (";
|
|
232
|
+
} else {
|
|
233
|
+
strings[strings.length - 1] += "FOREIGN KEY (";
|
|
234
|
+
needsComma = true;
|
|
235
|
+
}
|
|
236
|
+
for (let i = 0; i < ref.fields.length; i++) {
|
|
237
|
+
if (i > 0)
|
|
238
|
+
strings[strings.length - 1] += ", ";
|
|
239
|
+
values.push(ident(ref.fields[i]));
|
|
240
|
+
strings.push("");
|
|
241
|
+
}
|
|
242
|
+
strings[strings.length - 1] += ") REFERENCES ";
|
|
243
|
+
values.push(ident(ref.table.name));
|
|
244
|
+
strings.push("(");
|
|
245
|
+
const refFields = ref.referencedFields ?? ref.fields;
|
|
246
|
+
for (let i = 0; i < refFields.length; i++) {
|
|
247
|
+
if (i > 0)
|
|
248
|
+
strings[strings.length - 1] += ", ";
|
|
249
|
+
values.push(ident(refFields[i]));
|
|
250
|
+
strings.push("");
|
|
251
|
+
}
|
|
252
|
+
let fkSuffix = ")";
|
|
253
|
+
if (ref.onDelete) {
|
|
254
|
+
const onDeleteSQL = ref.onDelete === "set null" ? "SET NULL" : ref.onDelete.toUpperCase();
|
|
255
|
+
fkSuffix += ` ON DELETE ${onDeleteSQL}`;
|
|
256
|
+
}
|
|
257
|
+
strings[strings.length - 1] += fkSuffix;
|
|
258
|
+
}
|
|
259
|
+
for (const uniqueCols of table.unique) {
|
|
260
|
+
if (needsComma) {
|
|
261
|
+
strings[strings.length - 1] += ",\n UNIQUE (";
|
|
262
|
+
} else {
|
|
263
|
+
strings[strings.length - 1] += "UNIQUE (";
|
|
264
|
+
needsComma = true;
|
|
265
|
+
}
|
|
266
|
+
for (let i = 0; i < uniqueCols.length; i++) {
|
|
267
|
+
if (i > 0)
|
|
268
|
+
strings[strings.length - 1] += ", ";
|
|
269
|
+
values.push(ident(uniqueCols[i]));
|
|
270
|
+
strings.push("");
|
|
271
|
+
}
|
|
272
|
+
strings[strings.length - 1] += ")";
|
|
273
|
+
}
|
|
274
|
+
strings[strings.length - 1] += "\n);";
|
|
275
|
+
for (const indexedField of meta.indexed) {
|
|
276
|
+
const indexName = `idx_${table.name}_${indexedField}`;
|
|
277
|
+
strings[strings.length - 1] += `
|
|
278
|
+
|
|
279
|
+
CREATE INDEX ${indexExists}`;
|
|
280
|
+
values.push(ident(indexName));
|
|
281
|
+
strings.push(" ON ");
|
|
282
|
+
values.push(ident(table.name));
|
|
283
|
+
strings.push(" (");
|
|
284
|
+
values.push(ident(indexedField));
|
|
285
|
+
strings.push(");");
|
|
286
|
+
}
|
|
287
|
+
for (const indexCols of table.indexes) {
|
|
288
|
+
const indexName = `idx_${table.name}_${indexCols.join("_")}`;
|
|
289
|
+
strings[strings.length - 1] += `
|
|
290
|
+
|
|
291
|
+
CREATE INDEX ${indexExists}`;
|
|
292
|
+
values.push(ident(indexName));
|
|
293
|
+
strings.push(" ON ");
|
|
294
|
+
values.push(ident(table.name));
|
|
295
|
+
strings.push(" (");
|
|
296
|
+
for (let i = 0; i < indexCols.length; i++) {
|
|
297
|
+
if (i > 0)
|
|
298
|
+
strings[strings.length - 1] += ", ";
|
|
299
|
+
values.push(ident(indexCols[i]));
|
|
300
|
+
strings.push("");
|
|
301
|
+
}
|
|
302
|
+
strings[strings.length - 1] += ");";
|
|
303
|
+
}
|
|
304
|
+
return createTemplate(makeTemplate(strings), values);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export {
|
|
308
|
+
generateColumnDDL,
|
|
309
|
+
generateDDL
|
|
310
|
+
};
|
package/ddl-NAJM37GQ.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@b9g/zen",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The simple database client. Define tables. Write SQL. Get objects.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"database",
|
|
7
|
+
"sql",
|
|
8
|
+
"zod",
|
|
9
|
+
"schema",
|
|
10
|
+
"orm",
|
|
11
|
+
"sqlite",
|
|
12
|
+
"postgres",
|
|
13
|
+
"mysql"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"zod": "^4.0.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@b9g/libuild": "^0.1.20",
|
|
21
|
+
"@eslint/js": "^9.39.2",
|
|
22
|
+
"@types/better-sqlite3": "^7.6.0",
|
|
23
|
+
"@types/bun": "^1.3.4",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^8.49.0",
|
|
25
|
+
"@typescript-eslint/parser": "^8.49.0",
|
|
26
|
+
"better-sqlite3": "^11.8.1",
|
|
27
|
+
"eslint": "^9.39.2",
|
|
28
|
+
"eslint-config-prettier": "^10.1.8",
|
|
29
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
30
|
+
"mysql2": "^3.12.0",
|
|
31
|
+
"postgres": "^3.4.0",
|
|
32
|
+
"tsx": "^4.21.0",
|
|
33
|
+
"typescript": "^5.7.3"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"better-sqlite3": "^11.0.0",
|
|
37
|
+
"mysql2": "^3.0.0",
|
|
38
|
+
"postgres": "^3.0.0",
|
|
39
|
+
"zod": "^4.0.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"better-sqlite3": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"postgres": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"mysql2": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"type": "module",
|
|
53
|
+
"types": "src/zen.d.ts",
|
|
54
|
+
"module": "src/zen.js",
|
|
55
|
+
"exports": {
|
|
56
|
+
".": {
|
|
57
|
+
"types": "./src/zen.d.ts",
|
|
58
|
+
"import": "./src/zen.js"
|
|
59
|
+
},
|
|
60
|
+
"./bun": {
|
|
61
|
+
"types": "./src/bun.d.ts",
|
|
62
|
+
"import": "./src/bun.js"
|
|
63
|
+
},
|
|
64
|
+
"./sqlite": {
|
|
65
|
+
"types": "./src/sqlite.d.ts",
|
|
66
|
+
"import": "./src/sqlite.js"
|
|
67
|
+
},
|
|
68
|
+
"./postgres": {
|
|
69
|
+
"types": "./src/postgres.d.ts",
|
|
70
|
+
"import": "./src/postgres.js"
|
|
71
|
+
},
|
|
72
|
+
"./mysql": {
|
|
73
|
+
"types": "./src/mysql.d.ts",
|
|
74
|
+
"import": "./src/mysql.js"
|
|
75
|
+
},
|
|
76
|
+
"./bun.js": {
|
|
77
|
+
"types": "./src/bun.d.ts",
|
|
78
|
+
"import": "./src/bun.js"
|
|
79
|
+
},
|
|
80
|
+
"./mysql.js": {
|
|
81
|
+
"types": "./src/mysql.d.ts",
|
|
82
|
+
"import": "./src/mysql.js"
|
|
83
|
+
},
|
|
84
|
+
"./postgres.js": {
|
|
85
|
+
"types": "./src/postgres.d.ts",
|
|
86
|
+
"import": "./src/postgres.js"
|
|
87
|
+
},
|
|
88
|
+
"./sqlite.js": {
|
|
89
|
+
"types": "./src/sqlite.d.ts",
|
|
90
|
+
"import": "./src/sqlite.js"
|
|
91
|
+
},
|
|
92
|
+
"./zen": {
|
|
93
|
+
"types": "./src/zen.d.ts",
|
|
94
|
+
"import": "./src/zen.js"
|
|
95
|
+
},
|
|
96
|
+
"./zen.js": {
|
|
97
|
+
"types": "./src/zen.d.ts",
|
|
98
|
+
"import": "./src/zen.js"
|
|
99
|
+
},
|
|
100
|
+
"./package.json": "./package.json"
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/bun.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bun.SQL adapter for @b9g/zen
|
|
3
|
+
*
|
|
4
|
+
* Unified driver supporting PostgreSQL, MySQL, and SQLite via Bun's built-in SQL.
|
|
5
|
+
* Zero dependencies - uses native Bun implementation.
|
|
6
|
+
*/
|
|
7
|
+
import type { Driver, Table, EnsureResult } from "./zen.js";
|
|
8
|
+
/**
|
|
9
|
+
* Bun driver using Bun's built-in SQL.
|
|
10
|
+
* Supports PostgreSQL, MySQL, and SQLite with automatic dialect detection.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import BunDriver from "@b9g/zen/bun";
|
|
14
|
+
* import {Database} from "@b9g/zen";
|
|
15
|
+
*
|
|
16
|
+
* const driver = new BunDriver("postgres://localhost/mydb");
|
|
17
|
+
* const db = new Database(driver);
|
|
18
|
+
*
|
|
19
|
+
* db.addEventListener("upgradeneeded", (e) => {
|
|
20
|
+
* e.waitUntil(runMigrations(e));
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* await db.open(1);
|
|
24
|
+
*
|
|
25
|
+
* // When done:
|
|
26
|
+
* await driver.close();
|
|
27
|
+
*/
|
|
28
|
+
export default class BunDriver implements Driver {
|
|
29
|
+
#private;
|
|
30
|
+
readonly supportsReturning: boolean;
|
|
31
|
+
constructor(url: string, options?: Record<string, unknown>);
|
|
32
|
+
all<T>(strings: TemplateStringsArray, values: unknown[]): Promise<T[]>;
|
|
33
|
+
get<T>(strings: TemplateStringsArray, values: unknown[]): Promise<T | null>;
|
|
34
|
+
run(strings: TemplateStringsArray, values: unknown[]): Promise<number>;
|
|
35
|
+
val<T>(strings: TemplateStringsArray, values: unknown[]): Promise<T | null>;
|
|
36
|
+
close(): Promise<void>;
|
|
37
|
+
transaction<T>(fn: (txDriver: Driver) => Promise<T>): Promise<T>;
|
|
38
|
+
withMigrationLock<T>(fn: () => Promise<T>): Promise<T>;
|
|
39
|
+
ensureTable<T extends Table<any>>(table: T): Promise<EnsureResult>;
|
|
40
|
+
ensureConstraints<T extends Table<any>>(table: T): Promise<EnsureResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Optional introspection: list columns for a table.
|
|
43
|
+
* Exposed for Database-level helpers that need column existence checks.
|
|
44
|
+
*/
|
|
45
|
+
getColumns(tableName: string): Promise<{
|
|
46
|
+
name: string;
|
|
47
|
+
type?: string;
|
|
48
|
+
notnull?: boolean;
|
|
49
|
+
}[]>;
|
|
50
|
+
}
|