workers-qb 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Gabriel Massadas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # workers-qb
2
+
3
+ ## Development
4
+
5
+ ### Set up tools and environment
6
+
7
+ You need to have [Node.js](https://nodejs.org/en/download/) installed. Node includes npm as its default package manager.
8
+
9
+ Open the whole package folder with a good code editor, preferably [Visual Studio Code](https://code.visualstudio.com/download). Consider installing VS Code extensions [ES Lint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode).
10
+
11
+ In the VS Code top menu: **Terminal** -> **New Terminal**
12
+
13
+ ### Install dependencies
14
+
15
+ Install dependencies with npm:
16
+
17
+ ```bash
18
+ npm i
19
+ ```
20
+
21
+ ### Write your code
22
+
23
+ Write your code in **src** folder, and unit test in **test** folder.
24
+
25
+ The VS Code shortcuts for formatting of a code file are: <kbd>Shift</kbd> + <kbd>Alt</kbd> + <kbd>F</kbd> (Windows); <kbd>Shift</kbd> + <kbd>Option (Alt)</kbd> + <kbd>F</kbd> (MacOS); <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>I</kbd> (Linux).
26
+
27
+ ### Test
28
+
29
+ Test your code with Jest framework:
30
+
31
+ ```bash
32
+ npm run test
33
+ ```
34
+
35
+ **Note:** This project uses [husky](https://typicode.github.io/husky/), [pinst](https://github.com/typicode/pinst) and [commitlint](https://commitlint.js.org/) to automatically execute test and [lint commit message](https://www.conventionalcommits.org/) before every commit.
36
+
37
+ ### Build
38
+
39
+ Build production (distribution) files in your **dist** folder:
40
+
41
+ ```bash
42
+ npm run build
43
+ ```
44
+
45
+ It generates CommonJS (in **dist/cjs** folder), ES Modules (in **dist/esm** folder), bundled and minified UMD (in **dist/umd** folder), as well as TypeScript declaration files (in **dist/types** folder).
46
+
47
+ ### Try it before publishing
48
+
49
+ Run:
50
+
51
+ ```bash
52
+ npm link
53
+ ```
54
+
55
+ [npm link](https://docs.npmjs.com/cli/v6/commands/npm-link) will create a symlink in the global folder, which may be **{prefix}/lib/node_modules/workers-qb** or **C:\Users\<username>\AppData\Roaming\npm\node_modules\workers-qb**.
56
+
57
+ Create an empty folder elsewhere, you don't even need to `npm init` (to generate **package.json**). Open the folder with VS Code, open a terminal and just run:
58
+
59
+ ```bash
60
+ npm link workers-qb
61
+ ```
62
+
63
+ This will create a symbolic link from globally-installed workers-qb to **node_modules/** of the current folder.
64
+
65
+ You can then create a, for example, **testsql.ts** file with the content:
66
+
67
+ ```ts
68
+ import { D1QB } from 'workers-qb' TODO
69
+ const qb = new D1QB(env.DB)
70
+
71
+ console.log("Creating table...")
72
+ const created = await qb.createTable({
73
+ tableName: "testTable",
74
+ schema: `
75
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
76
+ name TEXT NOT NULL
77
+ `,
78
+ ifNotExists: true,
79
+ })
80
+ console.log(created)
81
+
82
+ console.log("Inserting rows...")
83
+ const inserted = await qb.insert({
84
+ tableName: "testTable",
85
+ data: {
86
+ name: "my name",
87
+ },
88
+ returning: "*",
89
+ })
90
+ console.log(inserted)
91
+
92
+ console.log("Selecting rows...")
93
+ const selected = await qb.fetchAll({
94
+ tableName: "testTable",
95
+ fields: "*"
96
+ })
97
+ console.log(selected)
98
+ ```
99
+
100
+ If you don't see any linting errors in VS Code, if you put your mouse cursor over `D1QB` and see its type, then it's all good.
101
+
102
+ Whenever you want to uninstall the globally-installed workers-qb and remove the symlink in the global folder, run:
103
+
104
+ ```bash
105
+ npm uninstall workers-qb -g
106
+ ```
107
+
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.QueryBuilder = void 0;
51
+ var enums_1 = require("./enums");
52
+ var QueryBuilder = /** @class */ (function () {
53
+ function QueryBuilder() {
54
+ }
55
+ QueryBuilder.prototype.execute = function (params) {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ return __generator(this, function (_a) {
58
+ throw new Error("Execute method not implemented");
59
+ });
60
+ });
61
+ };
62
+ QueryBuilder.prototype.createTable = function (params) {
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ return __generator(this, function (_a) {
65
+ return [2 /*return*/, this.execute({
66
+ query: "CREATE TABLE " + ((params.ifNotExists) ? 'IF NOT EXISTS' : '') + " " + params.tableName + " (" + params.schema + ")"
67
+ })];
68
+ });
69
+ });
70
+ };
71
+ QueryBuilder.prototype.dropTable = function (params) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ return __generator(this, function (_a) {
74
+ return [2 /*return*/, this.execute({
75
+ query: "DROP TABLE " + ((params.ifExists) ? 'IF EXISTS' : '') + " " + params.tableName
76
+ })];
77
+ });
78
+ });
79
+ };
80
+ QueryBuilder.prototype.fetchOne = function (params) {
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ return __generator(this, function (_a) {
83
+ return [2 /*return*/, this.execute({
84
+ query: this._select(__assign(__assign({}, params), { limit: 1 })),
85
+ arguments: params.where ? params.where.params : undefined,
86
+ fetchType: enums_1.FetchTypes.ALL,
87
+ })];
88
+ });
89
+ });
90
+ };
91
+ QueryBuilder.prototype.fetchAll = function (params) {
92
+ return __awaiter(this, void 0, void 0, function () {
93
+ return __generator(this, function (_a) {
94
+ return [2 /*return*/, this.execute({
95
+ query: this._select(params),
96
+ arguments: params.where ? params.where.params : undefined,
97
+ fetchType: enums_1.FetchTypes.ALL,
98
+ })];
99
+ });
100
+ });
101
+ };
102
+ QueryBuilder.prototype.insert = function (params) {
103
+ return __awaiter(this, void 0, void 0, function () {
104
+ return __generator(this, function (_a) {
105
+ return [2 /*return*/, this.execute({
106
+ query: this._insert(params),
107
+ arguments: Object.values(params.data),
108
+ fetchType: enums_1.FetchTypes.ALL,
109
+ })];
110
+ });
111
+ });
112
+ };
113
+ QueryBuilder.prototype.update = function (params) {
114
+ return __awaiter(this, void 0, void 0, function () {
115
+ return __generator(this, function (_a) {
116
+ return [2 /*return*/, this.execute({
117
+ query: this._update(params),
118
+ arguments: params.where && params.where.params ? Object.values(params.data).concat(params.where.params) : Object.values(params.data),
119
+ fetchType: enums_1.FetchTypes.ALL,
120
+ })];
121
+ });
122
+ });
123
+ };
124
+ QueryBuilder.prototype.delete = function (params) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ return __generator(this, function (_a) {
127
+ return [2 /*return*/, this.execute({
128
+ query: this._delete(params),
129
+ arguments: params.where ? params.where.params : undefined,
130
+ fetchType: enums_1.FetchTypes.ALL,
131
+ })];
132
+ });
133
+ });
134
+ };
135
+ QueryBuilder.prototype._insert = function (params) {
136
+ var columns = Object.keys(params.data).join(", ");
137
+ var values = [];
138
+ Object.keys(params.data).forEach(function (key, index) {
139
+ values.push("?" + (index + 1));
140
+ });
141
+ return ("INSERT INTO " + params.tableName + " (" + columns + ") VALUES(" + values.join(", ") + ")" +
142
+ this._returning(params.returning));
143
+ };
144
+ QueryBuilder.prototype._update = function (params) {
145
+ var _a;
146
+ var whereParamsLength = params.where && params.where.params ? Object.keys(params.where.params).length : 0;
147
+ var set = [];
148
+ Object.entries(params.data).forEach(function (_a, index) {
149
+ var key = _a[0], value = _a[1];
150
+ set.push(key + " = ?" + (whereParamsLength + index + 1));
151
+ });
152
+ return ("UPDATE " + params.tableName + " SET (" + set.join(", ") + ")" +
153
+ this._where((_a = params.where) === null || _a === void 0 ? void 0 : _a.conditions) +
154
+ this._returning(params.returning));
155
+ };
156
+ QueryBuilder.prototype._delete = function (params) {
157
+ var _a;
158
+ return ("DELETE FROM " + params.tableName +
159
+ this._where((_a = params.where) === null || _a === void 0 ? void 0 : _a.conditions) +
160
+ this._returning(params.returning));
161
+ };
162
+ QueryBuilder.prototype._select = function (params) {
163
+ var _a;
164
+ return ("SELECT " + this._fields(params.fields) + " FROM " + params.tableName +
165
+ this._where((_a = params.where) === null || _a === void 0 ? void 0 : _a.conditions) +
166
+ this._groupBy(params.groupBy) +
167
+ this._having(params.having) +
168
+ this._orderBy(params.orderBy) +
169
+ this._limit(params.limit) +
170
+ this._offset(params.offset));
171
+ };
172
+ QueryBuilder.prototype._fields = function (value) {
173
+ if (typeof value === 'string')
174
+ return value;
175
+ return value.join(', ');
176
+ };
177
+ QueryBuilder.prototype._where = function (value) {
178
+ if (!value)
179
+ return '';
180
+ if (typeof value === 'string')
181
+ return " WHERE " + value;
182
+ return " WHERE " + value.join(' AND ');
183
+ };
184
+ QueryBuilder.prototype._groupBy = function (value) {
185
+ if (!value)
186
+ return '';
187
+ if (typeof value === 'string')
188
+ return " GROUP BY " + value;
189
+ return " GROUP BY " + value.join(', ');
190
+ };
191
+ QueryBuilder.prototype._having = function (value) {
192
+ if (!value)
193
+ return '';
194
+ return " HAVING " + value;
195
+ };
196
+ QueryBuilder.prototype._orderBy = function (value) {
197
+ if (!value)
198
+ return '';
199
+ if (typeof value === 'string')
200
+ return " ORDER BY " + value;
201
+ if (value.constructor.name.toLowerCase() === 'array') { // @ts-ignore
202
+ return " ORDER BY " + value.join(', ');
203
+ }
204
+ var order = [];
205
+ Object.entries(value).forEach(function (_a) {
206
+ var key = _a[0], item = _a[1];
207
+ order.push(key + " " + item);
208
+ });
209
+ return " ORDER BY " + order.join(', ');
210
+ };
211
+ QueryBuilder.prototype._limit = function (value) {
212
+ if (!value)
213
+ return '';
214
+ return " LIMIT " + value;
215
+ };
216
+ QueryBuilder.prototype._offset = function (value) {
217
+ if (!value)
218
+ return '';
219
+ return " OFFSET " + value;
220
+ };
221
+ QueryBuilder.prototype._returning = function (value) {
222
+ if (!value)
223
+ return '';
224
+ if (typeof value === 'string')
225
+ return " RETURNING " + value;
226
+ return " RETURNING " + value.join(', ');
227
+ };
228
+ return QueryBuilder;
229
+ }());
230
+ exports.QueryBuilder = QueryBuilder;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.D1QB = void 0;
55
+ var Builder_1 = require("./Builder");
56
+ var enums_1 = require("./enums");
57
+ var D1QB = /** @class */ (function (_super) {
58
+ __extends(D1QB, _super);
59
+ function D1QB(db) {
60
+ var _this = _super.call(this) || this;
61
+ _this.db = db;
62
+ return _this;
63
+ }
64
+ D1QB.prototype.execute = function (params) {
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ var stmt;
67
+ return __generator(this, function (_a) {
68
+ stmt = this.db.prepare(params.query);
69
+ if (params.arguments) {
70
+ stmt = stmt.bind.apply(stmt, params.arguments);
71
+ }
72
+ console.log(params);
73
+ if (params.fetchType === enums_1.FetchTypes.ONE) {
74
+ return [2 /*return*/, stmt.first()];
75
+ }
76
+ else if (params.fetchType === enums_1.FetchTypes.ALL) {
77
+ return [2 /*return*/, stmt.all()];
78
+ }
79
+ return [2 /*return*/, stmt.run()];
80
+ });
81
+ });
82
+ };
83
+ return D1QB;
84
+ }(Builder_1.QueryBuilder));
85
+ exports.D1QB = D1QB;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FetchTypes = exports.OrderTypes = void 0;
4
+ var OrderTypes;
5
+ (function (OrderTypes) {
6
+ OrderTypes["ASC"] = "ASC";
7
+ OrderTypes["DESC"] = "DESC";
8
+ })(OrderTypes = exports.OrderTypes || (exports.OrderTypes = {}));
9
+ var FetchTypes;
10
+ (function (FetchTypes) {
11
+ FetchTypes["ONE"] = "ONE";
12
+ FetchTypes["ALL"] = "ALL";
13
+ })(FetchTypes = exports.FetchTypes || (exports.FetchTypes = {}));
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.D1QB = exports.QueryBuilder = void 0;
4
+ var Builder_1 = require("./Builder");
5
+ Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return Builder_1.QueryBuilder; } });
6
+ var Databases_1 = require("./Databases");
7
+ Object.defineProperty(exports, "D1QB", { enumerable: true, get: function () { return Databases_1.D1QB; } });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,227 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { FetchTypes } from "./enums";
49
+ var QueryBuilder = /** @class */ (function () {
50
+ function QueryBuilder() {
51
+ }
52
+ QueryBuilder.prototype.execute = function (params) {
53
+ return __awaiter(this, void 0, void 0, function () {
54
+ return __generator(this, function (_a) {
55
+ throw new Error("Execute method not implemented");
56
+ });
57
+ });
58
+ };
59
+ QueryBuilder.prototype.createTable = function (params) {
60
+ return __awaiter(this, void 0, void 0, function () {
61
+ return __generator(this, function (_a) {
62
+ return [2 /*return*/, this.execute({
63
+ query: "CREATE TABLE " + ((params.ifNotExists) ? 'IF NOT EXISTS' : '') + " " + params.tableName + " (" + params.schema + ")"
64
+ })];
65
+ });
66
+ });
67
+ };
68
+ QueryBuilder.prototype.dropTable = function (params) {
69
+ return __awaiter(this, void 0, void 0, function () {
70
+ return __generator(this, function (_a) {
71
+ return [2 /*return*/, this.execute({
72
+ query: "DROP TABLE " + ((params.ifExists) ? 'IF EXISTS' : '') + " " + params.tableName
73
+ })];
74
+ });
75
+ });
76
+ };
77
+ QueryBuilder.prototype.fetchOne = function (params) {
78
+ return __awaiter(this, void 0, void 0, function () {
79
+ return __generator(this, function (_a) {
80
+ return [2 /*return*/, this.execute({
81
+ query: this._select(__assign(__assign({}, params), { limit: 1 })),
82
+ arguments: params.where ? params.where.params : undefined,
83
+ fetchType: FetchTypes.ALL,
84
+ })];
85
+ });
86
+ });
87
+ };
88
+ QueryBuilder.prototype.fetchAll = function (params) {
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ return __generator(this, function (_a) {
91
+ return [2 /*return*/, this.execute({
92
+ query: this._select(params),
93
+ arguments: params.where ? params.where.params : undefined,
94
+ fetchType: FetchTypes.ALL,
95
+ })];
96
+ });
97
+ });
98
+ };
99
+ QueryBuilder.prototype.insert = function (params) {
100
+ return __awaiter(this, void 0, void 0, function () {
101
+ return __generator(this, function (_a) {
102
+ return [2 /*return*/, this.execute({
103
+ query: this._insert(params),
104
+ arguments: Object.values(params.data),
105
+ fetchType: FetchTypes.ALL,
106
+ })];
107
+ });
108
+ });
109
+ };
110
+ QueryBuilder.prototype.update = function (params) {
111
+ return __awaiter(this, void 0, void 0, function () {
112
+ return __generator(this, function (_a) {
113
+ return [2 /*return*/, this.execute({
114
+ query: this._update(params),
115
+ arguments: params.where && params.where.params ? Object.values(params.data).concat(params.where.params) : Object.values(params.data),
116
+ fetchType: FetchTypes.ALL,
117
+ })];
118
+ });
119
+ });
120
+ };
121
+ QueryBuilder.prototype.delete = function (params) {
122
+ return __awaiter(this, void 0, void 0, function () {
123
+ return __generator(this, function (_a) {
124
+ return [2 /*return*/, this.execute({
125
+ query: this._delete(params),
126
+ arguments: params.where ? params.where.params : undefined,
127
+ fetchType: FetchTypes.ALL,
128
+ })];
129
+ });
130
+ });
131
+ };
132
+ QueryBuilder.prototype._insert = function (params) {
133
+ var columns = Object.keys(params.data).join(", ");
134
+ var values = [];
135
+ Object.keys(params.data).forEach(function (key, index) {
136
+ values.push("?" + (index + 1));
137
+ });
138
+ return ("INSERT INTO " + params.tableName + " (" + columns + ") VALUES(" + values.join(", ") + ")" +
139
+ this._returning(params.returning));
140
+ };
141
+ QueryBuilder.prototype._update = function (params) {
142
+ var _a;
143
+ var whereParamsLength = params.where && params.where.params ? Object.keys(params.where.params).length : 0;
144
+ var set = [];
145
+ Object.entries(params.data).forEach(function (_a, index) {
146
+ var key = _a[0], value = _a[1];
147
+ set.push(key + " = ?" + (whereParamsLength + index + 1));
148
+ });
149
+ return ("UPDATE " + params.tableName + " SET (" + set.join(", ") + ")" +
150
+ this._where((_a = params.where) === null || _a === void 0 ? void 0 : _a.conditions) +
151
+ this._returning(params.returning));
152
+ };
153
+ QueryBuilder.prototype._delete = function (params) {
154
+ var _a;
155
+ return ("DELETE FROM " + params.tableName +
156
+ this._where((_a = params.where) === null || _a === void 0 ? void 0 : _a.conditions) +
157
+ this._returning(params.returning));
158
+ };
159
+ QueryBuilder.prototype._select = function (params) {
160
+ var _a;
161
+ return ("SELECT " + this._fields(params.fields) + " FROM " + params.tableName +
162
+ this._where((_a = params.where) === null || _a === void 0 ? void 0 : _a.conditions) +
163
+ this._groupBy(params.groupBy) +
164
+ this._having(params.having) +
165
+ this._orderBy(params.orderBy) +
166
+ this._limit(params.limit) +
167
+ this._offset(params.offset));
168
+ };
169
+ QueryBuilder.prototype._fields = function (value) {
170
+ if (typeof value === 'string')
171
+ return value;
172
+ return value.join(', ');
173
+ };
174
+ QueryBuilder.prototype._where = function (value) {
175
+ if (!value)
176
+ return '';
177
+ if (typeof value === 'string')
178
+ return " WHERE " + value;
179
+ return " WHERE " + value.join(' AND ');
180
+ };
181
+ QueryBuilder.prototype._groupBy = function (value) {
182
+ if (!value)
183
+ return '';
184
+ if (typeof value === 'string')
185
+ return " GROUP BY " + value;
186
+ return " GROUP BY " + value.join(', ');
187
+ };
188
+ QueryBuilder.prototype._having = function (value) {
189
+ if (!value)
190
+ return '';
191
+ return " HAVING " + value;
192
+ };
193
+ QueryBuilder.prototype._orderBy = function (value) {
194
+ if (!value)
195
+ return '';
196
+ if (typeof value === 'string')
197
+ return " ORDER BY " + value;
198
+ if (value.constructor.name.toLowerCase() === 'array') { // @ts-ignore
199
+ return " ORDER BY " + value.join(', ');
200
+ }
201
+ var order = [];
202
+ Object.entries(value).forEach(function (_a) {
203
+ var key = _a[0], item = _a[1];
204
+ order.push(key + " " + item);
205
+ });
206
+ return " ORDER BY " + order.join(', ');
207
+ };
208
+ QueryBuilder.prototype._limit = function (value) {
209
+ if (!value)
210
+ return '';
211
+ return " LIMIT " + value;
212
+ };
213
+ QueryBuilder.prototype._offset = function (value) {
214
+ if (!value)
215
+ return '';
216
+ return " OFFSET " + value;
217
+ };
218
+ QueryBuilder.prototype._returning = function (value) {
219
+ if (!value)
220
+ return '';
221
+ if (typeof value === 'string')
222
+ return " RETURNING " + value;
223
+ return " RETURNING " + value.join(', ');
224
+ };
225
+ return QueryBuilder;
226
+ }());
227
+ export { QueryBuilder };
@@ -0,0 +1,82 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (_) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ import { QueryBuilder } from "./Builder";
53
+ import { FetchTypes } from "./enums";
54
+ var D1QB = /** @class */ (function (_super) {
55
+ __extends(D1QB, _super);
56
+ function D1QB(db) {
57
+ var _this = _super.call(this) || this;
58
+ _this.db = db;
59
+ return _this;
60
+ }
61
+ D1QB.prototype.execute = function (params) {
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ var stmt;
64
+ return __generator(this, function (_a) {
65
+ stmt = this.db.prepare(params.query);
66
+ if (params.arguments) {
67
+ stmt = stmt.bind.apply(stmt, params.arguments);
68
+ }
69
+ console.log(params);
70
+ if (params.fetchType === FetchTypes.ONE) {
71
+ return [2 /*return*/, stmt.first()];
72
+ }
73
+ else if (params.fetchType === FetchTypes.ALL) {
74
+ return [2 /*return*/, stmt.all()];
75
+ }
76
+ return [2 /*return*/, stmt.run()];
77
+ });
78
+ });
79
+ };
80
+ return D1QB;
81
+ }(QueryBuilder));
82
+ export { D1QB };
@@ -0,0 +1,10 @@
1
+ export var OrderTypes;
2
+ (function (OrderTypes) {
3
+ OrderTypes["ASC"] = "ASC";
4
+ OrderTypes["DESC"] = "DESC";
5
+ })(OrderTypes || (OrderTypes = {}));
6
+ export var FetchTypes;
7
+ (function (FetchTypes) {
8
+ FetchTypes["ONE"] = "ONE";
9
+ FetchTypes["ALL"] = "ALL";
10
+ })(FetchTypes || (FetchTypes = {}));
@@ -0,0 +1,3 @@
1
+ import { QueryBuilder } from './Builder';
2
+ import { D1QB } from './Databases';
3
+ export { QueryBuilder, D1QB };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import { Delete, Insert, SelectAll, SelectOne, Update } from "./interfaces";
2
+ import { FetchTypes, OrderTypes } from "./enums";
3
+ export declare class QueryBuilder {
4
+ execute(params: {
5
+ query: String;
6
+ arguments?: (string | number | boolean | null)[];
7
+ fetchType?: FetchTypes;
8
+ }): Promise<any>;
9
+ createTable(params: {
10
+ tableName: string;
11
+ schema: string;
12
+ ifNotExists?: boolean;
13
+ }): Promise<any>;
14
+ dropTable(params: {
15
+ tableName: string;
16
+ ifExists?: boolean;
17
+ }): Promise<any>;
18
+ fetchOne(params: SelectOne): Promise<any>;
19
+ fetchAll(params: SelectAll): Promise<any>;
20
+ insert(params: Insert): Promise<any>;
21
+ update(params: Update): Promise<any>;
22
+ delete(params: Delete): Promise<any>;
23
+ _insert(params: Insert): string;
24
+ _update(params: Update): string;
25
+ _delete(params: Delete): string;
26
+ _select(params: SelectAll): string;
27
+ _fields(value: string | Array<string>): string;
28
+ _where(value?: string | Array<string>): string;
29
+ _groupBy(value?: string | Array<string>): string;
30
+ _having(value?: string): string;
31
+ _orderBy(value?: string | Array<string> | Record<string, string | OrderTypes>): string;
32
+ _limit(value?: number): string;
33
+ _offset(value?: number): string;
34
+ _returning(value?: string | Array<string>): string;
35
+ }
@@ -0,0 +1,11 @@
1
+ import { QueryBuilder } from "./Builder";
2
+ import { FetchTypes } from "./enums";
3
+ export declare class D1QB extends QueryBuilder {
4
+ private db;
5
+ constructor(db: any);
6
+ execute(params: {
7
+ query: String;
8
+ arguments?: (string | number | boolean | null)[];
9
+ fetchType?: FetchTypes;
10
+ }): Promise<any>;
11
+ }
@@ -0,0 +1,8 @@
1
+ export declare enum OrderTypes {
2
+ ASC = "ASC",
3
+ DESC = "DESC"
4
+ }
5
+ export declare enum FetchTypes {
6
+ ONE = "ONE",
7
+ ALL = "ALL"
8
+ }
@@ -0,0 +1,3 @@
1
+ import { QueryBuilder } from './Builder';
2
+ import { D1QB } from './Databases';
3
+ export { QueryBuilder, D1QB };
@@ -0,0 +1,33 @@
1
+ import { OrderTypes } from "./enums";
2
+ export interface Where {
3
+ conditions: string | Array<string>;
4
+ params?: (string | boolean | number | null)[];
5
+ }
6
+ export interface SelectOne {
7
+ tableName: string;
8
+ fields: string | Array<string>;
9
+ where?: Where;
10
+ groupBy?: string | Array<string>;
11
+ having?: string;
12
+ orderBy?: string | Array<string> | Record<string, string | OrderTypes>;
13
+ offset?: number;
14
+ }
15
+ export interface SelectAll extends SelectOne {
16
+ limit?: number;
17
+ }
18
+ export interface Insert {
19
+ tableName: string;
20
+ data: Record<string, string | boolean | number | null>;
21
+ returning?: string | Array<string>;
22
+ }
23
+ export interface Update {
24
+ tableName: string;
25
+ data: Record<string, string | boolean | number | null>;
26
+ where: Where;
27
+ returning?: string | Array<string>;
28
+ }
29
+ export interface Delete {
30
+ tableName: string;
31
+ where: Where;
32
+ returning?: string | Array<string>;
33
+ }
@@ -0,0 +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(){return i(this,(function(t){return[2,this.execute({query:this._select(n(n({},e),{limit:1})),arguments:e.where?e.where.params:void 0,fetchType:u.FetchTypes.ALL})]}))}))},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?Object.values(e.data).concat(e.where.params):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._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 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 "+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._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._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)),console.log(e),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;Object.defineProperty(t,"__esModule",{value:!0}),t.FetchTypes=t.OrderTypes=void 0,(n=t.OrderTypes||(t.OrderTypes={})).ASC="ASC",n.DESC="DESC",(r=t.FetchTypes||(t.FetchTypes={})).ONE="ONE",r.ALL="ALL"}},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.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}})})(),n})()}));
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "workers-qb",
3
+ "version": "0.1.0",
4
+ "description": "Easily run SQL queries in Cloudflare Workers D1",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "umd:main": "dist/umd/index.js",
8
+ "types": "dist/types/index.d.js",
9
+ "scripts": {
10
+ "_postinstall": "husky install",
11
+ "prepublishOnly": "pinst --disable",
12
+ "postpublish": "pinst --enable",
13
+ "build": "npm run build:cjs && npm run build:esm && npm run build:umd && npm run build:types",
14
+ "build:cjs": "node tools/cleanup cjs && tsc -p config/tsconfig.cjs.json",
15
+ "build:esm": "node tools/cleanup esm && tsc -p config/tsconfig.esm.json",
16
+ "build:umd": "node tools/cleanup umd && webpack --config config/webpack.config.js",
17
+ "build:types": "node tools/cleanup types && tsc -p config/tsconfig.types.json",
18
+ "clean": "node tools/cleanup",
19
+ "package": "npm run build && npm pack",
20
+ "test": "jest --no-cache --runInBand",
21
+ "test:cov": "jest --coverage --no-cache --runInBand",
22
+ "addscope": "node tools/packagejson name @g4brym/workers-qb"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "keywords": [
31
+ "cloudflare",
32
+ "worker",
33
+ "workers",
34
+ "serverless",
35
+ "cloudflare d1",
36
+ "d1sql",
37
+ "sql builder",
38
+ "query builder",
39
+ "cloudflare sql",
40
+ "workers sql",
41
+ "cf",
42
+ "optional",
43
+ "middleware",
44
+ "query",
45
+ "parameters",
46
+ "typescript",
47
+ "npm",
48
+ "package",
49
+ "cjs",
50
+ "esm",
51
+ "umd",
52
+ "typed"
53
+ ],
54
+ "author": "Gabriel Massadas",
55
+ "license": "MIT",
56
+ "homepage": "https://github.com/G4brym/workers-qb",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git@github.com:G4brym/workers-qb.git"
60
+ },
61
+ "bugs": {
62
+ "url": "https://github.com/G4brym/workers-qb/issues"
63
+ },
64
+ "dependencies": {},
65
+ "devDependencies": {
66
+ "@commitlint/cli": "^13.1.0",
67
+ "@commitlint/config-conventional": "^13.1.0",
68
+ "@types/jest": "^27.0.1",
69
+ "@typescript-eslint/eslint-plugin": "^4.31.1",
70
+ "@typescript-eslint/parser": "^4.31.1",
71
+ "eslint": "^7.32.0",
72
+ "eslint-config-prettier": "^8.3.0",
73
+ "eslint-plugin-prettier": "^4.0.0",
74
+ "husky": "^7.0.2",
75
+ "jest": "^28.1.2",
76
+ "pinst": "^2.1.6",
77
+ "prettier": "^2.4.0",
78
+ "ts-jest": "^28.0.5",
79
+ "ts-loader": "^9.2.5",
80
+ "typescript": "^4.4.3",
81
+ "webpack": "^5.52.1",
82
+ "webpack-cli": "^4.8.0"
83
+ }
84
+ }