@ignisia/sql 0.4.0 → 0.4.2
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/database/alter.d.cts +2 -2
- package/dist/cjs/database/column.d.cts +2 -2
- package/dist/cjs/database/contract.d.cts +2 -2
- package/dist/cjs/database/index.d.cts +2 -2
- package/dist/cjs/database/table.d.cts +2 -2
- package/dist/cjs/database/types.d.cts +1 -1
- package/dist/cjs/database/wrapper.d.cts +1 -1
- package/dist/cjs/{index-CHxuUiO4.d.cts → index-CY-nPZED.d.cts} +102 -74
- package/dist/cjs/{index-CZhrzE5r.d.cts → index-DQRamRz3.d.cts} +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/migration/index.d.cts +2 -2
- package/dist/cjs/migration/type.d.cts +2 -2
- package/dist/cjs/query/ast.d.cts +8 -0
- package/dist/cjs/query/ast.js +2 -0
- package/dist/cjs/query/builder.d.cts +3 -3
- package/dist/cjs/query/builder.js +8 -10
- package/dist/cjs/query/compiler.d.cts +13 -0
- package/dist/cjs/query/compiler.js +114 -0
- package/dist/cjs/query/condition/common.d.cts +16 -11
- package/dist/cjs/query/condition/common.js +0 -12
- package/dist/cjs/query/condition/core.d.cts +1 -1
- package/dist/cjs/query/condition/core.js +67 -33
- package/dist/cjs/query/condition/index.d.cts +2 -2
- package/dist/cjs/query/condition/index.js +0 -7
- package/dist/cjs/query/condition/not.d.cts +15 -3
- package/dist/cjs/query/constants.d.cts +8 -9
- package/dist/cjs/query/constants.js +9 -10
- package/dist/cjs/query/contract.d.cts +1 -1
- package/dist/cjs/query/explain.d.cts +1 -1
- package/dist/cjs/query/explain.js +1 -1
- package/dist/cjs/query/helper.d.cts +1 -1
- package/dist/cjs/query/helper.js +0 -4
- package/dist/cjs/query/index.d.cts +3 -3
- package/dist/cjs/query/index.js +1 -11
- package/dist/cjs/query/join.d.cts +5 -5
- package/dist/cjs/query/join.js +19 -11
- package/dist/cjs/query/sql.d.cts +2 -2
- package/dist/cjs/query/sql.js +39 -22
- package/dist/cjs/query/types.d.cts +1 -1
- package/dist/cjs/query/utilities.d.cts +4 -6
- package/dist/cjs/query/utilities.js +0 -116
- package/dist/cjs/table/index.d.cts +1 -1
- package/dist/cjs/table/types.d.cts +1 -1
- package/dist/cjs/table/utilities.d.cts +1 -1
- package/dist/esm/database/alter.d.ts +2 -2
- package/dist/esm/database/column.d.ts +2 -2
- package/dist/esm/database/contract.d.ts +2 -2
- package/dist/esm/database/index.d.ts +2 -2
- package/dist/esm/database/table.d.ts +2 -2
- package/dist/esm/database/types.d.ts +1 -1
- package/dist/esm/database/wrapper.d.ts +1 -1
- package/dist/esm/{index-DgOs61lH.d.ts → index-BWg1JZRt.d.ts} +1 -1
- package/dist/esm/{index-CjurLJdK.d.ts → index-CsVPGz2o.d.ts} +102 -74
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/migration/index.d.ts +2 -2
- package/dist/esm/migration/type.d.ts +2 -2
- package/dist/esm/query/ast.d.ts +8 -0
- package/dist/esm/query/ast.js +1 -0
- package/dist/esm/query/builder.d.ts +3 -3
- package/dist/esm/query/builder.js +8 -10
- package/dist/esm/query/compiler.d.ts +13 -0
- package/dist/esm/query/compiler.js +112 -0
- package/dist/esm/query/condition/common.d.ts +16 -11
- package/dist/esm/query/condition/common.js +1 -12
- package/dist/esm/query/condition/core.d.ts +1 -1
- package/dist/esm/query/condition/core.js +68 -34
- package/dist/esm/query/condition/index.d.ts +2 -2
- package/dist/esm/query/condition/index.js +0 -1
- package/dist/esm/query/condition/not.d.ts +15 -3
- package/dist/esm/query/constants.d.ts +8 -9
- package/dist/esm/query/constants.js +9 -11
- package/dist/esm/query/contract.d.ts +1 -1
- package/dist/esm/query/explain.d.ts +1 -1
- package/dist/esm/query/explain.js +1 -1
- package/dist/esm/query/helper.d.ts +1 -1
- package/dist/esm/query/helper.js +1 -4
- package/dist/esm/query/index.d.ts +3 -3
- package/dist/esm/query/index.js +2 -12
- package/dist/esm/query/join.d.ts +5 -5
- package/dist/esm/query/join.js +19 -11
- package/dist/esm/query/sql.d.ts +2 -2
- package/dist/esm/query/sql.js +40 -23
- package/dist/esm/query/types.d.ts +1 -1
- package/dist/esm/query/utilities.d.ts +4 -6
- package/dist/esm/query/utilities.js +2 -116
- package/dist/esm/table/index.d.ts +1 -1
- package/dist/esm/table/types.d.ts +1 -1
- package/dist/esm/table/utilities.d.ts +1 -1
- package/package.json +4 -4
- package/dist/cjs/query/condition/raw.d.cts +0 -8
- package/dist/cjs/query/condition/raw.js +0 -54
- package/dist/esm/query/condition/raw.d.ts +0 -8
- package/dist/esm/query/condition/raw.js +0 -50
package/dist/cjs/query/join.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _ = require('.');
|
|
4
|
+
var constants = require('./constants');
|
|
4
5
|
|
|
5
6
|
function addNoOnJoin(query, joinType, joinTable, alias) {
|
|
6
7
|
if (!query.definition.joins) query.definition.joins = [];
|
|
7
|
-
query.definition.joins.push(
|
|
8
|
+
query.definition.joins.push({
|
|
9
|
+
type: constants.AstType.JOIN,
|
|
10
|
+
alias,
|
|
11
|
+
join: joinType,
|
|
12
|
+
table: joinTable
|
|
13
|
+
});
|
|
8
14
|
if (!query.definition.joinedTables) {
|
|
9
15
|
query.definition.joinedTables = {};
|
|
10
16
|
}
|
|
@@ -16,21 +22,23 @@ function prepareJoin(query, joinType, joinTable, alias) {
|
|
|
16
22
|
on(callback) {
|
|
17
23
|
const sub = callback(new _.QueryBuilder(query.table));
|
|
18
24
|
const subDef = sub.definition;
|
|
19
|
-
if (!subDef.where
|
|
25
|
+
if (!subDef.where) {
|
|
20
26
|
return query;
|
|
21
27
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
if (!query.definition.joins) {
|
|
29
|
+
query.definition.joins = [];
|
|
30
|
+
}
|
|
31
|
+
const on = subDef.where;
|
|
32
|
+
query.definition.joins.push({
|
|
33
|
+
type: constants.AstType.JOIN,
|
|
34
|
+
alias,
|
|
35
|
+
join: joinType,
|
|
36
|
+
table: joinTable,
|
|
37
|
+
on
|
|
38
|
+
});
|
|
27
39
|
if (subDef.joins?.length) {
|
|
28
40
|
query.definition.joins.push(...subDef.joins);
|
|
29
41
|
}
|
|
30
|
-
if (subDef.params?.length) {
|
|
31
|
-
if (!query.definition.params) query.definition.params = [];
|
|
32
|
-
query.definition.params.push(...subDef.params);
|
|
33
|
-
}
|
|
34
42
|
if (!query.definition.joinedTables) {
|
|
35
43
|
query.definition.joinedTables = {};
|
|
36
44
|
}
|
package/dist/cjs/query/sql.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TransactionSQL } from 'bun';
|
|
2
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
2
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, h as StrictColumnSelector, i as QueryBuilder, E as ExplainOptions } from '../index-CY-nPZED.cjs';
|
|
3
3
|
import { Column } from '../column/index.cjs';
|
|
4
4
|
import { Dialect } from '../table/constants.cjs';
|
|
5
5
|
import '../types.cjs';
|
|
@@ -10,7 +10,7 @@ import '../column/types.cjs';
|
|
|
10
10
|
declare function buildQuery(query: string): string;
|
|
11
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): {
|
|
12
12
|
query: string;
|
|
13
|
-
params: unknown[]
|
|
13
|
+
params: unknown[];
|
|
14
14
|
};
|
|
15
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;
|
|
16
16
|
declare function toDebugString<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;
|
package/dist/cjs/query/sql.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var constants$1 = require('../table/constants');
|
|
4
4
|
var builder = require('./builder');
|
|
5
|
+
var compiler = require('./compiler');
|
|
5
6
|
var constants = require('./constants');
|
|
6
7
|
var explain$1 = require('./explain');
|
|
7
8
|
var utilities = require('./utilities');
|
|
@@ -13,17 +14,18 @@ function buildQuery(query) {
|
|
|
13
14
|
return `$${index}`;
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
|
-
function toQuery(dialect) {
|
|
17
|
+
function toQuery(dialect = this.table.dialect) {
|
|
18
|
+
const params = [];
|
|
17
19
|
const parts = [];
|
|
18
20
|
switch (this.definition.queryType) {
|
|
19
21
|
case constants.QueryType.SELECT:
|
|
20
22
|
parts.push(builder.buildSelectQuery(this));
|
|
21
23
|
break;
|
|
22
24
|
case constants.QueryType.INSERT:
|
|
23
|
-
parts.push(builder.buildInsertQuery(this));
|
|
25
|
+
parts.push(builder.buildInsertQuery(this, params));
|
|
24
26
|
break;
|
|
25
27
|
case constants.QueryType.UPDATE:
|
|
26
|
-
parts.push(builder.buildUpdateQuery(this));
|
|
28
|
+
parts.push(builder.buildUpdateQuery(this, params));
|
|
27
29
|
break;
|
|
28
30
|
case constants.QueryType.DELETE:
|
|
29
31
|
parts.push(builder.buildDeleteQuery(this));
|
|
@@ -32,33 +34,39 @@ function toQuery(dialect) {
|
|
|
32
34
|
throw new Error("No query type defined");
|
|
33
35
|
}
|
|
34
36
|
if (this.definition?.joins?.length) {
|
|
35
|
-
|
|
37
|
+
const joinParts = this.definition.joins.map(
|
|
38
|
+
(join) => compiler.compileJoin(dialect, join, params)
|
|
39
|
+
);
|
|
40
|
+
parts.push(...joinParts);
|
|
36
41
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
parts.push(`WHERE ${whereConditions
|
|
42
|
+
if (this.definition.where) {
|
|
43
|
+
const whereConditions = compiler.compileAst(dialect, this.definition.where, params);
|
|
44
|
+
parts.push(`WHERE ${whereConditions}`);
|
|
40
45
|
}
|
|
41
46
|
const groupByConditions = utilities.getGroupByConditions(this);
|
|
42
47
|
if (groupByConditions.length) {
|
|
43
48
|
parts.push(`GROUP BY ${groupByConditions.join(", ")}`);
|
|
44
49
|
}
|
|
45
|
-
if (this.definition?.having
|
|
46
|
-
|
|
50
|
+
if (this.definition?.having) {
|
|
51
|
+
const havingConditions = compiler.compileAst(
|
|
52
|
+
dialect,
|
|
53
|
+
this.definition.having,
|
|
54
|
+
params
|
|
55
|
+
);
|
|
56
|
+
parts.push(`HAVING ${havingConditions}`);
|
|
47
57
|
}
|
|
48
58
|
if (this.definition?.orderBy?.length) {
|
|
49
59
|
parts.push(
|
|
50
60
|
`ORDER BY ${this.definition.orderBy.map((order) => `${order.column} ${order.direction}`).join(", ")}`
|
|
51
61
|
);
|
|
52
62
|
}
|
|
53
|
-
if (this.definition?.limit
|
|
63
|
+
if (this.definition?.limit != null) {
|
|
54
64
|
parts.push("LIMIT ?");
|
|
55
|
-
|
|
56
|
-
this.definition.params.push(this.definition.limit);
|
|
65
|
+
params.push(this.definition.limit);
|
|
57
66
|
}
|
|
58
|
-
if (this.definition?.offset
|
|
67
|
+
if (this.definition?.offset != null) {
|
|
59
68
|
parts.push("OFFSET ?");
|
|
60
|
-
|
|
61
|
-
this.definition.params.push(this.definition.offset);
|
|
69
|
+
params.push(this.definition.offset);
|
|
62
70
|
}
|
|
63
71
|
if (this.definition.queryType === constants.QueryType.UPDATE || this.definition.queryType === constants.QueryType.DELETE) {
|
|
64
72
|
if (dialect !== constants$1.Dialect.MYSQL) {
|
|
@@ -66,7 +74,7 @@ function toQuery(dialect) {
|
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
const sql = buildQuery(parts.join(" "));
|
|
69
|
-
return { query: `${sql};`, params
|
|
77
|
+
return { query: `${sql};`, params };
|
|
70
78
|
}
|
|
71
79
|
function toString() {
|
|
72
80
|
return this.toQuery().query;
|
|
@@ -122,15 +130,24 @@ async function exec(tx) {
|
|
|
122
130
|
});
|
|
123
131
|
}
|
|
124
132
|
}
|
|
125
|
-
let result =
|
|
133
|
+
let result = [];
|
|
134
|
+
let mySqlResult = [];
|
|
135
|
+
if (isMySQL && isDelete) {
|
|
136
|
+
const query2 = this.clone().select(`${this.table.name}.*`);
|
|
137
|
+
mySqlResult = await client.exec({
|
|
138
|
+
sql: query2.toQuery().query,
|
|
139
|
+
params,
|
|
140
|
+
tx
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
result = await client.exec({
|
|
126
144
|
sql: query,
|
|
127
145
|
params,
|
|
128
146
|
tx
|
|
129
147
|
});
|
|
130
|
-
if (isMySQL &&
|
|
131
|
-
const query2 = this.clone();
|
|
132
|
-
|
|
133
|
-
result = await client.exec({
|
|
148
|
+
if (isMySQL && isUpdate) {
|
|
149
|
+
const query2 = this.clone().select(`${this.table.name}.*`);
|
|
150
|
+
mySqlResult = await client.exec({
|
|
134
151
|
sql: query2.toQuery().query,
|
|
135
152
|
params,
|
|
136
153
|
tx
|
|
@@ -146,7 +163,7 @@ async function exec(tx) {
|
|
|
146
163
|
});
|
|
147
164
|
}
|
|
148
165
|
}
|
|
149
|
-
return result.map(
|
|
166
|
+
return (isMySQL && isReturning ? mySqlResult : result).map(
|
|
150
167
|
(r) => utilities.parseAliasedRow({
|
|
151
168
|
row: r,
|
|
152
169
|
selects: this.definition.select ?? [],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'bun';
|
|
2
2
|
import '../column/index.cjs';
|
|
3
3
|
import '../column/constants.cjs';
|
|
4
|
-
export {
|
|
4
|
+
export { r as AcceptedInsertValues, q as AcceptedOrderBy, s as AcceptedUpdateValues, t as AggregateColumn, A as AliasedColumn, C as ColumnSelector, E as ExplainOptions, Q as QueryDefinition, n as QueryHooks, v as QueryOutput, p as QueryRunHooks, w as QueryRunHooksOptions, R as RawColumn, u as SelectQueryOutput, j as SelectableColumn, h as StrictColumnSelector, W as WhereValue } from '../index-CY-nPZED.cjs';
|
|
5
5
|
import '../types.cjs';
|
|
6
6
|
import './constants.cjs';
|
|
7
7
|
import '../table/constants.cjs';
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { T as Table,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, h as StrictColumnSelector, i as QueryBuilder, A as AliasedColumn, j as SelectableColumn } from '../index-CY-nPZED.cjs';
|
|
2
2
|
import { Column } from '../column/index.cjs';
|
|
3
|
-
import { Dialect } from '../table/constants.cjs';
|
|
4
|
-
import { AcceptedOperator } from './constants.cjs';
|
|
5
3
|
import 'bun';
|
|
6
4
|
import '../types.cjs';
|
|
5
|
+
import './constants.cjs';
|
|
7
6
|
import '../column/constants.cjs';
|
|
7
|
+
import '../table/constants.cjs';
|
|
8
8
|
import '../column/types.cjs';
|
|
9
9
|
|
|
10
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): {
|
|
11
11
|
from: string;
|
|
12
12
|
columns: string[];
|
|
13
13
|
};
|
|
14
|
-
declare function getCondition<DbDialect extends Dialect, ColName extends string, Operator extends AcceptedOperator, Value extends WhereValue<Column>[Operator]>(dialect: DbDialect, column: ColName, operator: Operator, value: Value): string;
|
|
15
14
|
declare function getTimestamp<TableRef extends Table<string, Record<string, Column>>>(table: TableRef): {
|
|
16
15
|
isWithTimestamp: boolean;
|
|
17
16
|
timestamp: Date;
|
|
@@ -25,7 +24,6 @@ declare function getParanoid<TableRef extends Table<string, Record<string, Colum
|
|
|
25
24
|
timestamp: Date;
|
|
26
25
|
deletedAt: string;
|
|
27
26
|
};
|
|
28
|
-
declare function getWhereConditions<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>>(q: Query): string[];
|
|
29
27
|
declare function getGroupByConditions<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>>(q: Query): (string | AliasedColumn<ColumnSelector<Alias, TableRef, JoinedTables>, string>)[];
|
|
30
28
|
declare function getTableSelectName<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>>(q: Query): string;
|
|
31
29
|
declare function parseAliasedRow({ row, selects, root, }: {
|
|
@@ -35,4 +33,4 @@ declare function parseAliasedRow({ row, selects, root, }: {
|
|
|
35
33
|
}): Record<string, any>;
|
|
36
34
|
declare function sanitizeParams(params: unknown[]): (string | number | bigint | boolean | null)[];
|
|
37
35
|
|
|
38
|
-
export {
|
|
36
|
+
export { getGroupByConditions, getParanoid, getTableColumnNames, getTableSelectName, getTimestamp, parseAliasedRow, sanitizeParams };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('.');
|
|
4
|
-
var constants$1 = require('../table/constants');
|
|
5
4
|
var utilities = require('../utilities');
|
|
6
5
|
var constants = require('./constants');
|
|
7
6
|
|
|
@@ -15,102 +14,6 @@ function getTableColumnNames(column, baseAlias, baseTable, joinedTables) {
|
|
|
15
14
|
columns
|
|
16
15
|
};
|
|
17
16
|
}
|
|
18
|
-
function getCondition(dialect, column, operator, value) {
|
|
19
|
-
switch (operator) {
|
|
20
|
-
case constants.AcceptedOperator.EQ:
|
|
21
|
-
return `${column} = ?`;
|
|
22
|
-
case constants.AcceptedOperator.NE:
|
|
23
|
-
return `${column} != ?`;
|
|
24
|
-
case constants.AcceptedOperator.GT:
|
|
25
|
-
return `${column} > ?`;
|
|
26
|
-
case constants.AcceptedOperator.LT:
|
|
27
|
-
return `${column} < ?`;
|
|
28
|
-
case constants.AcceptedOperator.GTE:
|
|
29
|
-
return `${column} >= ?`;
|
|
30
|
-
case constants.AcceptedOperator.LTE:
|
|
31
|
-
return `${column} <= ?`;
|
|
32
|
-
case constants.AcceptedOperator.IN:
|
|
33
|
-
return `${column} IN (${value.map(() => "?").join(", ")})`;
|
|
34
|
-
case constants.AcceptedOperator.NOT_IN:
|
|
35
|
-
return `${column} NOT IN (${value.map(() => "?").join(", ")})`;
|
|
36
|
-
case constants.AcceptedOperator.LIKE:
|
|
37
|
-
return `${column} LIKE ?`;
|
|
38
|
-
case constants.AcceptedOperator.NOT_LIKE:
|
|
39
|
-
return `${column} NOT LIKE ?`;
|
|
40
|
-
case constants.AcceptedOperator.ILIKE:
|
|
41
|
-
if (dialect === constants$1.Dialect.POSTGRES) {
|
|
42
|
-
return `${column} ILIKE ?`;
|
|
43
|
-
}
|
|
44
|
-
return `LOWER(${column}) LIKE LOWER(?)`;
|
|
45
|
-
case constants.AcceptedOperator.NOT_ILIKE:
|
|
46
|
-
if (dialect === constants$1.Dialect.POSTGRES) {
|
|
47
|
-
return `${column} NOT ILIKE ?`;
|
|
48
|
-
}
|
|
49
|
-
return `LOWER(${column}) NOT LIKE LOWER(?)`;
|
|
50
|
-
case constants.AcceptedOperator.IS_NULL:
|
|
51
|
-
return `${column} IS NULL`;
|
|
52
|
-
case constants.AcceptedOperator.IS_NOT_NULL:
|
|
53
|
-
return `${column} IS NOT NULL`;
|
|
54
|
-
case constants.AcceptedOperator.BETWEEN:
|
|
55
|
-
return `${column} BETWEEN ? AND ?`;
|
|
56
|
-
case constants.AcceptedOperator.NOT_BETWEEN:
|
|
57
|
-
return `${column} NOT BETWEEN ? AND ?`;
|
|
58
|
-
case constants.AcceptedOperator.STARTS_WITH:
|
|
59
|
-
return `${column} LIKE ?`;
|
|
60
|
-
case constants.AcceptedOperator.ENDS_WITH:
|
|
61
|
-
return `${column} LIKE ?`;
|
|
62
|
-
case constants.AcceptedOperator.REG_EXP: {
|
|
63
|
-
switch (dialect) {
|
|
64
|
-
case constants$1.Dialect.POSTGRES:
|
|
65
|
-
return `${column} ~ ?`;
|
|
66
|
-
case constants$1.Dialect.MYSQL:
|
|
67
|
-
return `${column} REGEXP ?`;
|
|
68
|
-
case constants$1.Dialect.SQLITE:
|
|
69
|
-
return `${column} GLOB ?`;
|
|
70
|
-
default:
|
|
71
|
-
throw new Error("Operator not supported");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
case constants.AcceptedOperator.NOT_REG_EXP: {
|
|
75
|
-
switch (dialect) {
|
|
76
|
-
case constants$1.Dialect.POSTGRES:
|
|
77
|
-
return `${column} !~ ?`;
|
|
78
|
-
case constants$1.Dialect.MYSQL:
|
|
79
|
-
return `${column} NOT REGEXP ?`;
|
|
80
|
-
case constants$1.Dialect.SQLITE:
|
|
81
|
-
return `${column} NOT GLOB ?`;
|
|
82
|
-
default:
|
|
83
|
-
throw new Error("Operator not supported");
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
case constants.AcceptedOperator.RLIKE: {
|
|
87
|
-
switch (dialect) {
|
|
88
|
-
case constants$1.Dialect.POSTGRES:
|
|
89
|
-
return `${column} ~* ?`;
|
|
90
|
-
case constants$1.Dialect.MYSQL:
|
|
91
|
-
return `${column} RLIKE ?`;
|
|
92
|
-
case constants$1.Dialect.SQLITE:
|
|
93
|
-
return `${column} GLOB ?`;
|
|
94
|
-
default:
|
|
95
|
-
throw new Error("Operator not supported");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
case constants.AcceptedOperator.NOT_RLIKE: {
|
|
99
|
-
switch (dialect) {
|
|
100
|
-
case constants$1.Dialect.POSTGRES:
|
|
101
|
-
return `${column} !~* ?`;
|
|
102
|
-
case constants$1.Dialect.MYSQL:
|
|
103
|
-
return `${column} NOT RLIKE ?`;
|
|
104
|
-
case constants$1.Dialect.SQLITE:
|
|
105
|
-
return `${column} NOT GLOB ?`;
|
|
106
|
-
default:
|
|
107
|
-
throw new Error("Operator not supported");
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
default:
|
|
111
|
-
throw new Error("Invalid operator");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
17
|
function getTimestamp(table) {
|
|
115
18
|
const isWithTimestamp = !!table.timestamp;
|
|
116
19
|
const timestamp = /* @__PURE__ */ new Date();
|
|
@@ -157,23 +60,6 @@ function getParanoid(table) {
|
|
|
157
60
|
deletedAt
|
|
158
61
|
};
|
|
159
62
|
}
|
|
160
|
-
function getWhereConditions(q) {
|
|
161
|
-
if (q.definition.queryType === constants.QueryType.INSERT) return [];
|
|
162
|
-
const conditions = [];
|
|
163
|
-
const base = q.definition.baseAlias ?? q.table.name;
|
|
164
|
-
const { isWithParanoid, deletedAt } = getParanoid(q.table);
|
|
165
|
-
const withDeleted = !!q.definition.withDeleted;
|
|
166
|
-
const isHasConditions = !!q.definition.where?.length;
|
|
167
|
-
if (!withDeleted && isWithParanoid) {
|
|
168
|
-
const suffix = isHasConditions ? " AND" : "";
|
|
169
|
-
const column = `${base}.${utilities.quoteIdentifier(deletedAt)}`;
|
|
170
|
-
conditions.unshift(`${column} IS NULL${suffix}`);
|
|
171
|
-
}
|
|
172
|
-
if (q.definition.where?.length) {
|
|
173
|
-
conditions.push(...q.definition.where);
|
|
174
|
-
}
|
|
175
|
-
return conditions;
|
|
176
|
-
}
|
|
177
63
|
function getGroupByConditions(q) {
|
|
178
64
|
if (q.definition.queryType !== constants.QueryType.SELECT) return [];
|
|
179
65
|
if (q.definition.groupBy?.length) return q.definition.groupBy;
|
|
@@ -254,12 +140,10 @@ function sanitizeParams(params) {
|
|
|
254
140
|
});
|
|
255
141
|
}
|
|
256
142
|
|
|
257
|
-
exports.getCondition = getCondition;
|
|
258
143
|
exports.getGroupByConditions = getGroupByConditions;
|
|
259
144
|
exports.getParanoid = getParanoid;
|
|
260
145
|
exports.getTableColumnNames = getTableColumnNames;
|
|
261
146
|
exports.getTableSelectName = getTableSelectName;
|
|
262
147
|
exports.getTimestamp = getTimestamp;
|
|
263
|
-
exports.getWhereConditions = getWhereConditions;
|
|
264
148
|
exports.parseAliasedRow = parseAliasedRow;
|
|
265
149
|
exports.sanitizeParams = sanitizeParams;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'bun';
|
|
2
|
-
export {
|
|
2
|
+
export { K as ExecOptions, M as MergeTimestampParanoid, H as TableOptions, I as TableOutput, c as TimestampOptions } from '../index-CY-nPZED.cjs';
|
|
3
3
|
import '../column/index.cjs';
|
|
4
4
|
import './constants.cjs';
|
|
5
5
|
import '../types.cjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../column/constants.cjs';
|
|
2
2
|
import '../column/index.cjs';
|
|
3
3
|
import './constants.cjs';
|
|
4
|
-
export {
|
|
4
|
+
export { y as createdAt, F as defineColumns, B as deletedAt, z as updatedAt } from '../index-CY-nPZED.cjs';
|
|
5
5
|
import '../column/types.cjs';
|
|
6
6
|
import 'bun';
|
|
7
7
|
import '../types.cjs';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { D as Database } from '../index-
|
|
1
|
+
import { D as Database } from '../index-BWg1JZRt.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
3
|
import { AcceptedColumnTypes } from '../column/constants.js';
|
|
4
|
-
import { T as Table, D as DatabaseDefinition } from '../index-
|
|
4
|
+
import { T as Table, D as DatabaseDefinition } from '../index-CsVPGz2o.js';
|
|
5
5
|
import { Dialect } from '../table/constants.js';
|
|
6
6
|
import 'bun';
|
|
7
7
|
import '../query/constants.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as Database } from '../index-
|
|
1
|
+
import { D as Database } from '../index-BWg1JZRt.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
|
-
import { T as Table, D as DatabaseDefinition } from '../index-
|
|
3
|
+
import { T as Table, D as DatabaseDefinition } from '../index-CsVPGz2o.js';
|
|
4
4
|
import { Dialect } from '../table/constants.js';
|
|
5
5
|
import 'bun';
|
|
6
6
|
import '../query/constants.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { C as ColumnAlterationContract, T as TableAlterationContract } from '../index-
|
|
1
|
+
export { C as ColumnAlterationContract, T as TableAlterationContract } from '../index-BWg1JZRt.js';
|
|
2
2
|
import '../column/index.js';
|
|
3
3
|
import '../column/constants.js';
|
|
4
|
-
import '../index-
|
|
4
|
+
import '../index-CsVPGz2o.js';
|
|
5
5
|
import '../table/constants.js';
|
|
6
6
|
import 'bun';
|
|
7
7
|
import '../query/constants.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import 'bun';
|
|
2
2
|
import '../column/index.js';
|
|
3
|
-
import '../index-
|
|
3
|
+
import '../index-CsVPGz2o.js';
|
|
4
4
|
import '../query/constants.js';
|
|
5
5
|
import '../table/constants.js';
|
|
6
|
-
export { D as Database } from '../index-
|
|
6
|
+
export { D as Database } from '../index-BWg1JZRt.js';
|
|
7
7
|
import '../column/constants.js';
|
|
8
8
|
import '../column/types.js';
|
|
9
9
|
import '../types.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as Database } from '../index-
|
|
1
|
+
import { D as Database } from '../index-BWg1JZRt.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
|
-
import { T as Table, D as DatabaseDefinition,
|
|
3
|
+
import { T as Table, D as DatabaseDefinition, h as TimestampOptions, M as MergeTimestampParanoid } from '../index-CsVPGz2o.js';
|
|
4
4
|
import { Dialect } from '../table/constants.js';
|
|
5
5
|
import 'bun';
|
|
6
6
|
import '../query/constants.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'bun';
|
|
2
2
|
import '../column/index.js';
|
|
3
|
-
export { D as DatabaseDefinition,
|
|
3
|
+
export { D as DatabaseDefinition, j as DatabaseDialect, k as DatabaseExecOptions, o as DatabaseOptions, l as MysqlConfig, P as PostgresConfig, x as SqlConfig, i as SqlConfigMapping, m as SqliteConfig } from '../index-CsVPGz2o.js';
|
|
4
4
|
import '../table/constants.js';
|
|
5
5
|
import '../column/constants.js';
|
|
6
6
|
import '../column/types.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SQL, TransactionSQL } from 'bun';
|
|
2
2
|
import { Dialect } from '../table/constants.js';
|
|
3
|
-
import {
|
|
3
|
+
import { i as SqlConfigMapping, j as DatabaseDialect, k as DatabaseExecOptions, P as PostgresConfig, l as MysqlConfig, m as SqliteConfig } from '../index-CsVPGz2o.js';
|
|
4
4
|
import '../column/index.js';
|
|
5
5
|
import '../column/constants.js';
|
|
6
6
|
import '../column/types.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TransactionSQL } from 'bun';
|
|
2
2
|
import { Column } from './column/index.js';
|
|
3
|
-
import { T as Table, D as DatabaseDefinition,
|
|
3
|
+
import { T as Table, D as DatabaseDefinition, h as TimestampOptions, M as MergeTimestampParanoid, n as QueryHooks, j as DatabaseDialect, o as DatabaseOptions, c as QueryBuilder, p as QueryRunHooks } from './index-CsVPGz2o.js';
|
|
4
4
|
import { QueryHooksType } from './query/constants.js';
|
|
5
5
|
import { Dialect } from './table/constants.js';
|
|
6
6
|
import { AcceptedColumnTypes } from './column/constants.js';
|