workers-qb 0.1.3 → 0.1.4
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 +4 -1
- package/dist/cjs/Builder.js +40 -12
- package/dist/cjs/Databases.js +9 -2
- package/dist/cjs/tools.js +11 -0
- package/dist/esm/Builder.js +40 -12
- package/dist/esm/Databases.js +9 -2
- package/dist/esm/tools.js +8 -0
- package/dist/types/Builder.d.ts +4 -3
- package/dist/types/Databases.d.ts +3 -2
- package/dist/types/interfaces.d.ts +4 -3
- package/dist/types/tools.d.ts +5 -0
- package/dist/umd/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,8 @@ Read the documentation [Here](https://workers-qb.massadas.com/)!
|
|
|
16
16
|
- [x] Zero dependencies.
|
|
17
17
|
- [x] Fully typed/TypeScript support
|
|
18
18
|
- [x] SQL Type checking with compatible IDE's
|
|
19
|
-
- [x] Insert/Update/Select/Delete queries
|
|
19
|
+
- [x] Insert/Update/Select/Delete/Join queries
|
|
20
|
+
- [x] On Conflict for Inserts and Updates
|
|
20
21
|
- [x] Create/drop tables
|
|
21
22
|
- [x] Keep where conditions simple in code
|
|
22
23
|
- [ ] Bulk insert/update
|
|
@@ -92,6 +93,7 @@ fetched.results.forEach((employee) => {
|
|
|
92
93
|
#### Inserting rows
|
|
93
94
|
|
|
94
95
|
```ts
|
|
96
|
+
import { Raw } from 'workers-qb'
|
|
95
97
|
const qb = new D1QB(env.DB)
|
|
96
98
|
|
|
97
99
|
const inserted = await qb.insert({
|
|
@@ -100,6 +102,7 @@ const inserted = await qb.insert({
|
|
|
100
102
|
name: 'Joe',
|
|
101
103
|
role: 'manager',
|
|
102
104
|
department: 'store',
|
|
105
|
+
created_at: new Raw('CURRENT_TIMESTAMP'),
|
|
103
106
|
},
|
|
104
107
|
returning: '*',
|
|
105
108
|
})
|
package/dist/cjs/Builder.js
CHANGED
|
@@ -49,6 +49,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.QueryBuilder = void 0;
|
|
51
51
|
var enums_1 = require("./enums");
|
|
52
|
+
var tools_1 = require("./tools");
|
|
52
53
|
var QueryBuilder = /** @class */ (function () {
|
|
53
54
|
function QueryBuilder() {
|
|
54
55
|
}
|
|
@@ -63,7 +64,7 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
63
64
|
return __awaiter(this, void 0, void 0, function () {
|
|
64
65
|
return __generator(this, function (_a) {
|
|
65
66
|
return [2 /*return*/, this.execute({
|
|
66
|
-
query: "CREATE TABLE " + (params.ifNotExists ? 'IF NOT EXISTS' : '') + " " + params.tableName + "
|
|
67
|
+
query: "CREATE TABLE " + (params.ifNotExists ? 'IF NOT EXISTS' : '') + " " + params.tableName + "\n (\n " + params.schema + "\n )",
|
|
67
68
|
})];
|
|
68
69
|
});
|
|
69
70
|
});
|
|
@@ -118,12 +119,20 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
118
119
|
};
|
|
119
120
|
QueryBuilder.prototype.update = function (params) {
|
|
120
121
|
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
+
var args;
|
|
121
123
|
return __generator(this, function (_a) {
|
|
124
|
+
args = Object.values(params.data);
|
|
125
|
+
if (params.where && params.where.params) {
|
|
126
|
+
args = params.where.params.concat(Object.values(params.data).map(function (value) {
|
|
127
|
+
if (value instanceof tools_1.Raw) {
|
|
128
|
+
return value.content;
|
|
129
|
+
}
|
|
130
|
+
return value;
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
122
133
|
return [2 /*return*/, this.execute({
|
|
123
134
|
query: this._update(params),
|
|
124
|
-
arguments:
|
|
125
|
-
? params.where.params.concat(Object.values(params.data))
|
|
126
|
-
: Object.values(params.data),
|
|
135
|
+
arguments: args,
|
|
127
136
|
fetchType: enums_1.FetchTypes.ALL,
|
|
128
137
|
})];
|
|
129
138
|
});
|
|
@@ -149,10 +158,18 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
149
158
|
QueryBuilder.prototype._insert = function (params) {
|
|
150
159
|
var columns = Object.keys(params.data).join(', ');
|
|
151
160
|
var values = [];
|
|
152
|
-
Object.
|
|
153
|
-
|
|
161
|
+
Object.entries(params.data).forEach(function (_a, index) {
|
|
162
|
+
var key = _a[0], value = _a[1];
|
|
163
|
+
if (value instanceof tools_1.Raw) {
|
|
164
|
+
values.push(value.content);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
values.push("?" + (index + 1));
|
|
168
|
+
}
|
|
154
169
|
});
|
|
155
|
-
return ("INSERT " + this._onConflict(params.onConflict) + "INTO " + params.tableName + " (" + columns + ")
|
|
170
|
+
return ("INSERT " + this._onConflict(params.onConflict) + "INTO " + params.tableName + " (" + columns + ")" +
|
|
171
|
+
(" VALUES(" + values.join(', ') + ")") +
|
|
172
|
+
this._returning(params.returning));
|
|
156
173
|
};
|
|
157
174
|
QueryBuilder.prototype._update = function (params) {
|
|
158
175
|
var _a;
|
|
@@ -160,7 +177,12 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
160
177
|
var set = [];
|
|
161
178
|
Object.entries(params.data).forEach(function (_a, index) {
|
|
162
179
|
var key = _a[0], value = _a[1];
|
|
163
|
-
|
|
180
|
+
if (value instanceof tools_1.Raw) {
|
|
181
|
+
set.push(key + " = " + value.content);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
set.push(key + " = ?" + (whereParamsLength + index + 1));
|
|
185
|
+
}
|
|
164
186
|
});
|
|
165
187
|
return ("UPDATE " + this._onConflict(params.onConflict) + params.tableName + " SET " + set.join(', ') +
|
|
166
188
|
this._where((_a = params.where) === null || _a === void 0 ? void 0 : _a.conditions) +
|
|
@@ -196,8 +218,15 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
196
218
|
QueryBuilder.prototype._join = function (value) {
|
|
197
219
|
if (!value)
|
|
198
220
|
return '';
|
|
199
|
-
|
|
200
|
-
|
|
221
|
+
if (!Array.isArray(value)) {
|
|
222
|
+
value = [value];
|
|
223
|
+
}
|
|
224
|
+
var joinQuery = [];
|
|
225
|
+
value.forEach(function (item) {
|
|
226
|
+
var type = item.type ? item.type + " " : '';
|
|
227
|
+
joinQuery.push(type + "JOIN " + item.table + " ON " + item.on);
|
|
228
|
+
});
|
|
229
|
+
return ' ' + joinQuery.join(' ');
|
|
201
230
|
};
|
|
202
231
|
QueryBuilder.prototype._groupBy = function (value) {
|
|
203
232
|
if (!value)
|
|
@@ -216,8 +245,7 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
216
245
|
return '';
|
|
217
246
|
if (typeof value === 'string')
|
|
218
247
|
return " ORDER BY " + value;
|
|
219
|
-
if (
|
|
220
|
-
// @ts-ignore
|
|
248
|
+
if (Array.isArray(value)) {
|
|
221
249
|
return " ORDER BY " + value.join(', ');
|
|
222
250
|
}
|
|
223
251
|
var order = [];
|
package/dist/cjs/Databases.js
CHANGED
|
@@ -54,6 +54,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
54
54
|
exports.D1QB = void 0;
|
|
55
55
|
var Builder_1 = require("./Builder");
|
|
56
56
|
var enums_1 = require("./enums");
|
|
57
|
+
var tools_1 = require("./tools");
|
|
57
58
|
var D1QB = /** @class */ (function (_super) {
|
|
58
59
|
__extends(D1QB, _super);
|
|
59
60
|
function D1QB(db) {
|
|
@@ -63,11 +64,17 @@ var D1QB = /** @class */ (function (_super) {
|
|
|
63
64
|
}
|
|
64
65
|
D1QB.prototype.execute = function (params) {
|
|
65
66
|
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
var stmt;
|
|
67
|
+
var stmt, args;
|
|
67
68
|
return __generator(this, function (_a) {
|
|
68
69
|
stmt = this.db.prepare(params.query);
|
|
69
70
|
if (params.arguments) {
|
|
70
|
-
|
|
71
|
+
args = params.arguments.map(function (value) {
|
|
72
|
+
if (value instanceof tools_1.Raw) {
|
|
73
|
+
return value.content;
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
});
|
|
77
|
+
stmt = stmt.bind.apply(stmt, args);
|
|
71
78
|
}
|
|
72
79
|
if (params.fetchType === enums_1.FetchTypes.ONE) {
|
|
73
80
|
return [2 /*return*/, stmt.first()];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Raw = void 0;
|
|
4
|
+
var Raw = /** @class */ (function () {
|
|
5
|
+
function Raw(content) {
|
|
6
|
+
this.isRaw = true;
|
|
7
|
+
this.content = content;
|
|
8
|
+
}
|
|
9
|
+
return Raw;
|
|
10
|
+
}());
|
|
11
|
+
exports.Raw = Raw;
|
package/dist/esm/Builder.js
CHANGED
|
@@ -46,6 +46,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
import { FetchTypes } from './enums';
|
|
49
|
+
import { Raw } from './tools';
|
|
49
50
|
var QueryBuilder = /** @class */ (function () {
|
|
50
51
|
function QueryBuilder() {
|
|
51
52
|
}
|
|
@@ -60,7 +61,7 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
60
61
|
return __awaiter(this, void 0, void 0, function () {
|
|
61
62
|
return __generator(this, function (_a) {
|
|
62
63
|
return [2 /*return*/, this.execute({
|
|
63
|
-
query: "CREATE TABLE " + (params.ifNotExists ? 'IF NOT EXISTS' : '') + " " + params.tableName + "
|
|
64
|
+
query: "CREATE TABLE " + (params.ifNotExists ? 'IF NOT EXISTS' : '') + " " + params.tableName + "\n (\n " + params.schema + "\n )",
|
|
64
65
|
})];
|
|
65
66
|
});
|
|
66
67
|
});
|
|
@@ -115,12 +116,20 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
115
116
|
};
|
|
116
117
|
QueryBuilder.prototype.update = function (params) {
|
|
117
118
|
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
var args;
|
|
118
120
|
return __generator(this, function (_a) {
|
|
121
|
+
args = Object.values(params.data);
|
|
122
|
+
if (params.where && params.where.params) {
|
|
123
|
+
args = params.where.params.concat(Object.values(params.data).map(function (value) {
|
|
124
|
+
if (value instanceof Raw) {
|
|
125
|
+
return value.content;
|
|
126
|
+
}
|
|
127
|
+
return value;
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
119
130
|
return [2 /*return*/, this.execute({
|
|
120
131
|
query: this._update(params),
|
|
121
|
-
arguments:
|
|
122
|
-
? params.where.params.concat(Object.values(params.data))
|
|
123
|
-
: Object.values(params.data),
|
|
132
|
+
arguments: args,
|
|
124
133
|
fetchType: FetchTypes.ALL,
|
|
125
134
|
})];
|
|
126
135
|
});
|
|
@@ -146,10 +155,18 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
146
155
|
QueryBuilder.prototype._insert = function (params) {
|
|
147
156
|
var columns = Object.keys(params.data).join(', ');
|
|
148
157
|
var values = [];
|
|
149
|
-
Object.
|
|
150
|
-
|
|
158
|
+
Object.entries(params.data).forEach(function (_a, index) {
|
|
159
|
+
var key = _a[0], value = _a[1];
|
|
160
|
+
if (value instanceof Raw) {
|
|
161
|
+
values.push(value.content);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
values.push("?" + (index + 1));
|
|
165
|
+
}
|
|
151
166
|
});
|
|
152
|
-
return ("INSERT " + this._onConflict(params.onConflict) + "INTO " + params.tableName + " (" + columns + ")
|
|
167
|
+
return ("INSERT " + this._onConflict(params.onConflict) + "INTO " + params.tableName + " (" + columns + ")" +
|
|
168
|
+
(" VALUES(" + values.join(', ') + ")") +
|
|
169
|
+
this._returning(params.returning));
|
|
153
170
|
};
|
|
154
171
|
QueryBuilder.prototype._update = function (params) {
|
|
155
172
|
var _a;
|
|
@@ -157,7 +174,12 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
157
174
|
var set = [];
|
|
158
175
|
Object.entries(params.data).forEach(function (_a, index) {
|
|
159
176
|
var key = _a[0], value = _a[1];
|
|
160
|
-
|
|
177
|
+
if (value instanceof Raw) {
|
|
178
|
+
set.push(key + " = " + value.content);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
set.push(key + " = ?" + (whereParamsLength + index + 1));
|
|
182
|
+
}
|
|
161
183
|
});
|
|
162
184
|
return ("UPDATE " + this._onConflict(params.onConflict) + params.tableName + " SET " + set.join(', ') +
|
|
163
185
|
this._where((_a = params.where) === null || _a === void 0 ? void 0 : _a.conditions) +
|
|
@@ -193,8 +215,15 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
193
215
|
QueryBuilder.prototype._join = function (value) {
|
|
194
216
|
if (!value)
|
|
195
217
|
return '';
|
|
196
|
-
|
|
197
|
-
|
|
218
|
+
if (!Array.isArray(value)) {
|
|
219
|
+
value = [value];
|
|
220
|
+
}
|
|
221
|
+
var joinQuery = [];
|
|
222
|
+
value.forEach(function (item) {
|
|
223
|
+
var type = item.type ? item.type + " " : '';
|
|
224
|
+
joinQuery.push(type + "JOIN " + item.table + " ON " + item.on);
|
|
225
|
+
});
|
|
226
|
+
return ' ' + joinQuery.join(' ');
|
|
198
227
|
};
|
|
199
228
|
QueryBuilder.prototype._groupBy = function (value) {
|
|
200
229
|
if (!value)
|
|
@@ -213,8 +242,7 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
213
242
|
return '';
|
|
214
243
|
if (typeof value === 'string')
|
|
215
244
|
return " ORDER BY " + value;
|
|
216
|
-
if (
|
|
217
|
-
// @ts-ignore
|
|
245
|
+
if (Array.isArray(value)) {
|
|
218
246
|
return " ORDER BY " + value.join(', ');
|
|
219
247
|
}
|
|
220
248
|
var order = [];
|
package/dist/esm/Databases.js
CHANGED
|
@@ -51,6 +51,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
51
51
|
};
|
|
52
52
|
import { QueryBuilder } from './Builder';
|
|
53
53
|
import { FetchTypes } from './enums';
|
|
54
|
+
import { Raw } from './tools';
|
|
54
55
|
var D1QB = /** @class */ (function (_super) {
|
|
55
56
|
__extends(D1QB, _super);
|
|
56
57
|
function D1QB(db) {
|
|
@@ -60,11 +61,17 @@ var D1QB = /** @class */ (function (_super) {
|
|
|
60
61
|
}
|
|
61
62
|
D1QB.prototype.execute = function (params) {
|
|
62
63
|
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
var stmt;
|
|
64
|
+
var stmt, args;
|
|
64
65
|
return __generator(this, function (_a) {
|
|
65
66
|
stmt = this.db.prepare(params.query);
|
|
66
67
|
if (params.arguments) {
|
|
67
|
-
|
|
68
|
+
args = params.arguments.map(function (value) {
|
|
69
|
+
if (value instanceof Raw) {
|
|
70
|
+
return value.content;
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
});
|
|
74
|
+
stmt = stmt.bind.apply(stmt, args);
|
|
68
75
|
}
|
|
69
76
|
if (params.fetchType === FetchTypes.ONE) {
|
|
70
77
|
return [2 /*return*/, stmt.first()];
|
package/dist/types/Builder.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Delete, Insert, Join, Result, ResultOne, SelectAll, SelectOne, Update } from './interfaces';
|
|
2
2
|
import { ConflictTypes, FetchTypes, OrderTypes } from './enums';
|
|
3
|
+
import { Raw } from './tools';
|
|
3
4
|
export declare class QueryBuilder {
|
|
4
5
|
execute(params: {
|
|
5
|
-
query:
|
|
6
|
-
arguments?: (string | number | boolean | null)[];
|
|
6
|
+
query: string;
|
|
7
|
+
arguments?: (string | number | boolean | null | Raw)[];
|
|
7
8
|
fetchType?: FetchTypes;
|
|
8
9
|
}): Promise<any>;
|
|
9
10
|
createTable(params: {
|
|
@@ -27,7 +28,7 @@ export declare class QueryBuilder {
|
|
|
27
28
|
_select(params: SelectAll): string;
|
|
28
29
|
_fields(value: string | Array<string>): string;
|
|
29
30
|
_where(value?: string | Array<string>): string;
|
|
30
|
-
_join(value?: Join): string;
|
|
31
|
+
_join(value?: Join | Array<Join>): string;
|
|
31
32
|
_groupBy(value?: string | Array<string>): string;
|
|
32
33
|
_having(value?: string): string;
|
|
33
34
|
_orderBy(value?: string | Array<string> | Record<string, string | OrderTypes>): string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { QueryBuilder } from './Builder';
|
|
2
2
|
import { FetchTypes } from './enums';
|
|
3
|
+
import { Raw } from './tools';
|
|
3
4
|
export declare class D1QB extends QueryBuilder {
|
|
4
5
|
private db;
|
|
5
6
|
constructor(db: any);
|
|
6
7
|
execute(params: {
|
|
7
|
-
query:
|
|
8
|
-
arguments?: (string | number | boolean | null)[];
|
|
8
|
+
query: string;
|
|
9
|
+
arguments?: (string | number | boolean | null | Raw)[];
|
|
9
10
|
fetchType?: FetchTypes;
|
|
10
11
|
}): Promise<any>;
|
|
11
12
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConflictTypes, JoinTypes, OrderTypes } from './enums';
|
|
2
|
+
import { Raw } from './tools';
|
|
2
3
|
export interface Where {
|
|
3
4
|
conditions: string | Array<string>;
|
|
4
5
|
params?: (string | boolean | number | null)[];
|
|
@@ -12,7 +13,7 @@ export interface SelectOne {
|
|
|
12
13
|
tableName: string;
|
|
13
14
|
fields: string | Array<string>;
|
|
14
15
|
where?: Where;
|
|
15
|
-
join?: Join
|
|
16
|
+
join?: Join | Array<Join>;
|
|
16
17
|
groupBy?: string | Array<string>;
|
|
17
18
|
having?: string;
|
|
18
19
|
orderBy?: string | Array<string> | Record<string, string | OrderTypes>;
|
|
@@ -23,13 +24,13 @@ export interface SelectAll extends SelectOne {
|
|
|
23
24
|
}
|
|
24
25
|
export interface Insert {
|
|
25
26
|
tableName: string;
|
|
26
|
-
data: Record<string, string | boolean | number | null>;
|
|
27
|
+
data: Record<string, string | boolean | number | null | Raw>;
|
|
27
28
|
returning?: string | Array<string>;
|
|
28
29
|
onConflict?: string | ConflictTypes;
|
|
29
30
|
}
|
|
30
31
|
export interface Update {
|
|
31
32
|
tableName: string;
|
|
32
|
-
data: Record<string, string | boolean | number | null>;
|
|
33
|
+
data: Record<string, string | boolean | number | null | Raw>;
|
|
33
34
|
where: Where;
|
|
34
35
|
returning?: string | Array<string>;
|
|
35
36
|
onConflict?: string | ConflictTypes;
|
package/dist/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["workers-qb"]=t():e["workers-qb"]=t()}(this,(function(){return(()=>{"use strict";var e={501:function(e,t,r){var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)},o=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function u(e){try{s(n.next(e))}catch(e){i(e)}}function c(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,c)}s((n=n.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.QueryBuilder=void 0;var u=r(40),c=function(){function e(){}return e.prototype.execute=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("Execute method not implemented")}))}))},e.prototype.createTable=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:"CREATE TABLE "+(e.ifNotExists?"IF NOT EXISTS":"")+" "+e.tableName+" ("+e.schema+")"})]}))}))},e.prototype.dropTable=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:"DROP TABLE "+(e.ifExists?"IF EXISTS":"")+" "+e.tableName})]}))}))},e.prototype.fetchOne=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(r){switch(r.label){case 0:return[4,this.execute({query:this._select(n(n({},e),{limit:1})),arguments:e.where?e.where.params:void 0,fetchType:u.FetchTypes.ALL})];case 1:return t=r.sent(),[2,n(n({},t),{results:t.results[0]})]}}))}))},e.prototype.fetchAll=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:this._select(e),arguments:e.where?e.where.params:void 0,fetchType:u.FetchTypes.ALL})]}))}))},e.prototype.insert=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:this._insert(e),arguments:Object.values(e.data),fetchType:u.FetchTypes.ALL})]}))}))},e.prototype.update=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:this._update(e),arguments:e.where&&e.where.params?e.where.params.concat(Object.values(e.data)):Object.values(e.data),fetchType:u.FetchTypes.ALL})]}))}))},e.prototype.delete=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:this._delete(e),arguments:e.where?e.where.params:void 0,fetchType:u.FetchTypes.ALL})]}))}))},e.prototype._onConflict=function(e){return e?"OR "+e+" ":""},e.prototype._insert=function(e){var t=Object.keys(e.data).join(", "),r=[];return Object.keys(e.data).forEach((function(e,t){r.push("?"+(t+1))})),"INSERT "+this._onConflict(e.onConflict)+"INTO "+e.tableName+" ("+t+") VALUES("+r.join(", ")+")"+this._returning(e.returning)},e.prototype._update=function(e){var t,r=e.where&&e.where.params?Object.keys(e.where.params).length:0,n=[];return Object.entries(e.data).forEach((function(e,t){var o=e[0];e[1],n.push(o+" = ?"+(r+t+1))})),"UPDATE "+this._onConflict(e.onConflict)+e.tableName+" SET "+n.join(", ")+this._where(null===(t=e.where)||void 0===t?void 0:t.conditions)+this._returning(e.returning)},e.prototype._delete=function(e){var t;return"DELETE FROM "+e.tableName+this._where(null===(t=e.where)||void 0===t?void 0:t.conditions)+this._returning(e.returning)},e.prototype._select=function(e){var t;return"SELECT "+this._fields(e.fields)+" FROM "+e.tableName+this._join(e.join)+this._where(null===(t=e.where)||void 0===t?void 0:t.conditions)+this._groupBy(e.groupBy)+this._having(e.having)+this._orderBy(e.orderBy)+this._limit(e.limit)+this._offset(e.offset)},e.prototype._fields=function(e){return"string"==typeof e?e:e.join(", ")},e.prototype._where=function(e){return e?"string"==typeof e?" WHERE "+e:" WHERE "+e.join(" AND "):""},e.prototype._join=function(e){return e?(e.type?" "+e.type:"")+" JOIN "+e.table+" ON "+e.on:""},e.prototype._groupBy=function(e){return e?"string"==typeof e?" GROUP BY "+e:" GROUP BY "+e.join(", "):""},e.prototype._having=function(e){return e?" HAVING "+e:""},e.prototype._orderBy=function(e){if(!e)return"";if("string"==typeof e)return" ORDER BY "+e;if("array"===e.constructor.name.toLowerCase())return" ORDER BY "+e.join(", ");var t=[];return Object.entries(e).forEach((function(e){var r=e[0],n=e[1];t.push(r+" "+n)}))," ORDER BY "+t.join(", ")},e.prototype._limit=function(e){return e?" LIMIT "+e:""},e.prototype._offset=function(e){return e?" OFFSET "+e:""},e.prototype._returning=function(e){return e?"string"==typeof e?" RETURNING "+e:" RETURNING "+e.join(", "):""},e}();t.QueryBuilder=c},513:function(e,t,r){var n,o=this&&this.__extends||(n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),i=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function u(e){try{s(n.next(e))}catch(e){i(e)}}function c(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,c)}s((n=n.apply(e,t||[])).next())}))},u=this&&this.__generator||function(e,t){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.D1QB=void 0;var c=r(501),s=r(40),a=function(e){function t(t){var r=e.call(this)||this;return r.db=t,r}return o(t,e),t.prototype.execute=function(e){return i(this,void 0,void 0,(function(){var t;return u(this,(function(r){return t=this.db.prepare(e.query),e.arguments&&(t=t.bind.apply(t,e.arguments)),e.fetchType===s.FetchTypes.ONE?[2,t.first()]:e.fetchType===s.FetchTypes.ALL?[2,t.all()]:[2,t.run()]}))}))},t}(c.QueryBuilder);t.D1QB=a},40:(e,t)=>{var r,n,o,i;Object.defineProperty(t,"__esModule",{value:!0}),t.JoinTypes=t.ConflictTypes=t.FetchTypes=t.OrderTypes=void 0,(i=t.OrderTypes||(t.OrderTypes={})).ASC="ASC",i.DESC="DESC",(o=t.FetchTypes||(t.FetchTypes={})).ONE="ONE",o.ALL="ALL",(n=t.ConflictTypes||(t.ConflictTypes={})).ROLLBACK="ROLLBACK",n.ABORT="ABORT",n.FAIL="FAIL",n.IGNORE="IGNORE",n.REPLACE="REPLACE",(r=t.JoinTypes||(t.JoinTypes={})).INNER="INNER",r.LEFT="LEFT",r.CROSS="CROSS"}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}var n={};return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.FetchTypes=e.OrderTypes=e.D1QB=e.QueryBuilder=void 0;var t=r(501);Object.defineProperty(e,"QueryBuilder",{enumerable:!0,get:function(){return t.QueryBuilder}});var o=r(513);Object.defineProperty(e,"D1QB",{enumerable:!0,get:function(){return o.D1QB}});var i=r(40);Object.defineProperty(e,"OrderTypes",{enumerable:!0,get:function(){return i.OrderTypes}}),Object.defineProperty(e,"FetchTypes",{enumerable:!0,get:function(){return i.FetchTypes}})})(),n})()}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["workers-qb"]=t():e["workers-qb"]=t()}(this,(function(){return(()=>{"use strict";var e={501:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)},o=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}s((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.QueryBuilder=void 0;var u=n(40),c=n(235),s=function(){function e(){}return e.prototype.execute=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("Execute method not implemented")}))}))},e.prototype.createTable=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:"CREATE TABLE "+(e.ifNotExists?"IF NOT EXISTS":"")+" "+e.tableName+"\n (\n "+e.schema+"\n )"})]}))}))},e.prototype.dropTable=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:"DROP TABLE "+(e.ifExists?"IF EXISTS":"")+" "+e.tableName})]}))}))},e.prototype.fetchOne=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,this.execute({query:this._select(r(r({},e),{limit:1})),arguments:e.where?e.where.params:void 0,fetchType:u.FetchTypes.ALL})];case 1:return t=n.sent(),[2,r(r({},t),{results:t.results[0]})]}}))}))},e.prototype.fetchAll=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:this._select(e),arguments:e.where?e.where.params:void 0,fetchType:u.FetchTypes.ALL})]}))}))},e.prototype.insert=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:this._insert(e),arguments:Object.values(e.data),fetchType:u.FetchTypes.ALL})]}))}))},e.prototype.update=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=Object.values(e.data),e.where&&e.where.params&&(t=e.where.params.concat(Object.values(e.data).map((function(e){return e instanceof c.Raw?e.content:e})))),[2,this.execute({query:this._update(e),arguments:t,fetchType:u.FetchTypes.ALL})]}))}))},e.prototype.delete=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.execute({query:this._delete(e),arguments:e.where?e.where.params:void 0,fetchType:u.FetchTypes.ALL})]}))}))},e.prototype._onConflict=function(e){return e?"OR "+e+" ":""},e.prototype._insert=function(e){var t=Object.keys(e.data).join(", "),n=[];return Object.entries(e.data).forEach((function(e,t){e[0];var r=e[1];r instanceof c.Raw?n.push(r.content):n.push("?"+(t+1))})),"INSERT "+this._onConflict(e.onConflict)+"INTO "+e.tableName+" ("+t+") VALUES("+n.join(", ")+")"+this._returning(e.returning)},e.prototype._update=function(e){var t,n=e.where&&e.where.params?Object.keys(e.where.params).length:0,r=[];return Object.entries(e.data).forEach((function(e,t){var o=e[0],i=e[1];i instanceof c.Raw?r.push(o+" = "+i.content):r.push(o+" = ?"+(n+t+1))})),"UPDATE "+this._onConflict(e.onConflict)+e.tableName+" SET "+r.join(", ")+this._where(null===(t=e.where)||void 0===t?void 0:t.conditions)+this._returning(e.returning)},e.prototype._delete=function(e){var t;return"DELETE FROM "+e.tableName+this._where(null===(t=e.where)||void 0===t?void 0:t.conditions)+this._returning(e.returning)},e.prototype._select=function(e){var t;return"SELECT "+this._fields(e.fields)+" FROM "+e.tableName+this._join(e.join)+this._where(null===(t=e.where)||void 0===t?void 0:t.conditions)+this._groupBy(e.groupBy)+this._having(e.having)+this._orderBy(e.orderBy)+this._limit(e.limit)+this._offset(e.offset)},e.prototype._fields=function(e){return"string"==typeof e?e:e.join(", ")},e.prototype._where=function(e){return e?"string"==typeof e?" WHERE "+e:" WHERE "+e.join(" AND "):""},e.prototype._join=function(e){if(!e)return"";Array.isArray(e)||(e=[e]);var t=[];return e.forEach((function(e){var n=e.type?e.type+" ":"";t.push(n+"JOIN "+e.table+" ON "+e.on)}))," "+t.join(" ")},e.prototype._groupBy=function(e){return e?"string"==typeof e?" GROUP BY "+e:" GROUP BY "+e.join(", "):""},e.prototype._having=function(e){return e?" HAVING "+e:""},e.prototype._orderBy=function(e){if(!e)return"";if("string"==typeof e)return" ORDER BY "+e;if(Array.isArray(e))return" ORDER BY "+e.join(", ");var t=[];return Object.entries(e).forEach((function(e){var n=e[0],r=e[1];t.push(n+" "+r)}))," ORDER BY "+t.join(", ")},e.prototype._limit=function(e){return e?" LIMIT "+e:""},e.prototype._offset=function(e){return e?" OFFSET "+e:""},e.prototype._returning=function(e){return e?"string"==typeof e?" RETURNING "+e:" RETURNING "+e.join(", "):""},e}();t.QueryBuilder=s},513:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}s((r=r.apply(e,t||[])).next())}))},u=this&&this.__generator||function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.D1QB=void 0;var c=n(501),s=n(40),a=n(235),f=function(e){function t(t){var n=e.call(this)||this;return n.db=t,n}return o(t,e),t.prototype.execute=function(e){return i(this,void 0,void 0,(function(){var t,n;return u(this,(function(r){return t=this.db.prepare(e.query),e.arguments&&(n=e.arguments.map((function(e){return e instanceof a.Raw?e.content:e})),t=t.bind.apply(t,n)),e.fetchType===s.FetchTypes.ONE?[2,t.first()]:e.fetchType===s.FetchTypes.ALL?[2,t.all()]:[2,t.run()]}))}))},t}(c.QueryBuilder);t.D1QB=f},40:(e,t)=>{var n,r,o,i;Object.defineProperty(t,"__esModule",{value:!0}),t.JoinTypes=t.ConflictTypes=t.FetchTypes=t.OrderTypes=void 0,(i=t.OrderTypes||(t.OrderTypes={})).ASC="ASC",i.DESC="DESC",(o=t.FetchTypes||(t.FetchTypes={})).ONE="ONE",o.ALL="ALL",(r=t.ConflictTypes||(t.ConflictTypes={})).ROLLBACK="ROLLBACK",r.ABORT="ABORT",r.FAIL="FAIL",r.IGNORE="IGNORE",r.REPLACE="REPLACE",(n=t.JoinTypes||(t.JoinTypes={})).INNER="INNER",n.LEFT="LEFT",n.CROSS="CROSS"},235:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Raw=void 0;t.Raw=function(e){this.isRaw=!0,this.content=e}}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}var r={};return(()=>{var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.FetchTypes=e.OrderTypes=e.D1QB=e.QueryBuilder=void 0;var t=n(501);Object.defineProperty(e,"QueryBuilder",{enumerable:!0,get:function(){return t.QueryBuilder}});var o=n(513);Object.defineProperty(e,"D1QB",{enumerable:!0,get:function(){return o.D1QB}});var i=n(40);Object.defineProperty(e,"OrderTypes",{enumerable:!0,get:function(){return i.OrderTypes}}),Object.defineProperty(e,"FetchTypes",{enumerable:!0,get:function(){return i.FetchTypes}})})(),r})()}));
|