cl-orm 0.1.0 → 0.1.1

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.
Files changed (103) hide show
  1. package/lib/drivers/_utils.d.ts +4 -0
  2. package/lib/drivers/_utils.js +23 -0
  3. package/lib/drivers/d1.d.ts +2 -0
  4. package/lib/drivers/d1.js +48 -0
  5. package/lib/drivers/do.d.ts +2 -0
  6. package/lib/drivers/do.js +45 -0
  7. package/{src/index.ts → lib/index.d.ts} +1 -10
  8. package/lib/index.js +9 -0
  9. package/lib/queries/_utils.d.ts +1 -0
  10. package/lib/queries/_utils.js +13 -0
  11. package/lib/queries/delete.d.ts +5 -0
  12. package/lib/queries/delete.js +22 -0
  13. package/lib/queries/insert.d.ts +5 -0
  14. package/lib/queries/insert.js +19 -0
  15. package/lib/queries/select.d.ts +5 -0
  16. package/lib/queries/select.js +55 -0
  17. package/lib/queries/update.d.ts +5 -0
  18. package/lib/queries/update.js +25 -0
  19. package/lib/queries/where/operators.d.ts +23 -0
  20. package/lib/queries/where/operators.js +60 -0
  21. package/lib/queries/where/where.d.ts +5 -0
  22. package/lib/queries/where/where.js +34 -0
  23. package/lib/types.d.ts +64 -0
  24. package/lib/types.js +2 -0
  25. package/package.json +27 -2
  26. package/.editorconfig +0 -12
  27. package/.gitattributes +0 -1
  28. package/.prettierignore +0 -3
  29. package/.prettierrc +0 -34
  30. package/.vscode/settings.json +0 -14
  31. package/mcr.config.ts +0 -12
  32. package/src/drivers/_utils.ts +0 -31
  33. package/src/drivers/d1.ts +0 -70
  34. package/src/drivers/do.ts +0 -81
  35. package/src/queries/_utils.ts +0 -10
  36. package/src/queries/delete.ts +0 -26
  37. package/src/queries/insert.ts +0 -22
  38. package/src/queries/select.ts +0 -64
  39. package/src/queries/update.ts +0 -28
  40. package/src/queries/where/operators.ts +0 -96
  41. package/src/queries/where/where.ts +0 -50
  42. package/src/types.ts +0 -76
  43. package/test/__fixtures__/d1/worker.ts +0 -70
  44. package/test/__fixtures__/d1/wrangler.jsonc +0 -13
  45. package/test/__fixtures__/do/worker.ts +0 -106
  46. package/test/__fixtures__/do/wrangler.jsonc +0 -20
  47. package/test/e2e/d1.test.ts +0 -113
  48. package/test/e2e/do.test.ts +0 -116
  49. package/test/unit/buildDelete.test.ts +0 -36
  50. package/test/unit/buildInsert.test.ts +0 -36
  51. package/test/unit/buildSelect.test.ts +0 -137
  52. package/test/unit/buildUpdate.test.ts +0 -34
  53. package/test/unit/buildWhere.test.ts +0 -249
  54. package/test/unit/operators.test.ts +0 -98
  55. package/test/unit/prepare.test.ts +0 -22
  56. package/test/unit/quoteIdentifier.test.ts +0 -12
  57. package/test/unit/returnsRows.test.ts +0 -41
  58. package/test/unit/setMeta.test.ts +0 -31
  59. package/tsconfig.build.json +0 -4
  60. package/tsconfig.json +0 -34
  61. package/website/.prettierignore +0 -4
  62. package/website/.prettierrc +0 -34
  63. package/website/README.md +0 -3
  64. package/website/docs/documentation/connection.mdx +0 -123
  65. package/website/docs/documentation/queries/_category_.json +0 -7
  66. package/website/docs/documentation/queries/delete.mdx +0 -51
  67. package/website/docs/documentation/queries/insert.mdx +0 -63
  68. package/website/docs/documentation/queries/operators/_category_.json +0 -7
  69. package/website/docs/documentation/queries/operators/between.mdx +0 -17
  70. package/website/docs/documentation/queries/operators/eq.mdx +0 -22
  71. package/website/docs/documentation/queries/operators/gt.mdx +0 -22
  72. package/website/docs/documentation/queries/operators/gte.mdx +0 -22
  73. package/website/docs/documentation/queries/operators/in.mdx +0 -28
  74. package/website/docs/documentation/queries/operators/is-not-null.mdx +0 -22
  75. package/website/docs/documentation/queries/operators/is-null.mdx +0 -22
  76. package/website/docs/documentation/queries/operators/like.mdx +0 -27
  77. package/website/docs/documentation/queries/operators/lt.mdx +0 -22
  78. package/website/docs/documentation/queries/operators/lte.mdx +0 -22
  79. package/website/docs/documentation/queries/operators/ne.mdx +0 -22
  80. package/website/docs/documentation/queries/operators/not-between.mdx +0 -17
  81. package/website/docs/documentation/queries/operators/not-like.mdx +0 -27
  82. package/website/docs/documentation/queries/operators/notIn.mdx +0 -28
  83. package/website/docs/documentation/queries/select.mdx +0 -294
  84. package/website/docs/documentation/queries/update.mdx +0 -61
  85. package/website/docs/documentation/queries/where.mdx +0 -176
  86. package/website/docs/index.mdx +0 -228
  87. package/website/docusaurus.config.ts +0 -82
  88. package/website/package-lock.json +0 -21348
  89. package/website/package.json +0 -59
  90. package/website/plugins/locale.ts +0 -16
  91. package/website/sidebars.ts +0 -18
  92. package/website/src/components/FAQ.tsx +0 -35
  93. package/website/src/components/Loading.tsx +0 -4
  94. package/website/src/components/PageTitle.tsx +0 -29
  95. package/website/src/css/_faq.scss +0 -39
  96. package/website/src/css/_loading.scss +0 -43
  97. package/website/src/css/_mixins.scss +0 -19
  98. package/website/src/css/custom.scss +0 -149
  99. package/website/src/pages/index.tsx +0 -17
  100. package/website/static/.nojekyll +0 -0
  101. package/website/static/img/favicon.svg +0 -1
  102. package/website/test/unit/check-extensions.test.ts +0 -48
  103. package/website/tsconfig.json +0 -14
