workers-qb 0.1.4 → 0.1.6
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 +32 -1
- package/dist/cjs/Builder.js +48 -21
- package/dist/cjs/index.js +3 -1
- package/dist/esm/Builder.js +48 -21
- package/dist/esm/index.js +2 -1
- package/dist/types/Builder.d.ts +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/interfaces.d.ts +1 -1
- package/dist/umd/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Read the documentation [Here](https://workers-qb.massadas.com/)!
|
|
|
20
20
|
- [x] On Conflict for Inserts and Updates
|
|
21
21
|
- [x] Create/drop tables
|
|
22
22
|
- [x] Keep where conditions simple in code
|
|
23
|
-
- [
|
|
23
|
+
- [x] Bulk insert
|
|
24
24
|
- [ ] Named parameters (waiting for full support in D1)
|
|
25
25
|
|
|
26
26
|
## Installation
|
|
@@ -110,6 +110,37 @@ const inserted = await qb.insert({
|
|
|
110
110
|
console.log(inserted) // This will contain the data after SQL triggers and primary keys that are automated
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
+
## Bulk Inserting rows
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { Raw } from 'workers-qb'
|
|
117
|
+
const qb = new D1QB(env.DB)
|
|
118
|
+
|
|
119
|
+
const inserted = await qb.insert({
|
|
120
|
+
tableName: 'employees',
|
|
121
|
+
data: [
|
|
122
|
+
{
|
|
123
|
+
name: 'Joe',
|
|
124
|
+
role: 'manager',
|
|
125
|
+
department: 'store',
|
|
126
|
+
created_at: new Raw('CURRENT_TIMESTAMP'),
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'John',
|
|
130
|
+
role: 'employee',
|
|
131
|
+
department: 'store',
|
|
132
|
+
created_at: new Raw('CURRENT_TIMESTAMP'),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'Mickael',
|
|
136
|
+
role: 'employee',
|
|
137
|
+
department: 'store',
|
|
138
|
+
created_at: new Raw('CURRENT_TIMESTAMP'),
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
})
|
|
142
|
+
```
|
|
143
|
+
|
|
113
144
|
#### Updating rows
|
|
114
145
|
|
|
115
146
|
```ts
|
package/dist/cjs/Builder.js
CHANGED
|
@@ -108,10 +108,21 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
108
108
|
};
|
|
109
109
|
QueryBuilder.prototype.insert = function (params) {
|
|
110
110
|
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
-
|
|
111
|
+
var args, _i, _a, row;
|
|
112
|
+
return __generator(this, function (_b) {
|
|
113
|
+
args = [];
|
|
114
|
+
if (Array.isArray(params.data)) {
|
|
115
|
+
for (_i = 0, _a = params.data; _i < _a.length; _i++) {
|
|
116
|
+
row = _a[_i];
|
|
117
|
+
args = args.concat(this._parse_arguments(row));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
args = args.concat(this._parse_arguments(params.data));
|
|
122
|
+
}
|
|
112
123
|
return [2 /*return*/, this.execute({
|
|
113
124
|
query: this._insert(params),
|
|
114
|
-
arguments:
|
|
125
|
+
arguments: args,
|
|
115
126
|
fetchType: enums_1.FetchTypes.ALL,
|
|
116
127
|
})];
|
|
117
128
|
});
|
|
@@ -121,14 +132,9 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
121
132
|
return __awaiter(this, void 0, void 0, function () {
|
|
122
133
|
var args;
|
|
123
134
|
return __generator(this, function (_a) {
|
|
124
|
-
args =
|
|
135
|
+
args = this._parse_arguments(params.data);
|
|
125
136
|
if (params.where && params.where.params) {
|
|
126
|
-
args = params.where.params.concat(
|
|
127
|
-
if (value instanceof tools_1.Raw) {
|
|
128
|
-
return value.content;
|
|
129
|
-
}
|
|
130
|
-
return value;
|
|
131
|
-
}));
|
|
137
|
+
args = params.where.params.concat(args);
|
|
132
138
|
}
|
|
133
139
|
return [2 /*return*/, this.execute({
|
|
134
140
|
query: this._update(params),
|
|
@@ -149,6 +155,14 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
149
155
|
});
|
|
150
156
|
});
|
|
151
157
|
};
|
|
158
|
+
QueryBuilder.prototype._parse_arguments = function (row) {
|
|
159
|
+
return Object.values(row).map(function (value) {
|
|
160
|
+
if (value instanceof tools_1.Raw) {
|
|
161
|
+
return value.content;
|
|
162
|
+
}
|
|
163
|
+
return value;
|
|
164
|
+
});
|
|
165
|
+
};
|
|
152
166
|
QueryBuilder.prototype._onConflict = function (resolution) {
|
|
153
167
|
if (resolution) {
|
|
154
168
|
return "OR " + resolution + " ";
|
|
@@ -156,19 +170,32 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
156
170
|
return '';
|
|
157
171
|
};
|
|
158
172
|
QueryBuilder.prototype._insert = function (params) {
|
|
159
|
-
var
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
var rows = [];
|
|
174
|
+
if (!Array.isArray(params.data)) {
|
|
175
|
+
params.data = [params.data];
|
|
176
|
+
}
|
|
177
|
+
var columns = Object.keys(params.data[0]).join(', ');
|
|
178
|
+
var index = 1;
|
|
179
|
+
var _loop_1 = function (row) {
|
|
180
|
+
var values = [];
|
|
181
|
+
Object.entries(row).forEach(function (_a) {
|
|
182
|
+
var key = _a[0], value = _a[1];
|
|
183
|
+
if (value instanceof tools_1.Raw) {
|
|
184
|
+
values.push(value.content);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
values.push("?" + index);
|
|
188
|
+
}
|
|
189
|
+
index += 1;
|
|
190
|
+
});
|
|
191
|
+
rows.push("(" + values.join(', ') + ")");
|
|
192
|
+
};
|
|
193
|
+
for (var _i = 0, _a = params.data; _i < _a.length; _i++) {
|
|
194
|
+
var row = _a[_i];
|
|
195
|
+
_loop_1(row);
|
|
196
|
+
}
|
|
170
197
|
return ("INSERT " + this._onConflict(params.onConflict) + "INTO " + params.tableName + " (" + columns + ")" +
|
|
171
|
-
(" VALUES
|
|
198
|
+
(" VALUES " + rows.join(', ')) +
|
|
172
199
|
this._returning(params.returning));
|
|
173
200
|
};
|
|
174
201
|
QueryBuilder.prototype._update = function (params) {
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FetchTypes = exports.OrderTypes = exports.D1QB = exports.QueryBuilder = void 0;
|
|
3
|
+
exports.Raw = exports.FetchTypes = exports.OrderTypes = exports.D1QB = exports.QueryBuilder = void 0;
|
|
4
4
|
var Builder_1 = require("./Builder");
|
|
5
5
|
Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return Builder_1.QueryBuilder; } });
|
|
6
6
|
var Databases_1 = require("./Databases");
|
|
@@ -8,3 +8,5 @@ Object.defineProperty(exports, "D1QB", { enumerable: true, get: function () { re
|
|
|
8
8
|
var enums_1 = require("./enums");
|
|
9
9
|
Object.defineProperty(exports, "OrderTypes", { enumerable: true, get: function () { return enums_1.OrderTypes; } });
|
|
10
10
|
Object.defineProperty(exports, "FetchTypes", { enumerable: true, get: function () { return enums_1.FetchTypes; } });
|
|
11
|
+
var tools_1 = require("./tools");
|
|
12
|
+
Object.defineProperty(exports, "Raw", { enumerable: true, get: function () { return tools_1.Raw; } });
|
package/dist/esm/Builder.js
CHANGED
|
@@ -105,10 +105,21 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
105
105
|
};
|
|
106
106
|
QueryBuilder.prototype.insert = function (params) {
|
|
107
107
|
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
-
|
|
108
|
+
var args, _i, _a, row;
|
|
109
|
+
return __generator(this, function (_b) {
|
|
110
|
+
args = [];
|
|
111
|
+
if (Array.isArray(params.data)) {
|
|
112
|
+
for (_i = 0, _a = params.data; _i < _a.length; _i++) {
|
|
113
|
+
row = _a[_i];
|
|
114
|
+
args = args.concat(this._parse_arguments(row));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
args = args.concat(this._parse_arguments(params.data));
|
|
119
|
+
}
|
|
109
120
|
return [2 /*return*/, this.execute({
|
|
110
121
|
query: this._insert(params),
|
|
111
|
-
arguments:
|
|
122
|
+
arguments: args,
|
|
112
123
|
fetchType: FetchTypes.ALL,
|
|
113
124
|
})];
|
|
114
125
|
});
|
|
@@ -118,14 +129,9 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
118
129
|
return __awaiter(this, void 0, void 0, function () {
|
|
119
130
|
var args;
|
|
120
131
|
return __generator(this, function (_a) {
|
|
121
|
-
args =
|
|
132
|
+
args = this._parse_arguments(params.data);
|
|
122
133
|
if (params.where && params.where.params) {
|
|
123
|
-
args = params.where.params.concat(
|
|
124
|
-
if (value instanceof Raw) {
|
|
125
|
-
return value.content;
|
|
126
|
-
}
|
|
127
|
-
return value;
|
|
128
|
-
}));
|
|
134
|
+
args = params.where.params.concat(args);
|
|
129
135
|
}
|
|
130
136
|
return [2 /*return*/, this.execute({
|
|
131
137
|
query: this._update(params),
|
|
@@ -146,6 +152,14 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
146
152
|
});
|
|
147
153
|
});
|
|
148
154
|
};
|
|
155
|
+
QueryBuilder.prototype._parse_arguments = function (row) {
|
|
156
|
+
return Object.values(row).map(function (value) {
|
|
157
|
+
if (value instanceof Raw) {
|
|
158
|
+
return value.content;
|
|
159
|
+
}
|
|
160
|
+
return value;
|
|
161
|
+
});
|
|
162
|
+
};
|
|
149
163
|
QueryBuilder.prototype._onConflict = function (resolution) {
|
|
150
164
|
if (resolution) {
|
|
151
165
|
return "OR " + resolution + " ";
|
|
@@ -153,19 +167,32 @@ var QueryBuilder = /** @class */ (function () {
|
|
|
153
167
|
return '';
|
|
154
168
|
};
|
|
155
169
|
QueryBuilder.prototype._insert = function (params) {
|
|
156
|
-
var
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
170
|
+
var rows = [];
|
|
171
|
+
if (!Array.isArray(params.data)) {
|
|
172
|
+
params.data = [params.data];
|
|
173
|
+
}
|
|
174
|
+
var columns = Object.keys(params.data[0]).join(', ');
|
|
175
|
+
var index = 1;
|
|
176
|
+
var _loop_1 = function (row) {
|
|
177
|
+
var values = [];
|
|
178
|
+
Object.entries(row).forEach(function (_a) {
|
|
179
|
+
var key = _a[0], value = _a[1];
|
|
180
|
+
if (value instanceof Raw) {
|
|
181
|
+
values.push(value.content);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
values.push("?" + index);
|
|
185
|
+
}
|
|
186
|
+
index += 1;
|
|
187
|
+
});
|
|
188
|
+
rows.push("(" + values.join(', ') + ")");
|
|
189
|
+
};
|
|
190
|
+
for (var _i = 0, _a = params.data; _i < _a.length; _i++) {
|
|
191
|
+
var row = _a[_i];
|
|
192
|
+
_loop_1(row);
|
|
193
|
+
}
|
|
167
194
|
return ("INSERT " + this._onConflict(params.onConflict) + "INTO " + params.tableName + " (" + columns + ")" +
|
|
168
|
-
(" VALUES
|
|
195
|
+
(" VALUES " + rows.join(', ')) +
|
|
169
196
|
this._returning(params.returning));
|
|
170
197
|
};
|
|
171
198
|
QueryBuilder.prototype._update = function (params) {
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { QueryBuilder } from './Builder';
|
|
2
2
|
import { D1QB } from './Databases';
|
|
3
3
|
import { OrderTypes, FetchTypes } from './enums';
|
|
4
|
-
|
|
4
|
+
import { Raw } from './tools';
|
|
5
|
+
export { QueryBuilder, D1QB, OrderTypes, FetchTypes, Raw };
|
package/dist/types/Builder.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class QueryBuilder {
|
|
|
21
21
|
insert(params: Insert): Promise<Result>;
|
|
22
22
|
update(params: Update): Promise<Result>;
|
|
23
23
|
delete(params: Delete): Promise<Result>;
|
|
24
|
+
_parse_arguments(row: Record<string, string | boolean | number | null | Raw>): Array<any>;
|
|
24
25
|
_onConflict(resolution?: string | ConflictTypes): string;
|
|
25
26
|
_insert(params: Insert): string;
|
|
26
27
|
_update(params: Update): string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import { QueryBuilder } from './Builder';
|
|
|
2
2
|
import { D1QB } from './Databases';
|
|
3
3
|
import { OrderTypes, FetchTypes } from './enums';
|
|
4
4
|
import { Where, Insert, Update, Delete, SelectAll, SelectOne } from './interfaces';
|
|
5
|
-
|
|
5
|
+
import { Raw } from './tools';
|
|
6
|
+
export { QueryBuilder, D1QB, OrderTypes, FetchTypes, Where, Insert, Update, Delete, SelectAll, SelectOne, Raw };
|
|
@@ -24,7 +24,7 @@ export interface SelectAll extends SelectOne {
|
|
|
24
24
|
}
|
|
25
25
|
export interface Insert {
|
|
26
26
|
tableName: string;
|
|
27
|
-
data: Record<string, string | boolean | number | null | Raw
|
|
27
|
+
data: Record<string, string | boolean | number | null | Raw> | Array<Record<string, string | boolean | number | null | Raw>>;
|
|
28
28
|
returning?: string | Array<string>;
|
|
29
29
|
onConflict?: string | ConflictTypes;
|
|
30
30
|
}
|
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,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})()}));
|
|
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{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,a)}c((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:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){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,a])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.QueryBuilder=void 0;var u=r(40),a=r(235),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+"\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(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(){var t,r,n,o;return i(this,(function(i){if(t=[],Array.isArray(e.data))for(r=0,n=e.data;r<n.length;r++)o=n[r],t=t.concat(this._parse_arguments(o));else t=t.concat(this._parse_arguments(e.data));return[2,this.execute({query:this._insert(e),arguments:t,fetchType:u.FetchTypes.ALL})]}))}))},e.prototype.update=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(r){return t=this._parse_arguments(e.data),e.where&&e.where.params&&(t=e.where.params.concat(t)),[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._parse_arguments=function(e){return Object.values(e).map((function(e){return e instanceof a.Raw?e.content:e}))},e.prototype._onConflict=function(e){return e?"OR "+e+" ":""},e.prototype._insert=function(e){var t=[];Array.isArray(e.data)||(e.data=[e.data]);for(var r=Object.keys(e.data[0]).join(", "),n=1,o=function(e){var r=[];Object.entries(e).forEach((function(e){e[0];var t=e[1];t instanceof a.Raw?r.push(t.content):r.push("?"+n),n+=1})),t.push("("+r.join(", ")+")")},i=0,u=e.data;i<u.length;i++)o(u[i]);return"INSERT "+this._onConflict(e.onConflict)+"INTO "+e.tableName+" ("+r+") VALUES "+t.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],i=e[1];i instanceof a.Raw?n.push(o+" = "+i.content):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){if(!e)return"";Array.isArray(e)||(e=[e]);var t=[];return e.forEach((function(e){var r=e.type?e.type+" ":"";t.push(r+"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 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{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,a)}c((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:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){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,a])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.D1QB=void 0;var a=r(501),c=r(40),s=r(235),f=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,r;return u(this,(function(n){return t=this.db.prepare(e.query),e.arguments&&(r=e.arguments.map((function(e){return e instanceof s.Raw?e.content:e})),t=t.bind.apply(t,r)),e.fetchType===c.FetchTypes.ONE?[2,t.first()]:e.fetchType===c.FetchTypes.ALL?[2,t.all()]:[2,t.run()]}))}))},t}(a.QueryBuilder);t.D1QB=f},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"},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 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.Raw=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}});var u=r(235);Object.defineProperty(e,"Raw",{enumerable:!0,get:function(){return u.Raw}})})(),n})()}));
|