@3lineas/d1-orm 1.0.6 → 1.0.8
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/README.md +41 -148
- package/dist/chunk-N3G6NOJP.js +127 -0
- package/dist/cli/index.cjs +781 -0
- package/dist/cli/index.js +245 -258
- package/dist/{index.mjs → index.cjs} +159 -14
- package/dist/{index.d.mts → index.d.cts} +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -157
- package/package.json +2 -2
- package/dist/chunk-5BBZKUNZ.mjs +0 -147
- package/dist/cli/index.mjs +0 -563
- /package/dist/cli/{index.d.mts → index.d.cts} +0 -0
|
@@ -1,12 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
7
19
|
|
|
8
20
|
// src/index.ts
|
|
9
|
-
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
BelongsTo: () => BelongsTo,
|
|
24
|
+
Blueprint: () => Blueprint,
|
|
25
|
+
Column: () => Column,
|
|
26
|
+
Connection: () => Connection,
|
|
27
|
+
Database: () => Database,
|
|
28
|
+
HasMany: () => HasMany,
|
|
29
|
+
HasOne: () => HasOne,
|
|
30
|
+
Model: () => Model,
|
|
31
|
+
ModelQueryBuilder: () => ModelQueryBuilder,
|
|
32
|
+
QueryBuilder: () => QueryBuilder,
|
|
33
|
+
Relationship: () => Relationship,
|
|
34
|
+
Schema: () => Schema
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/core/connection.ts
|
|
39
|
+
var Connection = class {
|
|
40
|
+
/**
|
|
41
|
+
* The underlying D1Database instance.
|
|
42
|
+
*/
|
|
43
|
+
db;
|
|
44
|
+
/**
|
|
45
|
+
* Create a new Connection instance.
|
|
46
|
+
*
|
|
47
|
+
* @param database - The D1Database instance.
|
|
48
|
+
*/
|
|
49
|
+
constructor(database) {
|
|
50
|
+
this.db = database;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Execute a SELECT statement.
|
|
54
|
+
*
|
|
55
|
+
* @param query - The SQL query string.
|
|
56
|
+
* @param bindings - The parameter bindings.
|
|
57
|
+
* @returns A promise that resolves to an array of results.
|
|
58
|
+
*/
|
|
59
|
+
async select(query, bindings = []) {
|
|
60
|
+
const stmt = this.db.prepare(query).bind(...bindings);
|
|
61
|
+
const result = await stmt.all();
|
|
62
|
+
return result.results || [];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Execute an INSERT statement.
|
|
66
|
+
*
|
|
67
|
+
* @param query - The SQL query string.
|
|
68
|
+
* @param bindings - The parameter bindings.
|
|
69
|
+
* @returns A promise that resolves to true on success.
|
|
70
|
+
*/
|
|
71
|
+
async insert(query, bindings = []) {
|
|
72
|
+
const stmt = this.db.prepare(query).bind(...bindings);
|
|
73
|
+
const result = await stmt.run();
|
|
74
|
+
return result.success;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Execute an UPDATE statement.
|
|
78
|
+
*
|
|
79
|
+
* @param query - The SQL query string.
|
|
80
|
+
* @param bindings - The parameter bindings.
|
|
81
|
+
* @returns A promise that resolves to true on success.
|
|
82
|
+
*/
|
|
83
|
+
async update(query, bindings = []) {
|
|
84
|
+
const stmt = this.db.prepare(query).bind(...bindings);
|
|
85
|
+
const result = await stmt.run();
|
|
86
|
+
return result.success;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Execute a DELETE statement.
|
|
90
|
+
*
|
|
91
|
+
* @param query - The SQL query string.
|
|
92
|
+
* @param bindings - The parameter bindings.
|
|
93
|
+
* @returns A promise that resolves to true on success.
|
|
94
|
+
*/
|
|
95
|
+
async delete(query, bindings = []) {
|
|
96
|
+
const stmt = this.db.prepare(query).bind(...bindings);
|
|
97
|
+
const result = await stmt.run();
|
|
98
|
+
return result.success;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Execute an arbitrary SQL statement.
|
|
102
|
+
*
|
|
103
|
+
* @param query - The SQL query string.
|
|
104
|
+
* @param bindings - The parameter bindings.
|
|
105
|
+
* @returns A promise that resolves to true on success.
|
|
106
|
+
*/
|
|
107
|
+
async statement(query, bindings = []) {
|
|
108
|
+
const stmt = this.db.prepare(query).bind(...bindings);
|
|
109
|
+
const result = await stmt.run();
|
|
110
|
+
return result.success;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
10
113
|
|
|
11
114
|
// src/core/query-builder.ts
|
|
12
115
|
var QueryBuilder = class {
|
|
@@ -274,11 +377,52 @@ var ModelQueryBuilder = class extends QueryBuilder {
|
|
|
274
377
|
}
|
|
275
378
|
};
|
|
276
379
|
|
|
277
|
-
// src/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
380
|
+
// src/core/database.ts
|
|
381
|
+
var Database = class _Database {
|
|
382
|
+
/**
|
|
383
|
+
* Symbol for global singleton access.
|
|
384
|
+
*/
|
|
385
|
+
static INSTANCE_KEY = /* @__PURE__ */ Symbol.for("d1-orm-instance");
|
|
386
|
+
/**
|
|
387
|
+
* The active database connection.
|
|
388
|
+
*/
|
|
389
|
+
connection;
|
|
390
|
+
/**
|
|
391
|
+
* Private constructor to enforce singleton pattern.
|
|
392
|
+
*
|
|
393
|
+
* @param d1 - The D1Database instance from Cloudflare.
|
|
394
|
+
*/
|
|
395
|
+
constructor(d1) {
|
|
396
|
+
this.connection = new Connection(d1);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Setup the database connection.
|
|
400
|
+
*
|
|
401
|
+
* @param d1 - The D1Database instance from Cloudflare environment (env.DB).
|
|
402
|
+
*/
|
|
403
|
+
static setup(d1) {
|
|
404
|
+
globalThis[_Database.INSTANCE_KEY] = new _Database(d1);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Get the singleton Database instance.
|
|
408
|
+
*
|
|
409
|
+
* @throws Error if setup() has not been called and auto-init fails.
|
|
410
|
+
* @returns The Database instance.
|
|
411
|
+
*/
|
|
412
|
+
static getInstance() {
|
|
413
|
+
const instance = globalThis[_Database.INSTANCE_KEY];
|
|
414
|
+
if (!instance) {
|
|
415
|
+
if (globalThis["DB"] && typeof globalThis["DB"].prepare === "function") {
|
|
416
|
+
_Database.setup(globalThis["DB"]);
|
|
417
|
+
return globalThis[_Database.INSTANCE_KEY];
|
|
418
|
+
}
|
|
419
|
+
throw new Error(
|
|
420
|
+
"Database not initialized. Call Database.setup(env.DB) first or ensure your D1 binding is named 'DB'."
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
return instance;
|
|
424
|
+
}
|
|
425
|
+
};
|
|
282
426
|
|
|
283
427
|
// src/core/relationships/relationship.ts
|
|
284
428
|
var Relationship = class {
|
|
@@ -700,7 +844,8 @@ var Schema = class {
|
|
|
700
844
|
return `DROP TABLE IF EXISTS ${table}`;
|
|
701
845
|
}
|
|
702
846
|
};
|
|
703
|
-
export
|
|
847
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
848
|
+
0 && (module.exports = {
|
|
704
849
|
BelongsTo,
|
|
705
850
|
Blueprint,
|
|
706
851
|
Column,
|
|
@@ -713,4 +858,4 @@ export {
|
|
|
713
858
|
QueryBuilder,
|
|
714
859
|
Relationship,
|
|
715
860
|
Schema
|
|
716
|
-
};
|
|
861
|
+
});
|
|
@@ -219,9 +219,9 @@ declare class QueryBuilder {
|
|
|
219
219
|
*/
|
|
220
220
|
declare class Database {
|
|
221
221
|
/**
|
|
222
|
-
*
|
|
222
|
+
* Symbol for global singleton access.
|
|
223
223
|
*/
|
|
224
|
-
private static
|
|
224
|
+
private static readonly INSTANCE_KEY;
|
|
225
225
|
/**
|
|
226
226
|
* The active database connection.
|
|
227
227
|
*/
|
|
@@ -241,7 +241,7 @@ declare class Database {
|
|
|
241
241
|
/**
|
|
242
242
|
* Get the singleton Database instance.
|
|
243
243
|
*
|
|
244
|
-
* @throws Error if setup() has not been called.
|
|
244
|
+
* @throws Error if setup() has not been called and auto-init fails.
|
|
245
245
|
* @returns The Database instance.
|
|
246
246
|
*/
|
|
247
247
|
static getInstance(): Database;
|
package/dist/index.d.ts
CHANGED
|
@@ -219,9 +219,9 @@ declare class QueryBuilder {
|
|
|
219
219
|
*/
|
|
220
220
|
declare class Database {
|
|
221
221
|
/**
|
|
222
|
-
*
|
|
222
|
+
* Symbol for global singleton access.
|
|
223
223
|
*/
|
|
224
|
-
private static
|
|
224
|
+
private static readonly INSTANCE_KEY;
|
|
225
225
|
/**
|
|
226
226
|
* The active database connection.
|
|
227
227
|
*/
|
|
@@ -241,7 +241,7 @@ declare class Database {
|
|
|
241
241
|
/**
|
|
242
242
|
* Get the singleton Database instance.
|
|
243
243
|
*
|
|
244
|
-
* @throws Error if setup() has not been called.
|
|
244
|
+
* @throws Error if setup() has not been called and auto-init fails.
|
|
245
245
|
* @returns The Database instance.
|
|
246
246
|
*/
|
|
247
247
|
static getInstance(): Database;
|
package/dist/index.js
CHANGED
|
@@ -1,115 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
BelongsTo: () => BelongsTo,
|
|
24
|
-
Blueprint: () => Blueprint,
|
|
25
|
-
Column: () => Column,
|
|
26
|
-
Connection: () => Connection,
|
|
27
|
-
Database: () => Database,
|
|
28
|
-
HasMany: () => HasMany,
|
|
29
|
-
HasOne: () => HasOne,
|
|
30
|
-
Model: () => Model,
|
|
31
|
-
ModelQueryBuilder: () => ModelQueryBuilder,
|
|
32
|
-
QueryBuilder: () => QueryBuilder,
|
|
33
|
-
Relationship: () => Relationship,
|
|
34
|
-
Schema: () => Schema
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
37
|
-
|
|
38
|
-
// src/core/connection.ts
|
|
39
|
-
var Connection = class {
|
|
40
|
-
/**
|
|
41
|
-
* The underlying D1Database instance.
|
|
42
|
-
*/
|
|
43
|
-
db;
|
|
44
|
-
/**
|
|
45
|
-
* Create a new Connection instance.
|
|
46
|
-
*
|
|
47
|
-
* @param database - The D1Database instance.
|
|
48
|
-
*/
|
|
49
|
-
constructor(database) {
|
|
50
|
-
this.db = database;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Execute a SELECT statement.
|
|
54
|
-
*
|
|
55
|
-
* @param query - The SQL query string.
|
|
56
|
-
* @param bindings - The parameter bindings.
|
|
57
|
-
* @returns A promise that resolves to an array of results.
|
|
58
|
-
*/
|
|
59
|
-
async select(query, bindings = []) {
|
|
60
|
-
const stmt = this.db.prepare(query).bind(...bindings);
|
|
61
|
-
const result = await stmt.all();
|
|
62
|
-
return result.results || [];
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Execute an INSERT statement.
|
|
66
|
-
*
|
|
67
|
-
* @param query - The SQL query string.
|
|
68
|
-
* @param bindings - The parameter bindings.
|
|
69
|
-
* @returns A promise that resolves to true on success.
|
|
70
|
-
*/
|
|
71
|
-
async insert(query, bindings = []) {
|
|
72
|
-
const stmt = this.db.prepare(query).bind(...bindings);
|
|
73
|
-
const result = await stmt.run();
|
|
74
|
-
return result.success;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Execute an UPDATE statement.
|
|
78
|
-
*
|
|
79
|
-
* @param query - The SQL query string.
|
|
80
|
-
* @param bindings - The parameter bindings.
|
|
81
|
-
* @returns A promise that resolves to true on success.
|
|
82
|
-
*/
|
|
83
|
-
async update(query, bindings = []) {
|
|
84
|
-
const stmt = this.db.prepare(query).bind(...bindings);
|
|
85
|
-
const result = await stmt.run();
|
|
86
|
-
return result.success;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Execute a DELETE statement.
|
|
90
|
-
*
|
|
91
|
-
* @param query - The SQL query string.
|
|
92
|
-
* @param bindings - The parameter bindings.
|
|
93
|
-
* @returns A promise that resolves to true on success.
|
|
94
|
-
*/
|
|
95
|
-
async delete(query, bindings = []) {
|
|
96
|
-
const stmt = this.db.prepare(query).bind(...bindings);
|
|
97
|
-
const result = await stmt.run();
|
|
98
|
-
return result.success;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Execute an arbitrary SQL statement.
|
|
102
|
-
*
|
|
103
|
-
* @param query - The SQL query string.
|
|
104
|
-
* @param bindings - The parameter bindings.
|
|
105
|
-
* @returns A promise that resolves to true on success.
|
|
106
|
-
*/
|
|
107
|
-
async statement(query, bindings = []) {
|
|
108
|
-
const stmt = this.db.prepare(query).bind(...bindings);
|
|
109
|
-
const result = await stmt.run();
|
|
110
|
-
return result.success;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
Connection,
|
|
3
|
+
Database
|
|
4
|
+
} from "./chunk-N3G6NOJP.js";
|
|
113
5
|
|
|
114
6
|
// src/core/query-builder.ts
|
|
115
7
|
var QueryBuilder = class {
|
|
@@ -377,48 +269,6 @@ var ModelQueryBuilder = class extends QueryBuilder {
|
|
|
377
269
|
}
|
|
378
270
|
};
|
|
379
271
|
|
|
380
|
-
// src/core/database.ts
|
|
381
|
-
var Database = class _Database {
|
|
382
|
-
/**
|
|
383
|
-
* The singleton instance of the Database.
|
|
384
|
-
*/
|
|
385
|
-
static instance;
|
|
386
|
-
/**
|
|
387
|
-
* The active database connection.
|
|
388
|
-
*/
|
|
389
|
-
connection;
|
|
390
|
-
/**
|
|
391
|
-
* Private constructor to enforce singleton pattern.
|
|
392
|
-
*
|
|
393
|
-
* @param d1 - The D1Database instance from Cloudflare.
|
|
394
|
-
*/
|
|
395
|
-
constructor(d1) {
|
|
396
|
-
this.connection = new Connection(d1);
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Setup the database connection.
|
|
400
|
-
*
|
|
401
|
-
* @param d1 - The D1Database instance from Cloudflare environment (env.DB).
|
|
402
|
-
*/
|
|
403
|
-
static setup(d1) {
|
|
404
|
-
_Database.instance = new _Database(d1);
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Get the singleton Database instance.
|
|
408
|
-
*
|
|
409
|
-
* @throws Error if setup() has not been called.
|
|
410
|
-
* @returns The Database instance.
|
|
411
|
-
*/
|
|
412
|
-
static getInstance() {
|
|
413
|
-
if (!_Database.instance) {
|
|
414
|
-
throw new Error(
|
|
415
|
-
"Database not initialized. Call Database.setup(env.DB) first."
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
return _Database.instance;
|
|
419
|
-
}
|
|
420
|
-
};
|
|
421
|
-
|
|
422
272
|
// src/core/relationships/relationship.ts
|
|
423
273
|
var Relationship = class {
|
|
424
274
|
query;
|
|
@@ -839,8 +689,7 @@ var Schema = class {
|
|
|
839
689
|
return `DROP TABLE IF EXISTS ${table}`;
|
|
840
690
|
}
|
|
841
691
|
};
|
|
842
|
-
|
|
843
|
-
0 && (module.exports = {
|
|
692
|
+
export {
|
|
844
693
|
BelongsTo,
|
|
845
694
|
Blueprint,
|
|
846
695
|
Column,
|
|
@@ -853,4 +702,4 @@ var Schema = class {
|
|
|
853
702
|
QueryBuilder,
|
|
854
703
|
Relationship,
|
|
855
704
|
Schema
|
|
856
|
-
}
|
|
705
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@3lineas/d1-orm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "A lightweight and powerful ORM for Cloudflare D1, inspired by Laravel Eloquent.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"keywords": [],
|
|
19
19
|
"author": "",
|
|
20
20
|
"license": "ISC",
|
|
21
|
-
"type": "
|
|
21
|
+
"type": "module",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@cloudflare/workers-types": "^4.20260124.0",
|
|
24
24
|
"@types/node": "^25.0.10",
|
package/dist/chunk-5BBZKUNZ.mjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __esm = (fn, res) => function __init() {
|
|
3
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
4
|
-
};
|
|
5
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
6
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
// src/core/connection.ts
|
|
10
|
-
var Connection;
|
|
11
|
-
var init_connection = __esm({
|
|
12
|
-
"src/core/connection.ts"() {
|
|
13
|
-
"use strict";
|
|
14
|
-
Connection = class {
|
|
15
|
-
/**
|
|
16
|
-
* The underlying D1Database instance.
|
|
17
|
-
*/
|
|
18
|
-
db;
|
|
19
|
-
/**
|
|
20
|
-
* Create a new Connection instance.
|
|
21
|
-
*
|
|
22
|
-
* @param database - The D1Database instance.
|
|
23
|
-
*/
|
|
24
|
-
constructor(database) {
|
|
25
|
-
this.db = database;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Execute a SELECT statement.
|
|
29
|
-
*
|
|
30
|
-
* @param query - The SQL query string.
|
|
31
|
-
* @param bindings - The parameter bindings.
|
|
32
|
-
* @returns A promise that resolves to an array of results.
|
|
33
|
-
*/
|
|
34
|
-
async select(query, bindings = []) {
|
|
35
|
-
const stmt = this.db.prepare(query).bind(...bindings);
|
|
36
|
-
const result = await stmt.all();
|
|
37
|
-
return result.results || [];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Execute an INSERT statement.
|
|
41
|
-
*
|
|
42
|
-
* @param query - The SQL query string.
|
|
43
|
-
* @param bindings - The parameter bindings.
|
|
44
|
-
* @returns A promise that resolves to true on success.
|
|
45
|
-
*/
|
|
46
|
-
async insert(query, bindings = []) {
|
|
47
|
-
const stmt = this.db.prepare(query).bind(...bindings);
|
|
48
|
-
const result = await stmt.run();
|
|
49
|
-
return result.success;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Execute an UPDATE statement.
|
|
53
|
-
*
|
|
54
|
-
* @param query - The SQL query string.
|
|
55
|
-
* @param bindings - The parameter bindings.
|
|
56
|
-
* @returns A promise that resolves to true on success.
|
|
57
|
-
*/
|
|
58
|
-
async update(query, bindings = []) {
|
|
59
|
-
const stmt = this.db.prepare(query).bind(...bindings);
|
|
60
|
-
const result = await stmt.run();
|
|
61
|
-
return result.success;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Execute a DELETE statement.
|
|
65
|
-
*
|
|
66
|
-
* @param query - The SQL query string.
|
|
67
|
-
* @param bindings - The parameter bindings.
|
|
68
|
-
* @returns A promise that resolves to true on success.
|
|
69
|
-
*/
|
|
70
|
-
async delete(query, bindings = []) {
|
|
71
|
-
const stmt = this.db.prepare(query).bind(...bindings);
|
|
72
|
-
const result = await stmt.run();
|
|
73
|
-
return result.success;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Execute an arbitrary SQL statement.
|
|
77
|
-
*
|
|
78
|
-
* @param query - The SQL query string.
|
|
79
|
-
* @param bindings - The parameter bindings.
|
|
80
|
-
* @returns A promise that resolves to true on success.
|
|
81
|
-
*/
|
|
82
|
-
async statement(query, bindings = []) {
|
|
83
|
-
const stmt = this.db.prepare(query).bind(...bindings);
|
|
84
|
-
const result = await stmt.run();
|
|
85
|
-
return result.success;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// src/core/database.ts
|
|
92
|
-
var Database;
|
|
93
|
-
var init_database = __esm({
|
|
94
|
-
"src/core/database.ts"() {
|
|
95
|
-
"use strict";
|
|
96
|
-
init_connection();
|
|
97
|
-
Database = class _Database {
|
|
98
|
-
/**
|
|
99
|
-
* The singleton instance of the Database.
|
|
100
|
-
*/
|
|
101
|
-
static instance;
|
|
102
|
-
/**
|
|
103
|
-
* The active database connection.
|
|
104
|
-
*/
|
|
105
|
-
connection;
|
|
106
|
-
/**
|
|
107
|
-
* Private constructor to enforce singleton pattern.
|
|
108
|
-
*
|
|
109
|
-
* @param d1 - The D1Database instance from Cloudflare.
|
|
110
|
-
*/
|
|
111
|
-
constructor(d1) {
|
|
112
|
-
this.connection = new Connection(d1);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Setup the database connection.
|
|
116
|
-
*
|
|
117
|
-
* @param d1 - The D1Database instance from Cloudflare environment (env.DB).
|
|
118
|
-
*/
|
|
119
|
-
static setup(d1) {
|
|
120
|
-
_Database.instance = new _Database(d1);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Get the singleton Database instance.
|
|
124
|
-
*
|
|
125
|
-
* @throws Error if setup() has not been called.
|
|
126
|
-
* @returns The Database instance.
|
|
127
|
-
*/
|
|
128
|
-
static getInstance() {
|
|
129
|
-
if (!_Database.instance) {
|
|
130
|
-
throw new Error(
|
|
131
|
-
"Database not initialized. Call Database.setup(env.DB) first."
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
return _Database.instance;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
export {
|
|
141
|
-
__esm,
|
|
142
|
-
__commonJS,
|
|
143
|
-
Connection,
|
|
144
|
-
init_connection,
|
|
145
|
-
Database,
|
|
146
|
-
init_database
|
|
147
|
-
};
|