@@ -0,0 +1,4 @@
1
+ import type { Meta } from '../types.js';
2
+ export declare const returnsRows: (sql: string) => boolean;
3
+ export declare const prepare: (db: D1Database, sql: string, params: unknown[]) => D1PreparedStatement;
4
+ export declare const setMeta: (cursor: SqlStorageCursor<Record<string, SqlStorageValue>>) => Meta;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setMeta = exports.prepare = exports.returnsRows = void 0;
4
+ const returnsRows = (sql) => {
5
+ const trimmed = sql.trimStart().toUpperCase();
6
+ return (trimmed.indexOf('SELECT') === 0 ||
7
+ trimmed.indexOf('WITH') === 0 ||
8
+ trimmed.indexOf('PRAGMA') === 0 ||
9
+ trimmed.indexOf('RETURNING') !== -1);
10
+ };
11
+ exports.returnsRows = returnsRows;
12
+ const prepare = (db, sql, params) => params.length > 0 ? db.prepare(sql).bind(...params) : db.prepare(sql);
13
+ exports.prepare = prepare;
14
+ const setMeta = (cursor) => ({
15
+ duration: 0,
16
+ size_after: 0,
17
+ rows_read: cursor.rowsRead,
18
+ rows_written: cursor.rowsWritten,
19
+ last_row_id: 0,
20
+ changed_db: cursor.rowsWritten > 0,
21
+ changes: cursor.rowsWritten,
22
+ });
23
+ exports.setMeta = setMeta;
@@ -0,0 +1,2 @@
1
+ import type { Connection } from '../types.js';
2
+ export declare const useD1: (db: D1Database) => Connection;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useD1 = void 0;
4
+ const delete_js_1 = require("../queries/delete.js");
5
+ const insert_js_1 = require("../queries/insert.js");
6
+ const select_js_1 = require("../queries/select.js");
7
+ const update_js_1 = require("../queries/update.js");
8
+ const _utils_js_1 = require("./_utils.js");
9
+ const useD1 = (db) => {
10
+ const query = async (sql, values) => {
11
+ const statement = values
12
+ ? db.prepare(sql).bind(...values)
13
+ : db.prepare(sql);
14
+ if ((0, _utils_js_1.returnsRows)(sql)) {
15
+ const { results, meta } = await statement.all();
16
+ return { rows: results, meta: meta };
17
+ }
18
+ const { meta } = await statement.run();
19
+ return { rows: [], meta: meta };
20
+ };
21
+ const select = async (options) => {
22
+ const { sql, params } = (0, select_js_1.buildSelect)(options);
23
+ const statement = (0, _utils_js_1.prepare)(db, sql, params);
24
+ if (options.limit === 1)
25
+ return statement.first();
26
+ const { results } = await statement.all();
27
+ return results;
28
+ };
29
+ const insert = async (options) => {
30
+ const { sql, params } = (0, insert_js_1.buildInsert)(options);
31
+ const { meta } = await query(sql, params);
32
+ return meta;
33
+ };
34
+ const update = async (options) => {
35
+ const { sql, params } = (0, update_js_1.buildUpdate)(options);
36
+ const statement = (0, _utils_js_1.prepare)(db, sql, params);
37
+ const { meta } = await statement.run();
38
+ return meta;
39
+ };
40
+ const del = async (options) => {
41
+ const { sql, params } = (0, delete_js_1.buildDelete)(options);
42
+ const statement = (0, _utils_js_1.prepare)(db, sql, params);
43
+ const { meta } = await statement.run();
44
+ return meta;
45
+ };
46
+ return { query, select, insert, update, delete: del };
47
+ };
48
+ exports.useD1 = useD1;
@@ -0,0 +1,2 @@
1
+ import type { Connection } from '../types.js';
2
+ export declare const useDO: (sql: SqlStorage) => Connection;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDO = void 0;
4
+ const delete_js_1 = require("../queries/delete.js");
5
+ const insert_js_1 = require("../queries/insert.js");
6
+ const select_js_1 = require("../queries/select.js");
7
+ const update_js_1 = require("../queries/update.js");
8
+ const _utils_js_1 = require("./_utils.js");
9
+ const useDO = (sql) => {
10
+ const exec = (query, values) => (values ? sql.exec(query, ...values) : sql.exec(query));
11
+ const query = async (queryStr, values) => {
12
+ const cursor = exec(queryStr, values);
13
+ if ((0, _utils_js_1.returnsRows)(queryStr)) {
14
+ const rows = cursor.toArray();
15
+ return { rows, meta: (0, _utils_js_1.setMeta)(cursor) };
16
+ }
17
+ return { rows: [], meta: (0, _utils_js_1.setMeta)(cursor) };
18
+ };
19
+ const select = async (options) => {
20
+ const built = (0, select_js_1.buildSelect)(options);
21
+ const cursor = exec(built.sql, built.params.length > 0 ? built.params : undefined);
22
+ if (options.limit === 1) {
23
+ const rows = cursor.toArray();
24
+ return rows[0] ?? null;
25
+ }
26
+ return cursor.toArray();
27
+ };
28
+ const insert = async (options) => {
29
+ const built = (0, insert_js_1.buildInsert)(options);
30
+ const cursor = exec(built.sql, built.params);
31
+ return (0, _utils_js_1.setMeta)(cursor);
32
+ };
33
+ const update = async (options) => {
34
+ const built = (0, update_js_1.buildUpdate)(options);
35
+ const cursor = exec(built.sql, built.params.length > 0 ? built.params : undefined);
36
+ return (0, _utils_js_1.setMeta)(cursor);
37
+ };
38
+ const del = async (options) => {
39
+ const built = (0, delete_js_1.buildDelete)(options);
40
+ const cursor = exec(built.sql, built.params.length > 0 ? built.params : undefined);
41
+ return (0, _utils_js_1.setMeta)(cursor);
42
+ };
43
+ return { query, select, insert, update, delete: del };
44
+ };
45
+ exports.useDO = useDO;
@@ -1,13 +1,4 @@
1
1
  export { useD1 } from './drivers/d1.js';
