@ignisia/sql 0.2.1 → 0.3.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/dist/cjs/column/constants.d.cts +150 -0
- package/dist/cjs/column/constants.js +158 -0
- package/dist/cjs/column/index.d.cts +43 -0
- package/dist/cjs/column/index.js +127 -0
- package/dist/cjs/column/types.d.cts +43 -0
- package/dist/cjs/column/types.js +4 -0
- package/dist/cjs/column/utils.d.cts +133 -0
- package/dist/cjs/column/utils.js +34 -0
- package/dist/cjs/database/alter.d.cts +53 -0
- package/dist/cjs/database/alter.js +93 -0
- package/dist/cjs/database/column.d.cts +25 -0
- package/dist/cjs/database/column.js +39 -0
- package/dist/cjs/database/contract.d.cts +9 -0
- package/dist/cjs/database/contract.js +2 -0
- package/dist/cjs/database/index.d.cts +9 -0
- package/dist/cjs/database/index.js +107 -0
- package/dist/cjs/database/table.d.cts +22 -0
- package/dist/cjs/database/table.js +49 -0
- package/dist/cjs/database/types.d.cts +8 -0
- package/dist/cjs/database/types.js +2 -0
- package/dist/cjs/database/wrapper.d.cts +32 -0
- package/dist/cjs/database/wrapper.js +87 -0
- package/dist/cjs/index-2jl8MRfX.d.cts +105 -0
- package/dist/cjs/index-CnQVnCEI.d.cts +392 -0
- package/dist/cjs/index.d.cts +11 -0
- package/dist/cjs/index.js +30 -0
- package/dist/cjs/migration/index.d.cts +31 -0
- package/dist/{migration → cjs/migration}/index.js +3 -1
- package/dist/cjs/migration/runner.js +58 -0
- package/dist/cjs/migration/type.d.cts +20 -0
- package/dist/cjs/migration/type.js +2 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/query/builder.d.cts +15 -0
- package/dist/cjs/query/builder.js +71 -0
- package/dist/cjs/query/condition.d.cts +8 -0
- package/dist/cjs/query/condition.js +109 -0
- package/dist/cjs/query/constants.js +64 -0
- package/dist/cjs/query/contract.d.cts +8 -0
- package/dist/cjs/query/contract.js +2 -0
- package/dist/cjs/query/helper.d.cts +8 -0
- package/dist/cjs/query/helper.js +36 -0
- package/dist/cjs/query/index.d.cts +8 -0
- package/dist/cjs/query/index.js +206 -0
- package/dist/cjs/query/join.d.cts +17 -0
- package/dist/cjs/query/join.js +18 -0
- package/dist/cjs/query/sql.d.cts +18 -0
- package/dist/cjs/query/sql.js +132 -0
- package/dist/cjs/query/types.d.cts +8 -0
- package/dist/cjs/query/types.js +2 -0
- package/dist/cjs/query/utilities.d.cts +37 -0
- package/dist/cjs/query/utilities.js +194 -0
- package/dist/cjs/table/constants.d.cts +8 -0
- package/dist/cjs/table/constants.js +9 -0
- package/dist/cjs/table/index.d.cts +8 -0
- package/dist/cjs/table/index.js +74 -0
- package/dist/cjs/table/types.d.cts +8 -0
- package/dist/cjs/table/types.js +2 -0
- package/dist/cjs/table/utilities.d.cts +8 -0
- package/dist/cjs/table/utilities.js +55 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utilities.js +21 -0
- package/dist/{column → esm/column}/constants.d.ts +58 -5
- package/dist/esm/column/constants.js +154 -0
- package/dist/{column → esm/column}/index.d.ts +1 -0
- package/dist/{column → esm/column}/index.js +36 -15
- package/dist/esm/column/types.js +1 -0
- package/dist/esm/column/utils.d.ts +133 -0
- package/dist/esm/column/utils.js +32 -0
- package/dist/{database → esm/database}/alter.d.ts +3 -2
- package/dist/{database → esm/database}/alter.js +17 -16
- package/dist/{database → esm/database}/column.d.ts +3 -2
- package/dist/{database → esm/database}/column.js +11 -8
- package/dist/{database → esm/database}/contract.d.ts +3 -2
- package/dist/{database → esm/database}/index.d.ts +3 -2
- package/dist/{database → esm/database}/index.js +24 -10
- package/dist/{database → esm/database}/table.d.ts +3 -2
- package/dist/{database → esm/database}/table.js +14 -5
- package/dist/esm/database/types.d.ts +8 -0
- package/dist/esm/database/wrapper.d.ts +32 -0
- package/dist/esm/database/wrapper.js +83 -0
- package/dist/{index-DFrpzXEn.d.ts → esm/index-BXOAxB_h.d.ts} +4 -2
- package/dist/{index-FMT0YEO7.d.ts → esm/index-BdpoD4zk.d.ts} +80 -46
- package/dist/{index.d.ts → esm/index.d.ts} +3 -2
- package/dist/esm/index.js +5 -0
- package/dist/{migration → esm/migration}/index.d.ts +3 -2
- package/dist/esm/migration/index.js +49 -0
- package/dist/esm/migration/runner.d.ts +3 -0
- package/dist/{migration → esm/migration}/runner.js +7 -6
- package/dist/{migration → esm/migration}/type.d.ts +3 -2
- package/dist/{query → esm/query}/builder.d.ts +2 -1
- package/dist/{query → esm/query}/builder.js +3 -2
- package/dist/esm/query/condition.d.ts +8 -0
- package/dist/{query → esm/query}/condition.js +9 -5
- package/dist/esm/query/constants.d.ts +63 -0
- package/dist/{query → esm/query}/constants.js +9 -8
- package/dist/{query → esm/query}/contract.d.ts +3 -2
- package/dist/{query → esm/query}/helper.d.ts +2 -1
- package/dist/{query → esm/query}/helper.js +3 -2
- package/dist/{query → esm/query}/index.d.ts +2 -1
- package/dist/{query → esm/query}/index.js +26 -16
- package/dist/{query → esm/query}/join.d.ts +2 -1
- package/dist/{query → esm/query}/join.js +1 -0
- package/dist/{query → esm/query}/sql.d.ts +5 -4
- package/dist/{query → esm/query}/sql.js +40 -11
- package/dist/esm/query/types.d.ts +8 -0
- package/dist/{query → esm/query}/utilities.d.ts +4 -1
- package/dist/{query → esm/query}/utilities.js +20 -9
- package/dist/{table → esm/table}/constants.d.ts +1 -0
- package/dist/{table → esm/table}/constants.js +3 -1
- package/dist/{table → esm/table}/index.d.ts +2 -1
- package/dist/{table → esm/table}/index.js +35 -14
- package/dist/{table → esm/table}/types.d.ts +2 -1
- package/dist/{table → esm/table}/utilities.d.ts +2 -1
- package/dist/{table → esm/table}/utilities.js +5 -4
- package/dist/esm/types.d.ts +3 -0
- package/dist/esm/utilities.d.ts +4 -0
- package/dist/{utilities.js → esm/utilities.js} +1 -0
- package/package.json +42 -19
- package/dist/column/constants.js +0 -98
- package/dist/column/types.js +0 -1
- package/dist/database/types.d.ts +0 -7
- package/dist/database/wrapper.d.ts +0 -36
- package/dist/database/wrapper.js +0 -92
- package/dist/index.js +0 -5
- package/dist/query/condition.d.ts +0 -7
- package/dist/query/types.d.ts +0 -7
- /package/dist/{migration/runner.d.ts → cjs/migration/runner.d.cts} +0 -0
- /package/dist/{query/constants.d.ts → cjs/query/constants.d.cts} +0 -0
- /package/dist/{types.d.ts → cjs/types.d.cts} +0 -0
- /package/dist/{utilities.d.ts → cjs/utilities.d.cts} +0 -0
- /package/dist/{column → esm/column}/types.d.ts +0 -0
- /package/dist/{database → esm/database}/contract.js +0 -0
- /package/dist/{database → esm/database}/types.js +0 -0
- /package/dist/{migration → esm/migration}/type.js +0 -0
- /package/dist/{query → esm/query}/contract.js +0 -0
- /package/dist/{query → esm/query}/types.js +0 -0
- /package/dist/{table → esm/table}/types.js +0 -0
- /package/dist/{types.js → esm/types.js} +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/migration/index.ts
|
|
2
|
+
var Migration = class _Migration {
|
|
3
|
+
db;
|
|
4
|
+
_up;
|
|
5
|
+
_down;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.db = options.db;
|
|
8
|
+
this._up = options.up;
|
|
9
|
+
this._down = options.down;
|
|
10
|
+
}
|
|
11
|
+
get up() {
|
|
12
|
+
return this._up;
|
|
13
|
+
}
|
|
14
|
+
get down() {
|
|
15
|
+
return this._down;
|
|
16
|
+
}
|
|
17
|
+
static setUp(migrator, fn) {
|
|
18
|
+
migrator._up = () => fn(migrator.db);
|
|
19
|
+
return migrator;
|
|
20
|
+
}
|
|
21
|
+
static setDown(migrator, fn) {
|
|
22
|
+
migrator._down = () => fn(migrator.db);
|
|
23
|
+
return migrator;
|
|
24
|
+
}
|
|
25
|
+
static define(db, options) {
|
|
26
|
+
const migration = new _Migration({
|
|
27
|
+
db,
|
|
28
|
+
up: options?.up ? () => options.up(db) : null,
|
|
29
|
+
down: options?.down ? () => options.down(db) : null
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
migration,
|
|
33
|
+
setUp(fn) {
|
|
34
|
+
return _Migration.setUp(
|
|
35
|
+
migration,
|
|
36
|
+
fn
|
|
37
|
+
);
|
|
38
|
+
},
|
|
39
|
+
setDown(fn) {
|
|
40
|
+
return _Migration.setDown(
|
|
41
|
+
migration,
|
|
42
|
+
fn
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { Migration };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { Column } from '../column';
|
|
2
|
-
import { Table } from '../table';
|
|
1
|
+
import { Column } from '../column/index.js';
|
|
2
|
+
import { Table } from '../table/index.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/migration/runner.ts
|
|
5
|
+
var nameColumn = Column.define({
|
|
5
6
|
type: "TEXT",
|
|
6
7
|
length: 255
|
|
7
8
|
}).primaryKey().notNull();
|
|
8
|
-
|
|
9
|
+
var runAtColumn = Column.define({
|
|
9
10
|
type: "DATETIME"
|
|
10
11
|
}).notNull();
|
|
11
|
-
|
|
12
|
+
var migrationTable = null;
|
|
12
13
|
async function runMigration(filePath, direction) {
|
|
13
14
|
const migrationFile = await import(filePath);
|
|
14
15
|
const fileName = filePath.split("/").pop();
|
|
@@ -28,7 +29,7 @@ async function runMigration(filePath, direction) {
|
|
|
28
29
|
dialect: migration.db.dialect
|
|
29
30
|
});
|
|
30
31
|
migrationTable.client = migration.db.client;
|
|
31
|
-
await migrationTable.create();
|
|
32
|
+
await migrationTable.create({});
|
|
32
33
|
}
|
|
33
34
|
const fn = migration[direction];
|
|
34
35
|
if (!fn)
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Column } from '../column/index.js';
|
|
2
|
-
import { D as Database } from '../index-
|
|
3
|
-
import { T as Table } from '../index-
|
|
2
|
+
import { D as Database } from '../index-BXOAxB_h.js';
|
|
3
|
+
import { T as Table } from '../index-BdpoD4zk.js';
|
|
4
4
|
import { Dialect } from '../table/constants.js';
|
|
5
5
|
import '../column/constants.js';
|
|
6
6
|
import '../column/types.js';
|
|
7
|
+
import 'bun';
|
|
7
8
|
import '../query/constants.js';
|
|
8
9
|
import '../types.js';
|
|
9
10
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, e as StrictColumnSelector, f as QueryBuilder } from '../index-BdpoD4zk.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
3
|
import '../column/constants.js';
|
|
4
4
|
import '../types.js';
|
|
5
5
|
import './constants.js';
|
|
6
|
+
import 'bun';
|
|
6
7
|
import '../table/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
8
9
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { quoteIdentifier } from '../utilities';
|
|
2
|
-
import { getTableSelectName } from './utilities';
|
|
1
|
+
import { quoteIdentifier } from '../utilities.js';
|
|
2
|
+
import { getTableSelectName } from './utilities.js';
|
|
3
3
|
|
|
4
|
+
// src/query/builder.ts
|
|
4
5
|
function buildSelectQuery(q) {
|
|
5
6
|
const from = getTableSelectName(q);
|
|
6
7
|
const columns = [];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { N as addCondition, I as addRawCondition, V as having, U as or, L as rawHaving, K as rawOr, J as rawWhere, O as where } from '../index-BdpoD4zk.js';
|
|
2
|
+
import '../column/index.js';
|
|
3
|
+
import './constants.js';
|
|
4
|
+
import '../column/constants.js';
|
|
5
|
+
import '../types.js';
|
|
6
|
+
import 'bun';
|
|
7
|
+
import '../table/constants.js';
|
|
8
|
+
import '../column/types.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { LogicalOperator, ConditionClause, AcceptedOperator } from './constants';
|
|
2
|
-
import { rawCol } from './helper';
|
|
3
|
-
import { getCondition } from './utilities';
|
|
1
|
+
import { LogicalOperator, ConditionClause, AcceptedOperator } from './constants.js';
|
|
2
|
+
import { rawCol } from './helper.js';
|
|
3
|
+
import { getCondition } from './utilities.js';
|
|
4
4
|
|
|
5
|
+
// src/query/condition.ts
|
|
5
6
|
function addRawCondition(query, clause, column, logical, params) {
|
|
6
7
|
const validClause = clause.toLowerCase();
|
|
7
8
|
if (!query.definition[validClause]) query.definition[validClause] = [];
|
|
@@ -47,6 +48,9 @@ function rawHaving(column, params) {
|
|
|
47
48
|
);
|
|
48
49
|
}
|
|
49
50
|
function addCondition(query, clause, column, operator, value, logical) {
|
|
51
|
+
if (!query.table.dialect) {
|
|
52
|
+
throw new Error("No DB Dialect defined");
|
|
53
|
+
}
|
|
50
54
|
const validClause = clause.toLowerCase();
|
|
51
55
|
const condition = getCondition(query.table.dialect, column, operator, value);
|
|
52
56
|
if (!query.definition[validClause]) query.definition[validClause] = [];
|
|
@@ -69,7 +73,7 @@ function where(column, operator, value) {
|
|
|
69
73
|
ConditionClause.WHERE,
|
|
70
74
|
column,
|
|
71
75
|
operator,
|
|
72
|
-
value,
|
|
76
|
+
value || null,
|
|
73
77
|
LogicalOperator.AND
|
|
74
78
|
);
|
|
75
79
|
}
|
|
@@ -79,7 +83,7 @@ function or(column, operator, value) {
|
|
|
79
83
|
ConditionClause.WHERE,
|
|
80
84
|
column,
|
|
81
85
|
operator,
|
|
82
|
-
value,
|
|
86
|
+
value || null,
|
|
83
87
|
LogicalOperator.OR
|
|
84
88
|
);
|
|
85
89
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
declare const LogicalOperator: {
|
|
2
|
+
readonly AND: "AND";
|
|
3
|
+
readonly OR: "OR";
|
|
4
|
+
};
|
|
5
|
+
type LogicalOperator = (typeof LogicalOperator)[keyof typeof LogicalOperator];
|
|
6
|
+
declare const ConditionClause: {
|
|
7
|
+
readonly WHERE: "WHERE";
|
|
8
|
+
readonly HAVING: "HAVING";
|
|
9
|
+
};
|
|
10
|
+
type ConditionClause = (typeof ConditionClause)[keyof typeof ConditionClause];
|
|
11
|
+
declare const AcceptedOperator: {
|
|
12
|
+
readonly EQ: "eq";
|
|
13
|
+
readonly NE: "ne";
|
|
14
|
+
readonly GT: "gt";
|
|
15
|
+
readonly LT: "lt";
|
|
16
|
+
readonly GTE: "gte";
|
|
17
|
+
readonly LTE: "lte";
|
|
18
|
+
readonly IN: "in";
|
|
19
|
+
readonly NOT_IN: "notIn";
|
|
20
|
+
readonly LIKE: "like";
|
|
21
|
+
readonly NOT_LIKE: "notLike";
|
|
22
|
+
readonly ILIKE: "ilike";
|
|
23
|
+
readonly NOT_ILIKE: "notILike";
|
|
24
|
+
readonly IS_NULL: "isNull";
|
|
25
|
+
readonly IS_NOT_NULL: "isNotNull";
|
|
26
|
+
readonly BETWEEN: "between";
|
|
27
|
+
readonly NOT_BETWEEN: "notBetween";
|
|
28
|
+
};
|
|
29
|
+
type AcceptedOperator = (typeof AcceptedOperator)[keyof typeof AcceptedOperator];
|
|
30
|
+
declare const QueryType: {
|
|
31
|
+
readonly SELECT: "SELECT";
|
|
32
|
+
readonly INSERT: "INSERT";
|
|
33
|
+
readonly UPDATE: "UPDATE";
|
|
34
|
+
readonly DELETE: "DELETE";
|
|
35
|
+
};
|
|
36
|
+
type QueryType = (typeof QueryType)[keyof typeof QueryType];
|
|
37
|
+
declare const OrderBy: {
|
|
38
|
+
readonly ASC: "ASC";
|
|
39
|
+
readonly DESC: "DESC";
|
|
40
|
+
};
|
|
41
|
+
type OrderBy = (typeof OrderBy)[keyof typeof OrderBy];
|
|
42
|
+
declare const AggregationFunction: {
|
|
43
|
+
readonly COUNT: "COUNT";
|
|
44
|
+
readonly SUM: "SUM";
|
|
45
|
+
readonly MIN: "MIN";
|
|
46
|
+
readonly MAX: "MAX";
|
|
47
|
+
readonly AVG: "AVG";
|
|
48
|
+
};
|
|
49
|
+
type AggregationFunction = (typeof AggregationFunction)[keyof typeof AggregationFunction];
|
|
50
|
+
declare const AcceptedJoin: {
|
|
51
|
+
readonly INNER: "INNER";
|
|
52
|
+
readonly LEFT: "LEFT";
|
|
53
|
+
readonly RIGHT: "RIGHT";
|
|
54
|
+
readonly NATURAL: "NATURAL";
|
|
55
|
+
};
|
|
56
|
+
type AcceptedJoin = (typeof AcceptedJoin)[keyof typeof AcceptedJoin];
|
|
57
|
+
declare const QueryHooksType: {
|
|
58
|
+
readonly AFTER: "after";
|
|
59
|
+
readonly BEFORE: "before";
|
|
60
|
+
};
|
|
61
|
+
type QueryHooksType = (typeof QueryHooksType)[keyof typeof QueryHooksType];
|
|
62
|
+
|
|
63
|
+
export { AcceptedJoin, AcceptedOperator, AggregationFunction, ConditionClause, LogicalOperator, OrderBy, QueryHooksType, QueryType };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
// src/query/constants.ts
|
|
2
|
+
var LogicalOperator = {
|
|
2
3
|
AND: "AND",
|
|
3
4
|
OR: "OR"
|
|
4
5
|
};
|
|
5
|
-
|
|
6
|
+
var ConditionClause = {
|
|
6
7
|
WHERE: "WHERE",
|
|
7
8
|
HAVING: "HAVING"
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
+
var AcceptedOperator = {
|
|
10
11
|
EQ: "eq",
|
|
11
12
|
NE: "ne",
|
|
12
13
|
GT: "gt",
|
|
@@ -24,30 +25,30 @@ const AcceptedOperator = {
|
|
|
24
25
|
BETWEEN: "between",
|
|
25
26
|
NOT_BETWEEN: "notBetween"
|
|
26
27
|
};
|
|
27
|
-
|
|
28
|
+
var QueryType = {
|
|
28
29
|
SELECT: "SELECT",
|
|
29
30
|
INSERT: "INSERT",
|
|
30
31
|
UPDATE: "UPDATE",
|
|
31
32
|
DELETE: "DELETE"
|
|
32
33
|
};
|
|
33
|
-
|
|
34
|
+
var OrderBy = {
|
|
34
35
|
ASC: "ASC",
|
|
35
36
|
DESC: "DESC"
|
|
36
37
|
};
|
|
37
|
-
|
|
38
|
+
var AggregationFunction = {
|
|
38
39
|
COUNT: "COUNT",
|
|
39
40
|
SUM: "SUM",
|
|
40
41
|
MIN: "MIN",
|
|
41
42
|
MAX: "MAX",
|
|
42
43
|
AVG: "AVG"
|
|
43
44
|
};
|
|
44
|
-
|
|
45
|
+
var AcceptedJoin = {
|
|
45
46
|
INNER: "INNER",
|
|
46
47
|
LEFT: "LEFT",
|
|
47
48
|
RIGHT: "RIGHT",
|
|
48
49
|
NATURAL: "NATURAL"
|
|
49
50
|
};
|
|
50
|
-
|
|
51
|
+
var QueryHooksType = {
|
|
51
52
|
AFTER: "after",
|
|
52
53
|
BEFORE: "before"
|
|
53
54
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import 'bun';
|
|
2
|
+
export { Y as QueryConditionContract, X as QueryTransformerContract } from '../index-BdpoD4zk.js';
|
|
2
3
|
import '../column/index.js';
|
|
4
|
+
import '../table/constants.js';
|
|
3
5
|
import './constants.js';
|
|
4
6
|
import '../column/constants.js';
|
|
5
7
|
import '../types.js';
|
|
6
|
-
import '../table/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { H as aggregateCol, z as alias, B as clone, G as col, F as rawCol } from '../index-BdpoD4zk.js';
|
|
2
2
|
import '../column/index.js';
|
|
3
3
|
import './constants.js';
|
|
4
4
|
import '../column/constants.js';
|
|
5
5
|
import '../types.js';
|
|
6
|
+
import 'bun';
|
|
6
7
|
import '../table/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { QueryBuilder } from '.';
|
|
2
|
-
import { deepClone } from '../utilities';
|
|
1
|
+
import { QueryBuilder } from './index.js';
|
|
2
|
+
import { deepClone } from '../utilities.js';
|
|
3
3
|
|
|
4
|
+
// src/query/helper.ts
|
|
4
5
|
function alias(alias2) {
|
|
5
6
|
this.definition.baseAlias = alias2;
|
|
6
7
|
return this;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import '../column/index.js';
|
|
2
|
-
export {
|
|
2
|
+
export { f as QueryBuilder } from '../index-BdpoD4zk.js';
|
|
3
3
|
import './constants.js';
|
|
4
4
|
import '../table/constants.js';
|
|
5
5
|
import '../column/constants.js';
|
|
6
6
|
import '../column/types.js';
|
|
7
7
|
import '../types.js';
|
|
8
|
+
import 'bun';
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { quoteIdentifier } from '../utilities';
|
|
2
|
-
import { rawWhere, rawHaving, rawOr, where, having, or } from './condition';
|
|
3
|
-
import { AcceptedJoin, QueryType } from './constants';
|
|
4
|
-
import { alias, clone, aggregateCol, col } from './helper';
|
|
5
|
-
import { addJoin } from './join';
|
|
6
|
-
import { toQuery, toString, exec } from './sql';
|
|
7
|
-
import { getTimestamp, getParanoid } from './utilities';
|
|
1
|
+
import { quoteIdentifier } from '../utilities.js';
|
|
2
|
+
import { rawWhere, rawHaving, rawOr, where, having, or } from './condition.js';
|
|
3
|
+
import { AcceptedJoin, QueryType } from './constants.js';
|
|
4
|
+
import { alias, clone, aggregateCol, col } from './helper.js';
|
|
5
|
+
import { addJoin } from './join.js';
|
|
6
|
+
import { toQuery, toString, exec } from './sql.js';
|
|
7
|
+
import { getTimestamp, getParanoid } from './utilities.js';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// src/query/index.ts
|
|
10
|
+
var QueryBuilder = class {
|
|
10
11
|
hooks;
|
|
11
12
|
table;
|
|
12
13
|
definition;
|
|
@@ -152,22 +153,31 @@ class QueryBuilder {
|
|
|
152
153
|
insert(...values) {
|
|
153
154
|
this.definition.queryType = QueryType.INSERT;
|
|
154
155
|
if (!this.definition.insertValues) this.definition.insertValues = [];
|
|
155
|
-
const {
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
const {
|
|
157
|
+
isWithTimestamp,
|
|
158
|
+
isHasCreatedAt,
|
|
159
|
+
isHasUpdatedAt,
|
|
160
|
+
createdAt,
|
|
161
|
+
updatedAt,
|
|
162
|
+
timestamp
|
|
163
|
+
} = getTimestamp(this.table);
|
|
158
164
|
if (isWithTimestamp) {
|
|
159
165
|
values = values.map((row) => ({
|
|
160
166
|
...row,
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
...isHasCreatedAt && {
|
|
168
|
+
[createdAt]: row[createdAt] ?? timestamp
|
|
169
|
+
},
|
|
170
|
+
...isHasUpdatedAt && {
|
|
171
|
+
[updatedAt]: row[updatedAt] ?? timestamp
|
|
172
|
+
}
|
|
163
173
|
}));
|
|
164
174
|
}
|
|
165
175
|
this.definition.insertValues = values;
|
|
166
176
|
return this;
|
|
167
177
|
}
|
|
168
178
|
update(values) {
|
|
169
|
-
const { isWithTimestamp, updatedAt, timestamp } = getTimestamp(this.table);
|
|
170
|
-
if (isWithTimestamp) {
|
|
179
|
+
const { isWithTimestamp, isHasUpdatedAt, updatedAt, timestamp } = getTimestamp(this.table);
|
|
180
|
+
if (isWithTimestamp && isHasUpdatedAt) {
|
|
171
181
|
values = {
|
|
172
182
|
...values,
|
|
173
183
|
[updatedAt]: values[updatedAt] ?? timestamp
|
|
@@ -190,6 +200,6 @@ class QueryBuilder {
|
|
|
190
200
|
infer() {
|
|
191
201
|
return null;
|
|
192
202
|
}
|
|
193
|
-
}
|
|
203
|
+
};
|
|
194
204
|
|
|
195
205
|
export { QueryBuilder };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, e as StrictColumnSelector, f as QueryBuilder } from '../index-BdpoD4zk.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
3
|
import { AcceptedJoin } from './constants.js';
|
|
4
4
|
import '../column/constants.js';
|
|
5
5
|
import '../types.js';
|
|
6
|
+
import 'bun';
|
|
6
7
|
import '../table/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
8
9
|
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TransactionSQL } from 'bun';
|
|
2
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, e as StrictColumnSelector, f as QueryBuilder } from '../index-BdpoD4zk.js';
|
|
2
3
|
import { Column } from '../column/index.js';
|
|
4
|
+
import { Dialect } from '../table/constants.js';
|
|
3
5
|
import '../column/constants.js';
|
|
4
6
|
import '../types.js';
|
|
5
7
|
import './constants.js';
|
|
6
|
-
import '../table/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
8
9
|
|
|
9
10
|
declare function buildQuery(query: string): string;
|
|
10
|
-
declare function toQuery<Alias extends string, TableRef extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>, Definition extends Partial<QueryDefinition<Alias, TableRef, JoinedTables>>, AllowedColumn extends ColumnSelector<Alias, TableRef, JoinedTables>, StrictAllowedColumn extends StrictColumnSelector<Alias, TableRef, JoinedTables>, Query extends QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>>(this: Query): {
|
|
11
|
+
declare function toQuery<Alias extends string, TableRef extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>, Definition extends Partial<QueryDefinition<Alias, TableRef, JoinedTables>>, AllowedColumn extends ColumnSelector<Alias, TableRef, JoinedTables>, StrictAllowedColumn extends StrictColumnSelector<Alias, TableRef, JoinedTables>, Query extends QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>>(this: Query, dialect?: Dialect | null): {
|
|
11
12
|
query: string;
|
|
12
13
|
params: unknown[] | null | undefined;
|
|
13
14
|
};
|
|
14
15
|
declare function toString<Alias extends string, TableRef extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>, Definition extends Partial<QueryDefinition<Alias, TableRef, JoinedTables>>, AllowedColumn extends ColumnSelector<Alias, TableRef, JoinedTables>, StrictAllowedColumn extends StrictColumnSelector<Alias, TableRef, JoinedTables>, Query extends QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>>(this: Query): string;
|
|
15
|
-
declare function exec<Alias extends string, TableRef extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>, Definition extends Partial<QueryDefinition<Alias, TableRef, JoinedTables>>, AllowedColumn extends ColumnSelector<Alias, TableRef, JoinedTables>, StrictAllowedColumn extends StrictColumnSelector<Alias, TableRef, JoinedTables>, Query extends QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, Output extends Query['_output'] = Query['_output']>(this: Query): Promise<Output>;
|
|
16
|
+
declare function exec<Alias extends string, TableRef extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>, Definition extends Partial<QueryDefinition<Alias, TableRef, JoinedTables>>, AllowedColumn extends ColumnSelector<Alias, TableRef, JoinedTables>, StrictAllowedColumn extends StrictColumnSelector<Alias, TableRef, JoinedTables>, Query extends QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, Output extends Query['_output'] = Query['_output']>(this: Query, tx?: TransactionSQL | null): Promise<Output>;
|
|
16
17
|
|
|
17
18
|
export { buildQuery, exec, toQuery, toString };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Dialect } from '../table/constants.js';
|
|
2
|
+
import { buildDeleteQuery, buildUpdateQuery, buildInsertQuery, buildSelectQuery } from './builder.js';
|
|
3
|
+
import { QueryType, QueryHooksType } from './constants.js';
|
|
4
|
+
import { getWhereConditions, getGroupByConditions, parseAliasedRow } from './utilities.js';
|
|
4
5
|
|
|
6
|
+
// src/query/sql.ts
|
|
5
7
|
function buildQuery(query) {
|
|
6
8
|
let index = 0;
|
|
7
9
|
return query.replace(/\?/g, () => {
|
|
@@ -9,7 +11,7 @@ function buildQuery(query) {
|
|
|
9
11
|
return `$${index}`;
|
|
10
12
|
});
|
|
11
13
|
}
|
|
12
|
-
function toQuery() {
|
|
14
|
+
function toQuery(dialect) {
|
|
13
15
|
let sql = "";
|
|
14
16
|
switch (this.definition.queryType) {
|
|
15
17
|
case QueryType.SELECT:
|
|
@@ -55,7 +57,9 @@ function toQuery() {
|
|
|
55
57
|
this.definition.params.push(this.definition.offset);
|
|
56
58
|
}
|
|
57
59
|
if (this.definition.queryType === QueryType.UPDATE || this.definition.queryType === QueryType.DELETE) {
|
|
58
|
-
|
|
60
|
+
if (dialect !== Dialect.MYSQL) {
|
|
61
|
+
sql += ` RETURNING *`;
|
|
62
|
+
}
|
|
59
63
|
}
|
|
60
64
|
sql = buildQuery(sql);
|
|
61
65
|
return { query: sql + ";", params: this.definition.params };
|
|
@@ -63,26 +67,51 @@ function toQuery() {
|
|
|
63
67
|
function toString() {
|
|
64
68
|
return this.toQuery().query;
|
|
65
69
|
}
|
|
66
|
-
async function exec() {
|
|
67
|
-
|
|
68
|
-
const
|
|
70
|
+
async function exec(tx) {
|
|
71
|
+
const client = this.table.client;
|
|
72
|
+
const dialect = this.table.dialect;
|
|
73
|
+
const queryType = this.definition.queryType;
|
|
74
|
+
const isUpdate = queryType === QueryType.UPDATE;
|
|
75
|
+
const isDelete = queryType === QueryType.DELETE;
|
|
76
|
+
const isReturning = isUpdate || isDelete;
|
|
77
|
+
const isMySQL = dialect === Dialect.MYSQL;
|
|
78
|
+
if (!client) {
|
|
79
|
+
throw new Error("Database client not defined");
|
|
80
|
+
}
|
|
81
|
+
if (!queryType) {
|
|
82
|
+
throw new Error("No query type defined");
|
|
83
|
+
}
|
|
84
|
+
const { query, params } = this.toQuery(dialect);
|
|
69
85
|
if (this.hooks?.before?.size) {
|
|
70
86
|
for (const hook of this.hooks.before.values()) {
|
|
71
87
|
hook({
|
|
72
88
|
query,
|
|
73
89
|
params,
|
|
74
|
-
type:
|
|
90
|
+
type: queryType,
|
|
75
91
|
hook: QueryHooksType.BEFORE
|
|
76
92
|
});
|
|
77
93
|
}
|
|
78
94
|
}
|
|
79
|
-
|
|
95
|
+
let result = await client.exec({
|
|
96
|
+
sql: query,
|
|
97
|
+
params,
|
|
98
|
+
tx
|
|
99
|
+
});
|
|
100
|
+
if (isMySQL && isReturning) {
|
|
101
|
+
const query2 = this.clone();
|
|
102
|
+
query2.definition.queryType = QueryType.SELECT;
|
|
103
|
+
result = await client.exec({
|
|
104
|
+
sql: query2.toQuery().query,
|
|
105
|
+
params,
|
|
106
|
+
tx
|
|
107
|
+
});
|
|
108
|
+
}
|
|
80
109
|
if (this.hooks?.after?.size) {
|
|
81
110
|
for (const hook of this.hooks.after.values()) {
|
|
82
111
|
hook({
|
|
83
112
|
query,
|
|
84
113
|
params,
|
|
85
|
-
type:
|
|
114
|
+
type: queryType,
|
|
86
115
|
hook: QueryHooksType.AFTER
|
|
87
116
|
});
|
|
88
117
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import '../column/index.js';
|
|
2
|
+
import '../column/constants.js';
|
|
3
|
+
export { l as AcceptedInsertValues, k as AcceptedOrderBy, m as AcceptedUpdateValues, n as AggregateColumn, A as AliasedColumn, C as ColumnSelector, h as QuerHooks, Q as QueryDefinition, p as QueryOutput, j as QueryRunHooks, q as QueryRunHooksOptions, R as RawColumn, o as SelectQueryOutput, g as SelectableColumn, e as StrictColumnSelector, W as WhereValue } from '../index-BdpoD4zk.js';
|
|
4
|
+
import '../types.js';
|
|
5
|
+
import './constants.js';
|
|
6
|
+
import '../table/constants.js';
|
|
7
|
+
import '../column/types.js';
|
|
8
|
+
import 'bun';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { T as Table, W as WhereValue, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, W as WhereValue, Q as QueryDefinition, C as ColumnSelector, e as StrictColumnSelector, f as QueryBuilder, A as AliasedColumn, g as SelectableColumn } from '../index-BdpoD4zk.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
3
|
import { Dialect } from '../table/constants.js';
|
|
4
4
|
import { AcceptedOperator } from './constants.js';
|
|
5
5
|
import '../column/constants.js';
|
|
6
6
|
import '../types.js';
|
|
7
|
+
import 'bun';
|
|
7
8
|
import '../column/types.js';
|
|
8
9
|
|
|
9
10
|
declare function getTableColumnNames<ColName extends string, BaseAlias extends string, BaseTable extends Table<string, Record<string, Column>>, JoinedTables extends Record<string, Table<string, Record<string, Column>>>>(column: ColName, baseAlias: BaseAlias, baseTable: BaseTable, joinedTables: JoinedTables): {
|
|
@@ -16,6 +17,8 @@ declare function getTimestamp<TableRef extends Table<string, Record<string, Colu
|
|
|
16
17
|
timestamp: Date;
|
|
17
18
|
createdAt: string;
|
|
18
19
|
updatedAt: string;
|
|
20
|
+
isHasUpdatedAt: boolean;
|
|
21
|
+
isHasCreatedAt: boolean;
|
|
19
22
|
};
|
|
20
23
|
declare function getParanoid<TableRef extends Table<string, Record<string, Column>>>(table: TableRef): {
|
|
21
24
|
isWithParanoid: boolean;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import '.';
|
|
2
|
-
import { Dialect } from '../table/constants';
|
|
3
|
-
import { quoteIdentifier } from '../utilities';
|
|
4
|
-
import { AcceptedOperator, QueryType } from './constants';
|
|
1
|
+
import './index.js';
|
|
2
|
+
import { Dialect } from '../table/constants.js';
|
|
3
|
+
import { quoteIdentifier } from '../utilities.js';
|
|
4
|
+
import { AcceptedOperator, QueryType } from './constants.js';
|
|
5
5
|
|
|
6
|
+
// src/query/utilities.ts
|
|
6
7
|
function getTableColumnNames(column, baseAlias, baseTable, joinedTables) {
|
|
7
8
|
const [tableAlias] = column.split(".");
|
|
8
9
|
const isOnBase = tableAlias === baseAlias;
|
|
@@ -60,22 +61,32 @@ function getCondition(dialect, column, operator, value) {
|
|
|
60
61
|
function getTimestamp(table) {
|
|
61
62
|
const isWithTimestamp = !!table.timestamp;
|
|
62
63
|
const timestamp = /* @__PURE__ */ new Date();
|
|
64
|
+
let isHasCreatedAt = true;
|
|
65
|
+
let isHasUpdatedAt = true;
|
|
63
66
|
let createdAt = "createdAt";
|
|
64
67
|
let updatedAt = "updatedAt";
|
|
65
68
|
if (isWithTimestamp) {
|
|
66
69
|
const isCustomTimestamp = typeof table.timestamp === "object";
|
|
67
|
-
if (isCustomTimestamp
|
|
68
|
-
|
|
70
|
+
if (isCustomTimestamp) {
|
|
71
|
+
if (typeof table.timestamp.createdAt === "string") {
|
|
72
|
+
createdAt = table.timestamp.createdAt;
|
|
73
|
+
}
|
|
74
|
+
isHasCreatedAt = table.timestamp.createdAt === false;
|
|
69
75
|
}
|
|
70
|
-
if (isCustomTimestamp
|
|
71
|
-
|
|
76
|
+
if (isCustomTimestamp) {
|
|
77
|
+
if (typeof table.timestamp.updatedAt === "string") {
|
|
78
|
+
updatedAt = table.timestamp.updatedAt;
|
|
79
|
+
}
|
|
80
|
+
isHasUpdatedAt = table.timestamp.updatedAt === false;
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
return {
|
|
75
84
|
isWithTimestamp,
|
|
76
85
|
timestamp,
|
|
77
86
|
createdAt,
|
|
78
|
-
updatedAt
|
|
87
|
+
updatedAt,
|
|
88
|
+
isHasUpdatedAt,
|
|
89
|
+
isHasCreatedAt
|
|
79
90
|
};
|
|
80
91
|
}
|
|
81
92
|
function getParanoid(table) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { T as Table } from '../index-
|
|
1
|
+
export { T as Table } from '../index-BdpoD4zk.js';
|
|
2
2
|
import '../column/index.js';
|
|
3
3
|
import './constants.js';
|
|
4
4
|
import '../column/constants.js';
|
|
5
5
|
import '../types.js';
|
|
6
6
|
import '../query/constants.js';
|
|
7
|
+
import 'bun';
|
|
7
8
|
import '../column/types.js';
|