2
2
  export { useDO } from './drivers/do.js';
3
3
  export { OP } from './queries/where/operators.js';
4
-
5
- export type {
6
- QueryResult,
7
- Connection,
8
- Meta,
9
- Condition,
10
- Param,
11
- WhereClause,
12
- WhereItem,
13
- } from './types.js';
4
+ export type { QueryResult, Connection, Meta, Condition, Param, WhereClause, WhereItem, } from './types.js';
package/lib/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OP = exports.useDO = exports.useD1 = void 0;
4
+ var d1_js_1 = require("./drivers/d1.js");
5
+ Object.defineProperty(exports, "useD1", { enumerable: true, get: function () { return d1_js_1.useD1; } });
6
+ var do_js_1 = require("./drivers/do.js");
7
+ Object.defineProperty(exports, "useDO", { enumerable: true, get: function () { return do_js_1.useDO; } });
8
+ var operators_js_1 = require("./queries/where/operators.js");
9
+ Object.defineProperty(exports, "OP", { enumerable: true, get: function () { return operators_js_1.OP; } });
@@ -0,0 +1 @@
1
+ export declare const quoteIdentifier: (name: string) => string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.quoteIdentifier = void 0;
4
+ const quoteIdentifier = (name) => {
5
+ if (name.includes('.')) {
6
+ return name
7
+ .split('.')
8
+ .map((part) => `\`${part}\``)
9
+ .join('.');
10
+ }
11
+ return `\`${name}\``;
12
+ };
13
+ exports.quoteIdentifier = quoteIdentifier;
@@ -0,0 +1,5 @@
1
+ import type { DeleteOptions } from '../types.js';
2
+ export declare const buildDelete: (options: DeleteOptions) => {
3
+ sql: string;
4
+ params: unknown[];
5
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildDelete = void 0;
4
+ const _utils_js_1 = require("./_utils.js");
5
+ const where_js_1 = require("./where/where.js");
6
+ const buildDelete = (options) => {
7
+ const parts = ['DELETE FROM', (0, _utils_js_1.quoteIdentifier)(options.table)];
8
+ const params = [];
9
+ if (options.where) {
10
+ const where = (0, where_js_1.buildWhere)(options.where);
11
+ parts.push('WHERE', where.sql);
12
+ params.push(...where.params);
13
+ }
14
+ if (options.limit !== undefined) {
15
+ parts.push('LIMIT ?');
16
+ params.push(options.limit);
17
+ }
18
+ if (options.params)
19
+ params.unshift(...options.params);
20
+ return { sql: parts.join(' '), params };
21
+ };
22
+ exports.buildDelete = buildDelete;
@@ -0,0 +1,5 @@
1
+ import type { InsertOptions } from '../types.js';
2
+ export declare const buildInsert: (options: InsertOptions) => {
3
+ sql: string;
4
+ params: unknown[];
5
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildInsert = void 0;
4
+ const _utils_js_1 = require("./_utils.js");
5
+ const buildInsert = (options) => {
6
+ const rows = Array.isArray(options.values)
7
+ ? options.values
8
+ : [options.values];
9
+ const columns = Object.keys(rows[0]);
10
+ const columnsSql = columns.map(_utils_js_1.quoteIdentifier).join(', ');
11
+ const placeholders = `(${columns.map(() => '?').join(', ')})`;
12
+ const valuesSql = rows.map(() => placeholders).join(', ');
13
+ const params = rows.flatMap((row) => columns.map((col) => row[col]));
14
+ return {
15
+ sql: `INSERT INTO ${(0, _utils_js_1.quoteIdentifier)(options.table)} (${columnsSql}) VALUES ${valuesSql}`,
16
+ params,
17
+ };
18
+ };
19
+ exports.buildInsert = buildInsert;
@@ -0,0 +1,5 @@
1
+ import type { SelectOptions } from '../types.js';
2
+ export declare const buildSelect: (options: SelectOptions) => {
3
+ sql: string;
4
+ params: unknown[];
5
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildSelect = void 0;
4
+ const _utils_js_1 = require("./_utils.js");
5
+ const where_js_1 = require("./where/where.js");
6
+ const buildColumns = (columns) => {
7
+ if (!columns)
8
+ return '*';
9
+ if (typeof columns === 'string')
10
+ return columns;
11
+ return columns.map(_utils_js_1.quoteIdentifier).join(', ');
12
+ };
13
+ const buildJoin = (join) => {
14
+ const type = join.outer
15
+ ? `${join.type.toUpperCase()} OUTER`
16
+ : join.type.toUpperCase();
17
+ return `${type} JOIN ${(0, _utils_js_1.quoteIdentifier)(join.table)} ON ${(0, _utils_js_1.quoteIdentifier)(join.on.a)} = ${(0, _utils_js_1.quoteIdentifier)(join.on.b)}`;
18
+ };
19
+ const buildSelect = (options) => {
20
+ const parts = ['SELECT'];
21
+ const params = [];
22
+ if (options.distinct)
23
+ parts.push('DISTINCT');
24
+ parts.push(buildColumns(options.columns));
25
+ parts.push('FROM', (0, _utils_js_1.quoteIdentifier)(options.table));
26
+ if (options.join) {
27
+ const joins = Array.isArray(options.join) ? options.join : [options.join];
28
+ for (const join of joins) {
29
+ parts.push(buildJoin(join));
30
+ }
31
+ }
32
+ if (options.where) {
33
+ const where = (0, where_js_1.buildWhere)(options.where);
34
+ parts.push('WHERE', where.sql);
35
+ params.push(...where.params);
36
+ }
37
+ if (options.groupBy)
38
+ parts.push('GROUP BY', (0, _utils_js_1.quoteIdentifier)(options.groupBy));
39
+ if (options.orderBy) {
40
+ const [column, direction = 'ASC'] = options.orderBy;
41
+ parts.push('ORDER BY', (0, _utils_js_1.quoteIdentifier)(column), direction);
42
+ }
43
+ if (options.limit !== undefined) {
44
+ parts.push('LIMIT ?');
45
+ params.push(options.limit);
46
+ }
47
+ if (options.offset !== undefined) {
48
+ parts.push('OFFSET ?');
49
+ params.push(options.offset);
50
+ }
51
+ if (options.params)
52
+ params.unshift(...options.params);
53
+ return { sql: parts.join(' '), params };
54
+ };
55
+ exports.buildSelect = buildSelect;
@@ -0,0 +1,5 @@
1
+ import type { UpdateOptions } from '../types.js';
2
+ export declare const buildUpdate: (options: UpdateOptions) => {
3
+ sql: string;
4
+ params: unknown[];
5
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildUpdate = void 0;
4
+ const _utils_js_1 = require("./_utils.js");
5
+ const where_js_1 = require("./where/where.js");
6
+ const buildUpdate = (options) => {
7
+ const columns = Object.keys(options.set);
8
+ const setSql = columns.map((col) => `${(0, _utils_js_1.quoteIdentifier)(col)} = ?`).join(', ');
9
+ const params = columns.map((col) => options.set[col]);
10
+ const parts = [
11
+ 'UPDATE',
12
+ (0, _utils_js_1.quoteIdentifier)(options.table),
13
+ 'SET',
14
+ setSql,
15
+ ];
16
+ if (options.where) {
17
+ const where = (0, where_js_1.buildWhere)(options.where);
18
+ parts.push('WHERE', where.sql);
19
+ params.push(...where.params);
20
+ }
21
+ if (options.params)
22
+ params.push(...options.params);
23
+ return { sql: parts.join(' '), params };
24
+ };
25
+ exports.buildUpdate = buildUpdate;
@@ -0,0 +1,23 @@
1
+ import type { Condition, Param } from '../../types.js';
2
+ export declare const OP: {
3
+ eq: (column: string, param: Param) => Condition;
4
+ ne: (column: string, param: Param) => Condition;
5
+ gt: (column: string, param: Param) => Condition;
6
+ lt: (column: string, param: Param) => Condition;
7
+ gte: (column: string, param: Param) => Condition;
8
+ lte: (column: string, param: Param) => Condition;
9
+ like: (column: string, param: Param) => Condition;
10
+ notLike: (column: string, param: Param) => Condition;
11
+ isNull: (column: string) => Condition;
12
+ isNotNull: (column: string) => Condition;
13
+ in: {
14
+ (column: string, params: Param[]): Condition;
15
+ (column: string, subquery: string, params: Param[]): Condition;
16
+ };
17
+ notIn: {
18
+ (column: string, params: Param[]): Condition;
19
+ (column: string, subquery: string, params: Param[]): Condition;
20
+ };
21
+ between: (column: string, params: [Param, Param]) => Condition;
22
+ notBetween: (column: string, params: [Param, Param]) => Condition;
23
+ };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OP = void 0;
4
+ const _utils_js_1 = require("../_utils.js");
5
+ const comparison = (column, operator, param) => ({
6
+ condition: `${(0, _utils_js_1.quoteIdentifier)(column)} ${operator} ?`,
7
+ params: [param],
8
+ });
9
+ exports.OP = {
10
+ eq: (column, param) => comparison(column, '=', param),
11
+ ne: (column, param) => comparison(column, '!=', param),
12
+ gt: (column, param) => comparison(column, '>', param),
13
+ lt: (column, param) => comparison(column, '<', param),
14
+ gte: (column, param) => comparison(column, '>=', param),
15
+ lte: (column, param) => comparison(column, '<=', param),
16
+ like: (column, param) => comparison(column, 'LIKE', param),
17
+ notLike: (column, param) => comparison(column, 'NOT LIKE', param),
18
+ isNull: (column) => ({
19
+ condition: `${(0, _utils_js_1.quoteIdentifier)(column)} IS NULL`,
20
+ params: [],
21
+ }),
22
+ isNotNull: (column) => ({
23
+ condition: `${(0, _utils_js_1.quoteIdentifier)(column)} IS NOT NULL`,
24
+ params: [],
25
+ }),
26
+ in: ((column, valuesOrSubquery, subqueryParams) => {
27
+ if (typeof valuesOrSubquery === 'string') {
28
+ return {
29
+ condition: `${(0, _utils_js_1.quoteIdentifier)(column)} IN (${valuesOrSubquery})`,
30
+ params: subqueryParams ?? [],
31
+ };
32
+ }
33
+ const placeholders = valuesOrSubquery.map(() => '?').join(', ');
34
+ return {
35
+ condition: `${(0, _utils_js_1.quoteIdentifier)(column)} IN (${placeholders})`,
36
+ params: valuesOrSubquery,
37
+ };
38
+ }),
39
+ notIn: ((column, valuesOrSubquery, subqueryParams) => {
40
+ if (typeof valuesOrSubquery === 'string') {
41
+ return {
42
+ condition: `${(0, _utils_js_1.quoteIdentifier)(column)} NOT IN (${valuesOrSubquery})`,
43
+ params: subqueryParams ?? [],
44
+ };
45
+ }
46
+ const placeholders = valuesOrSubquery.map(() => '?').join(', ');
47
+ return {
48
+ condition: `${(0, _utils_js_1.quoteIdentifier)(column)} NOT IN (${placeholders})`,
49
+ params: valuesOrSubquery,
50
+ };
51
+ }),
52
+ between: (column, params) => ({
53
+ condition: `${(0, _utils_js_1.quoteIdentifier)(column)} BETWEEN ? AND ?`,
54
+ params,
55
+ }),
56
+ notBetween: (column, params) => ({
57
+ condition: `${(0, _utils_js_1.quoteIdentifier)(column)} NOT BETWEEN ? AND ?`,
58
+ params,
59
+ }),
60
+ };
@@ -0,0 +1,5 @@
1
+ import type { Param, WhereClause } from '../../types.js';
2
+ export declare const buildWhere: (where: WhereClause) => {
3
+ sql: string;
4
+ params: Param[];
5
+ };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildWhere = void 0;
4
+ const isConnector = (value) => typeof value === 'string' && ['AND', 'OR', 'XOR', 'NOT'].includes(value);
5
+ const isCondition = (value) => typeof value === 'object' && !Array.isArray(value) && 'condition' in value;
6
+ const processItems = (items) => {
7
+ const parts = [];
8
+ const params = [];
9
+ for (const item of items) {
10
+ if (isConnector(item)) {
11
+ parts.push(item);
12
+ continue;
13
+ }
14
+ if (isCondition(item)) {
15
+ parts.push(item.condition);
16
+ params.push(...item.params);
17
+ continue;
18
+ }
19
+ if (Array.isArray(item)) {
20
+ const group = processItems(item);
21
+ parts.push(`(${group.sql})`);
22
+ params.push(...group.params);
23
+ }
24
+ }
25
+ return { sql: parts.join(' '), params };
26
+ };
27
+ const buildWhere = (where) => {
28
+ if (typeof where === 'string')
29
+ return { sql: where, params: [] };
30
+ if (isCondition(where))
31
+ return { sql: where.condition, params: [...where.params] };
32
+ return processItems(where);
33
+ };
34
+ exports.buildWhere = buildWhere;
package/lib/types.d.ts ADDED
@@ -0,0 +1,64 @@
1
+ export type Param = string | number | boolean | null;
2
+ export type Condition = {
3
+ condition: string;
4
+ params: Param[];
5
+ };
6
+ export type Connector = 'AND' | 'OR' | 'XOR' | 'NOT';
7
+ export type WhereItem = Condition | Connector | WhereItem[];
8
+ export type WhereClause = string | Condition | WhereItem[];
9
+ type Values = Record<string, unknown>;
10
+ export type InsertOptions = {
11
+ table: string;
12
+ values: Values | Values[];
13
+ };
14
+ export type JoinOptions = {
15
+ type: 'left' | 'right' | 'inner' | 'cross';
16
+ table: string;
17
+ on: {
18
+ a: string;
19
+ b: string;
20
+ };
21
+ outer?: boolean;
22
+ };
23
+ export type SelectOptions = {
24
+ distinct?: boolean;
25
+ columns?: string | string[];
26
+ table: string;
27
+ join?: JoinOptions | JoinOptions[];
28
+ where?: WhereClause;
29
+ limit?: number;
30
+ offset?: number;
31
+ groupBy?: string;
32
+ orderBy?: [string] | [string, 'ASC' | 'DESC'];
33
+ params?: unknown[];
34
+ };
35
+ export type UpdateOptions = {
36
+ table: string;
37
+ set: Record<string, unknown>;
38
+ where?: WhereClause;
39
+ params?: unknown[];
40
+ };
41
+ export type DeleteOptions = {
42
+ table: string;
43
+ where?: WhereClause;
44
+ limit?: number;
45
+ params?: unknown[];
46
+ };
47
+ export type Meta = D1Meta & Record<string, unknown>;
48
+ export type QueryResult<T> = {
49
+ rows: T[];
50
+ meta: Meta;
51
+ };
52
+ export type Connection = {
53
+ query: <T = Record<string, unknown>>(sql: string, values?: unknown[]) => Promise<QueryResult<T>>;
54
+ select: {
55
+ <T = Record<string, unknown>>(options: SelectOptions & {
56
+ limit: 1;
57
+ }): Promise<T | null>;
58
+ <T = Record<string, unknown>>(options: SelectOptions): Promise<T[]>;
59
+ };
60
+ insert: (options: InsertOptions) => Promise<Meta>;
61
+ update: (options: UpdateOptions) => Promise<Meta>;
62
+ delete: (options: DeleteOptions) => Promise<Meta>;
63
+ };
64
+ export {};
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "cl-orm",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A lightweight ORM for Cloudflare Workers (D1 and Durable Objects), designed to be intuitive, productive and focused on essential functionality",
5
+ "homepage": "https://wellwelwel.github.io/cl-orm/docs/",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/wellwelwel/cl-orm.git"
10
+ },
11
+ "author": "https://github.com/wellwelwel",
12
+ "bugs": {
13
+ "url": "https://github.com/wellwelwel/cl-orm/issues"
14
+ },
5
15
  "scripts": {
6
16
  "dev:d1": "wrangler dev --config test/__fixtures__/d1/wrangler.jsonc --port 8787 --inspector-port 9229",
7
17
  "dev:do": "wrangler dev --config test/__fixtures__/do/wrangler.jsonc --port 8788 --inspector-port 9230",
@@ -26,5 +36,20 @@
26
36
  "tsx": "^4.21.0",
27
37
  "typescript": "^5.9.3",
28
38
  "wrangler": "^4.61.1"
29
- }
39
+ },
40
+ "files": [
41
+ "lib"
42
+ ],
43
+ "keywords": [
44
+ "cloudflare",
45
+ "workers",
46
+ "orm",
47
+ "durable objects",
48
+ "durable-objects",
49
+ "d1",
50
+ "database",
51
+ "sqlite",
52
+ "prisma",
53
+ "drizzle"
54
+ ]
30
55
  }
package/.editorconfig DELETED
@@ -1,12 +0,0 @@
1
- # http://editorconfig.org
2
- root = true
3
-
4
- [*]
5
- indent_style = tab
6
- end_of_line = lf
7
- charset = utf-8
8
- trim_trailing_whitespace = true
9
- insert_final_newline = true
10
-
11
- [*.yml]
12
- indent_style = space
package/.gitattributes DELETED
@@ -1 +0,0 @@
1
- website/** linguist-documentation
package/.prettierignore DELETED
@@ -1,3 +0,0 @@
1
- /lib
2
- /CHANGELOG.md
3
- /website
package/.prettierrc DELETED
@@ -1,34 +0,0 @@
1
- {
2
- "printWidth": 80,
3
- "tabWidth": 2,
4
- "useTabs": false,
5
- "semi": true,
6
- "singleQuote": true,
7
- "quoteProps": "as-needed",
8
- "jsxSingleQuote": true,
9
- "trailingComma": "es5",
10
- "bracketSpacing": true,
11
- "bracketSameLine": false,
12
- "arrowParens": "always",
13
- "proseWrap": "preserve",
14
- "endOfLine": "auto",
15
- "embeddedLanguageFormatting": "auto",
16
- "singleAttributePerLine": false,
17
- "plugins": ["@ianvs/prettier-plugin-sort-imports"],
18
- "importOrder": [
19
- "<TYPES>^(node:)",
20
- "<TYPES>",
21
- "<TYPES>^[.]",
22
- "<BUILTIN_MODULES>",
23
- "<THIRD_PARTY_MODULES>",
24
- "^[.]"
25
- ],
26
- "overrides": [
27
- {
28
- "files": "*.jsonc",
29
- "options": {
30
- "trailingComma": "none"
31
- }
32
- }
33
- ]
34
- }
@@ -1,14 +0,0 @@
1
- {
2
- "editor.trimAutoWhitespace": true,
3
- "editor.indentSize": 2,
4
- "editor.tabSize": 2,
5
- "editor.formatOnSave": true,
6
- "files.trimTrailingWhitespace": true,
7
- "editor.defaultFormatter": "esbenp.prettier-vscode",
8
- "editor.codeActionsOnSave": {
9
- "source.fixAll": "explicit"
10
- },
11
- "[markdown]": {
12
- "files.trimTrailingWhitespace": false
13
- }
14
- }
package/mcr.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import type { CoverageReportOptions } from 'monocart-coverage-reports';
2
-
3
- const coverageOptions: CoverageReportOptions = {
4
- reports: ['v8', 'console-details', 'codecov'],
5
- entryFilter: {
6
- '**/node_modules/**': false,
7
- '**/test/**': false,
8
- '**/src/**': true,
9
- },
10
- };
11
-
12
- export default coverageOptions;