@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, S as StrictColumnSelector, W as WhereValue, c as QueryBuilder, e as QueryTransformerContract, f as QueryConditionContract, G as GroupNode } from '../../index-CsVPGz2o.js';
|
|
2
2
|
import { Column } from '../../column/index.js';
|
|
3
3
|
import { AcceptedOperator } from '../constants.js';
|
|
4
4
|
import 'bun';
|
|
@@ -21,13 +21,6 @@ declare function or<Alias extends string, TableRef extends Table<string, Record<
|
|
|
21
21
|
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>, QueryConditionContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
22
22
|
where: string[];
|
|
23
23
|
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>>;
|
|
24
|
-
declare function on<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>, ColName extends StrictAllowedColumn, Operator extends typeof AcceptedOperator.EQ | typeof AcceptedOperator.NE>(this: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, columnA: ColName, operator: Operator, columnB: ColName): QueryBuilder<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
25
|
-
where: string[];
|
|
26
|
-
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>, QueryTransformerContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
27
|
-
where: string[];
|
|
28
|
-
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>, QueryConditionContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
29
|
-
where: string[];
|
|
30
|
-
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>>;
|
|
31
24
|
declare function having<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>, ColName extends StrictAllowedColumn, Col extends ColName extends `${infer TableAlias}.${infer TableColumn}` ? TableAlias extends Alias ? TableRef['columns'][TableColumn] : JoinedTables[TableAlias]['columns'][TableColumn] : never, Operator extends AcceptedOperator, Value extends WhereValue<Col>[Operator]>(this: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, column: ColName, operator: Operator, value: Value): QueryBuilder<Alias, TableRef, JoinedTables, Omit<Definition, "having"> & {
|
|
32
25
|
having: string[];
|
|
33
26
|
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>, QueryTransformerContract<Alias, TableRef, JoinedTables, Omit<Definition, "having"> & {
|
|
@@ -35,7 +28,19 @@ declare function having<Alias extends string, TableRef extends Table<string, Rec
|
|
|
35
28
|
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>, QueryConditionContract<Alias, TableRef, JoinedTables, Omit<Definition, "having"> & {
|
|
36
29
|
having: string[];
|
|
37
30
|
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>>;
|
|
38
|
-
declare function whereGroup<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>>(this: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, callback: (q: QueryBuilder<Alias, TableRef, JoinedTables>) => QueryBuilder<Alias, TableRef, JoinedTables>): QueryBuilder<Alias, TableRef, JoinedTables,
|
|
39
|
-
|
|
31
|
+
declare function whereGroup<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>>(this: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, callback: (q: QueryBuilder<Alias, TableRef, JoinedTables>) => QueryBuilder<Alias, TableRef, JoinedTables>): QueryBuilder<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
32
|
+
where: GroupNode;
|
|
33
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>, QueryTransformerContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
34
|
+
where: GroupNode;
|
|
35
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>, QueryConditionContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
36
|
+
where: GroupNode;
|
|
37
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>>;
|
|
38
|
+
declare function orGroup<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>>(this: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, callback: (q: QueryBuilder<Alias, TableRef, JoinedTables>) => QueryBuilder<Alias, TableRef, JoinedTables>): QueryBuilder<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
39
|
+
where: GroupNode;
|
|
40
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>, QueryTransformerContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
41
|
+
where: GroupNode;
|
|
42
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>, QueryConditionContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
43
|
+
where: GroupNode;
|
|
44
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>>;
|
|
40
45
|
|
|
41
|
-
export { having,
|
|
46
|
+
export { having, or, orGroup, where, whereGroup };
|
|
@@ -24,17 +24,6 @@ function or(column, operator, value) {
|
|
|
24
24
|
false
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
|
-
function on(columnA, operator, columnB) {
|
|
28
|
-
return addCondition(
|
|
29
|
-
this,
|
|
30
|
-
ConditionClause.WHERE,
|
|
31
|
-
columnA,
|
|
32
|
-
operator,
|
|
33
|
-
columnB,
|
|
34
|
-
LogicalOperator.ON,
|
|
35
|
-
false
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
27
|
function having(column, operator, value) {
|
|
39
28
|
return addCondition(
|
|
40
29
|
this,
|
|
@@ -53,4 +42,4 @@ function orGroup(callback) {
|
|
|
53
42
|
return addGroupCondition(this, LogicalOperator.OR, callback, false);
|
|
54
43
|
}
|
|
55
44
|
|
|
56
|
-
export { having,
|
|
45
|
+
export { having, or, orGroup, where, whereGroup };
|
|
@@ -1,53 +1,87 @@
|
|
|
1
1
|
import { QueryBuilder } from '../index.js';
|
|
2
|
-
import { LogicalOperator, AcceptedOperator } from '../constants.js';
|
|
3
|
-
import { getCondition } from '../utilities.js';
|
|
2
|
+
import { LogicalOperator, AstType, AcceptedOperator } from '../constants.js';
|
|
4
3
|
|
|
5
4
|
// src/query/condition/core.ts
|
|
6
5
|
function addCondition(query, clause, column, operator, value, logical, negate) {
|
|
7
6
|
if (!query.table.dialect) {
|
|
8
7
|
throw new Error("No DB Dialect defined");
|
|
9
8
|
}
|
|
10
|
-
const isOn = logical === LogicalOperator.ON;
|
|
11
9
|
const validClause = clause.toLowerCase();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const not = negate ? "NOT " : "";
|
|
19
|
-
query.definition[validClause].push(
|
|
20
|
-
`${logicalPrefix} ${not}${condition}`.trim()
|
|
21
|
-
);
|
|
22
|
-
if (operator === AcceptedOperator.IS_NULL || operator === AcceptedOperator.IS_NOT_NULL) {
|
|
23
|
-
return query;
|
|
10
|
+
if (!query.definition[validClause]) {
|
|
11
|
+
query.definition[validClause] = {
|
|
12
|
+
type: AstType.GROUP,
|
|
13
|
+
operator: LogicalOperator.AND,
|
|
14
|
+
children: []
|
|
15
|
+
};
|
|
24
16
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
17
|
+
const root = query.definition[validClause];
|
|
18
|
+
let node = {
|
|
19
|
+
type: AstType.COMPARISON,
|
|
20
|
+
column,
|
|
21
|
+
operator,
|
|
22
|
+
value,
|
|
23
|
+
values: value
|
|
24
|
+
};
|
|
25
|
+
if (node.type === AstType.COMPARISON) {
|
|
26
|
+
if (node.operator === AcceptedOperator.IS_NULL && "value" in node) {
|
|
27
|
+
delete node.value;
|
|
28
|
+
}
|
|
29
|
+
if (node.operator === AcceptedOperator.STARTS_WITH) {
|
|
30
|
+
node.value = "%" + node.value;
|
|
31
|
+
}
|
|
32
|
+
if (node.operator === AcceptedOperator.ENDS_WITH) {
|
|
33
|
+
node.value = node.value + "%";
|
|
35
34
|
}
|
|
36
35
|
}
|
|
36
|
+
if (negate) {
|
|
37
|
+
node = {
|
|
38
|
+
type: AstType.NOT,
|
|
39
|
+
child: node
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (operator === AcceptedOperator.IS_NULL) {
|
|
43
|
+
return query;
|
|
44
|
+
}
|
|
45
|
+
if (root.operator === logical) {
|
|
46
|
+
root.children.push(node);
|
|
47
|
+
} else {
|
|
48
|
+
query.definition.where = {
|
|
49
|
+
type: AstType.GROUP,
|
|
50
|
+
operator: logical,
|
|
51
|
+
children: [root, node]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
37
54
|
return query;
|
|
38
55
|
}
|
|
39
56
|
function addGroupCondition(query, logical, callback, negate) {
|
|
40
57
|
const sub = callback(new QueryBuilder(query.table));
|
|
41
58
|
const subDef = sub.definition;
|
|
42
|
-
if (!
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
query
|
|
59
|
+
if (!query.definition.where) {
|
|
60
|
+
query.definition.where = {
|
|
61
|
+
type: AstType.GROUP,
|
|
62
|
+
operator: LogicalOperator.AND,
|
|
63
|
+
children: []
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (!subDef.where || subDef.where.children.length === 0) {
|
|
67
|
+
return query;
|
|
68
|
+
}
|
|
69
|
+
const root = query.definition.where;
|
|
70
|
+
let groupNode = subDef.where;
|
|
71
|
+
if (negate) {
|
|
72
|
+
groupNode = {
|
|
73
|
+
type: AstType.NOT,
|
|
74
|
+
child: groupNode
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (root.operator === logical) {
|
|
78
|
+
root.children.push(groupNode);
|
|
79
|
+
} else {
|
|
80
|
+
query.definition.where = {
|
|
81
|
+
type: AstType.GROUP,
|
|
82
|
+
operator: logical,
|
|
83
|
+
children: [root, groupNode]
|
|
84
|
+
};
|
|
51
85
|
}
|
|
52
86
|
return query;
|
|
53
87
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { having,
|
|
2
|
-
export { a as addCondition, b as addGroupCondition
|
|
1
|
+
export { having, or, orGroup, where, whereGroup } from './common.js';
|
|
2
|
+
export { a as addCondition, b as addGroupCondition } from '../../index-CsVPGz2o.js';
|
|
3
3
|
export { havingNot, orNot, orNotGroup, whereNot, whereNotGroup } from './not.js';
|
|
4
4
|
import '../../column/index.js';
|
|
5
5
|
import '../../table/constants.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, S as StrictColumnSelector, W as WhereValue, c as QueryBuilder, e as QueryTransformerContract, f as QueryConditionContract, G as GroupNode } from '../../index-CsVPGz2o.js';
|
|
2
2
|
import { Column } from '../../column/index.js';
|
|
3
3
|
import { AcceptedOperator } from '../constants.js';
|
|
4
4
|
import 'bun';
|
|
@@ -28,7 +28,19 @@ declare function orNot<Alias extends string, TableRef extends Table<string, Reco
|
|
|
28
28
|
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>, QueryConditionContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
29
29
|
where: string[];
|
|
30
30
|
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>>;
|
|
31
|
-
declare function whereNotGroup<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>>(this: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, callback: (q: QueryBuilder<Alias, TableRef, JoinedTables>) => QueryBuilder<Alias, TableRef, JoinedTables>): QueryBuilder<Alias, TableRef, JoinedTables,
|
|
32
|
-
|
|
31
|
+
declare function whereNotGroup<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>>(this: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, callback: (q: QueryBuilder<Alias, TableRef, JoinedTables>) => QueryBuilder<Alias, TableRef, JoinedTables>): QueryBuilder<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
32
|
+
where: GroupNode;
|
|
33
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>, QueryTransformerContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
34
|
+
where: GroupNode;
|
|
35
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>, QueryConditionContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
36
|
+
where: GroupNode;
|
|
37
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>>;
|
|
38
|
+
declare function orNotGroup<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>>(this: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, callback: (q: QueryBuilder<Alias, TableRef, JoinedTables>) => QueryBuilder<Alias, TableRef, JoinedTables>): QueryBuilder<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
39
|
+
where: GroupNode;
|
|
40
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>, QueryTransformerContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
41
|
+
where: GroupNode;
|
|
42
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>, QueryConditionContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
|
|
43
|
+
where: GroupNode;
|
|
44
|
+
}, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>>;
|
|
33
45
|
|
|
34
46
|
export { havingNot, orNot, orNotGroup, whereNot, whereNotGroup };
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
declare const LogicalOperator: {
|
|
2
2
|
readonly AND: "AND";
|
|
3
3
|
readonly OR: "OR";
|
|
4
|
-
readonly ON: "ON";
|
|
5
4
|
};
|
|
6
5
|
type LogicalOperator = (typeof LogicalOperator)[keyof typeof LogicalOperator];
|
|
6
|
+
declare const AstType: {
|
|
7
|
+
readonly GROUP: "GROUP";
|
|
8
|
+
readonly COMPARISON: "COMPARISON";
|
|
9
|
+
readonly NOT: "NOT";
|
|
10
|
+
readonly JOIN: "JOIN";
|
|
11
|
+
};
|
|
12
|
+
type AstType = (typeof AstType)[keyof typeof AstType];
|
|
7
13
|
declare const ConditionClause: {
|
|
8
14
|
readonly WHERE: "WHERE";
|
|
9
15
|
readonly HAVING: "HAVING";
|
|
@@ -17,21 +23,14 @@ declare const AcceptedOperator: {
|
|
|
17
23
|
readonly GTE: "gte";
|
|
18
24
|
readonly LTE: "lte";
|
|
19
25
|
readonly IN: "in";
|
|
20
|
-
readonly NOT_IN: "notIn";
|
|
21
26
|
readonly LIKE: "like";
|
|
22
|
-
readonly NOT_LIKE: "notLike";
|
|
23
27
|
readonly ILIKE: "ilike";
|
|
24
|
-
readonly NOT_ILIKE: "notILike";
|
|
25
28
|
readonly IS_NULL: "isNull";
|
|
26
|
-
readonly IS_NOT_NULL: "isNotNull";
|
|
27
29
|
readonly BETWEEN: "between";
|
|
28
|
-
readonly NOT_BETWEEN: "notBetween";
|
|
29
30
|
readonly STARTS_WITH: "startsWith";
|
|
30
31
|
readonly ENDS_WITH: "endsWith";
|
|
31
32
|
readonly REG_EXP: "regExp";
|
|
32
|
-
readonly NOT_REG_EXP: "notRegExp";
|
|
33
33
|
readonly RLIKE: "rlike";
|
|
34
|
-
readonly NOT_RLIKE: "notRlike";
|
|
35
34
|
};
|
|
36
35
|
type AcceptedOperator = (typeof AcceptedOperator)[keyof typeof AcceptedOperator];
|
|
37
36
|
declare const QueryType: {
|
|
@@ -86,4 +85,4 @@ declare const ExplainClause: {
|
|
|
86
85
|
};
|
|
87
86
|
type ExplainClause = (typeof ExplainClause)[keyof typeof ExplainClause];
|
|
88
87
|
|
|
89
|
-
export { AcceptedJoin, AcceptedOperator, AggregationFunction, ConditionClause, ExplainClause, ExplainFormat, LogicalOperator, OrderBy, QueryHooksType, QueryType };
|
|
88
|
+
export { AcceptedJoin, AcceptedOperator, AggregationFunction, AstType, ConditionClause, ExplainClause, ExplainFormat, LogicalOperator, OrderBy, QueryHooksType, QueryType };
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
// src/query/constants.ts
|
|
2
2
|
var LogicalOperator = {
|
|
3
3
|
AND: "AND",
|
|
4
|
-
OR: "OR"
|
|
5
|
-
|
|
4
|
+
OR: "OR"
|
|
5
|
+
};
|
|
6
|
+
var AstType = {
|
|
7
|
+
GROUP: "GROUP",
|
|
8
|
+
COMPARISON: "COMPARISON",
|
|
9
|
+
NOT: "NOT",
|
|
10
|
+
JOIN: "JOIN"
|
|
6
11
|
};
|
|
7
12
|
var ConditionClause = {
|
|
8
13
|
WHERE: "WHERE",
|
|
@@ -16,21 +21,14 @@ var AcceptedOperator = {
|
|
|
16
21
|
GTE: "gte",
|
|
17
22
|
LTE: "lte",
|
|
18
23
|
IN: "in",
|
|
19
|
-
NOT_IN: "notIn",
|
|
20
24
|
LIKE: "like",
|
|
21
|
-
NOT_LIKE: "notLike",
|
|
22
25
|
ILIKE: "ilike",
|
|
23
|
-
NOT_ILIKE: "notILike",
|
|
24
26
|
IS_NULL: "isNull",
|
|
25
|
-
IS_NOT_NULL: "isNotNull",
|
|
26
27
|
BETWEEN: "between",
|
|
27
|
-
NOT_BETWEEN: "notBetween",
|
|
28
28
|
STARTS_WITH: "startsWith",
|
|
29
29
|
ENDS_WITH: "endsWith",
|
|
30
30
|
REG_EXP: "regExp",
|
|
31
|
-
|
|
32
|
-
RLIKE: "rlike",
|
|
33
|
-
NOT_RLIKE: "notRlike"
|
|
31
|
+
RLIKE: "rlike"
|
|
34
32
|
};
|
|
35
33
|
var QueryType = {
|
|
36
34
|
SELECT: "SELECT",
|
|
@@ -77,4 +75,4 @@ var ExplainClause = {
|
|
|
77
75
|
TIMING: "TIMING"
|
|
78
76
|
};
|
|
79
77
|
|
|
80
|
-
export { AcceptedJoin, AcceptedOperator, AggregationFunction, ConditionClause, ExplainClause, ExplainFormat, LogicalOperator, OrderBy, QueryHooksType, QueryType };
|
|
78
|
+
export { AcceptedJoin, AcceptedOperator, AggregationFunction, AstType, ConditionClause, ExplainClause, ExplainFormat, LogicalOperator, OrderBy, QueryHooksType, QueryType };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'bun';
|
|
2
|
-
export {
|
|
2
|
+
export { f as QueryConditionContract, e as QueryTransformerContract } from '../index-CsVPGz2o.js';
|
|
3
3
|
import '../column/index.js';
|
|
4
4
|
import '../table/constants.js';
|
|
5
5
|
import './constants.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, S as StrictColumnSelector, c as QueryBuilder, E as ExplainOptions } from '../index-CsVPGz2o.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
3
|
import 'bun';
|
|
4
4
|
import '../types.js';
|
|
@@ -40,7 +40,7 @@ function buildMySqlExplainQuery(options) {
|
|
|
40
40
|
clauses.push(`${ExplainClause.FORMAT}=${options.format}`);
|
|
41
41
|
}
|
|
42
42
|
if (clauses.length > 1) {
|
|
43
|
-
throw new Error("
|
|
43
|
+
throw new Error("MySQL EXPLAIN only support one clauses at a time");
|
|
44
44
|
}
|
|
45
45
|
return `EXPLAIN ${clauses.join(" ")}`;
|
|
46
46
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a1 as aggregateCol, _ as alias, $ as clone, a0 as col } from '../index-CsVPGz2o.js';
|
|
2
2
|
import '../column/index.js';
|
|
3
3
|
import './constants.js';
|
|
4
4
|
import 'bun';
|
package/dist/esm/query/helper.js
CHANGED
|
@@ -11,9 +11,6 @@ function clone() {
|
|
|
11
11
|
Object.assign(query.definition, cloneDefinition(this.definition));
|
|
12
12
|
return query;
|
|
13
13
|
}
|
|
14
|
-
function rawCol(column) {
|
|
15
|
-
return column;
|
|
16
|
-
}
|
|
17
14
|
function col(column, alias2) {
|
|
18
15
|
return {
|
|
19
16
|
column,
|
|
@@ -28,4 +25,4 @@ function aggregateCol(fn, column, alias2) {
|
|
|
28
25
|
};
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
export { aggregateCol, alias, clone, col
|
|
28
|
+
export { aggregateCol, alias, clone, col };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
export { c as QueryBuilder } from '../index-CsVPGz2o.js';
|
|
1
2
|
import '../column/index.js';
|
|
2
|
-
export { l as QueryBuilder } from '../index-CjurLJdK.js';
|
|
3
3
|
import '../types.js';
|
|
4
4
|
import './constants.js';
|
|
5
|
-
import '
|
|
5
|
+
import 'bun';
|
|
6
6
|
import '../column/constants.js';
|
|
7
|
+
import '../table/constants.js';
|
|
7
8
|
import '../column/types.js';
|
|
8
|
-
import 'bun';
|
package/dist/esm/query/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { quoteIdentifier } from '../utilities.js';
|
|
2
|
-
import {
|
|
2
|
+
import { where, having, or, whereGroup, orGroup, orNotGroup, whereNotGroup, orNot, havingNot, whereNot } from './condition/index.js';
|
|
3
3
|
import { AcceptedJoin, QueryType } from './constants.js';
|
|
4
4
|
import { alias, clone, aggregateCol, col } from './helper.js';
|
|
5
5
|
import { prepareJoin, addNoOnJoin } from './join.js';
|
|
@@ -19,14 +19,9 @@ var QueryBuilder = class {
|
|
|
19
19
|
toDebugString;
|
|
20
20
|
explain;
|
|
21
21
|
exec;
|
|
22
|
-
rawWhere;
|
|
23
|
-
rawAnd;
|
|
24
|
-
rawOr;
|
|
25
|
-
rawHaving;
|
|
26
22
|
where;
|
|
27
23
|
and;
|
|
28
24
|
or;
|
|
29
|
-
on;
|
|
30
25
|
having;
|
|
31
26
|
whereGroup;
|
|
32
27
|
orGroup;
|
|
@@ -44,15 +39,10 @@ var QueryBuilder = class {
|
|
|
44
39
|
this.toDebugString = toDebugString.bind(this);
|
|
45
40
|
this.explain = explain.bind(this);
|
|
46
41
|
this.exec = exec.bind(this);
|
|
47
|
-
this.rawWhere = rawWhere.bind(this);
|
|
48
|
-
this.rawHaving = rawHaving.bind(this);
|
|
49
|
-
this.rawAnd = this.rawWhere;
|
|
50
|
-
this.rawOr = rawOr.bind(this);
|
|
51
42
|
this.where = where.bind(this);
|
|
52
43
|
this.having = having.bind(this);
|
|
53
44
|
this.and = this.where;
|
|
54
45
|
this.or = or.bind(this);
|
|
55
|
-
this.on = on.bind(this);
|
|
56
46
|
this.whereGroup = whereGroup.bind(this);
|
|
57
47
|
this.orGroup = orGroup.bind(this);
|
|
58
48
|
this.not = {
|
|
@@ -81,7 +71,7 @@ var QueryBuilder = class {
|
|
|
81
71
|
return addNoOnJoin(this, AcceptedJoin.CROSS, joinTable, alias2);
|
|
82
72
|
}
|
|
83
73
|
naturalJoin(joinTable, alias2) {
|
|
84
|
-
return
|
|
74
|
+
return addNoOnJoin(this, AcceptedJoin.NATURAL, joinTable, alias2);
|
|
85
75
|
}
|
|
86
76
|
distinct() {
|
|
87
77
|
this.definition.distinct = true;
|
package/dist/esm/query/join.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Table, Q as QueryDefinition, C as ColumnSelector,
|
|
1
|
+
import { T as Table, Q as QueryDefinition, C as ColumnSelector, S as StrictColumnSelector, c as QueryBuilder, J as JoinNode, e as QueryTransformerContract, f as QueryConditionContract } from '../index-CsVPGz2o.js';
|
|
2
2
|
import { Column } from '../column/index.js';
|
|
3
3
|
import { AcceptedJoin } from './constants.js';
|
|
4
4
|
import 'bun';
|
|
@@ -10,18 +10,18 @@ import '../column/types.js';
|
|
|
10
10
|
declare function addNoOnJoin<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>, JoinType extends AcceptedJoin, JoinTable extends Table<string, Record<string, Column>>, JoinAlias extends string, FinalJoinedTables extends JoinedTables & {
|
|
11
11
|
[K in JoinAlias]: JoinTable;
|
|
12
12
|
}>(query: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, joinType: JoinType, joinTable: JoinTable, alias: JoinAlias): QueryBuilder<Alias, TableRef, FinalJoinedTables, Omit<Definition, "joins" | "joinedTables"> & {
|
|
13
|
-
joins:
|
|
13
|
+
joins: JoinNode[];
|
|
14
14
|
joinedTables: FinalJoinedTables;
|
|
15
15
|
}>;
|
|
16
16
|
declare function prepareJoin<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>, JoinType extends AcceptedJoin, JoinTable extends Table<string, Record<string, Column>>, JoinAlias extends string>(query: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, joinType: JoinType, joinTable: JoinTable, alias: JoinAlias): {
|
|
17
17
|
on<FinalJoinedTables extends JoinedTables & { [K in JoinAlias]: JoinTable; }, ReturnedJoinedTables extends FinalJoinedTables = FinalJoinedTables>(callback: (q: QueryBuilder<Alias, TableRef, FinalJoinedTables>) => QueryBuilder<Alias, TableRef, ReturnedJoinedTables>): QueryBuilder<Alias, TableRef, ReturnedJoinedTables, Omit<Definition, "joins" | "joinedTables"> & {
|
|
18
|
-
joins:
|
|
18
|
+
joins: JoinNode[];
|
|
19
19
|
joinedTables: ReturnedJoinedTables;
|
|
20
20
|
}, ColumnSelector<Alias, TableRef, ReturnedJoinedTables>, StrictColumnSelector<Alias, TableRef, ReturnedJoinedTables>, QueryTransformerContract<Alias, TableRef, ReturnedJoinedTables, Omit<Definition, "joins" | "joinedTables"> & {
|
|
21
|
-
joins:
|
|
21
|
+
joins: JoinNode[];
|
|
22
22
|
joinedTables: ReturnedJoinedTables;
|
|
23
23
|
}, ColumnSelector<Alias, TableRef, ReturnedJoinedTables>, StrictColumnSelector<Alias, TableRef, ReturnedJoinedTables>>, QueryConditionContract<Alias, TableRef, ReturnedJoinedTables, Omit<Definition, "joins" | "joinedTables"> & {
|
|
24
|
-
joins:
|
|
24
|
+
joins: JoinNode[];
|
|
25
25
|
joinedTables: ReturnedJoinedTables;
|
|
26
26
|
}, ColumnSelector<Alias, TableRef, ReturnedJoinedTables>, StrictColumnSelector<Alias, TableRef, ReturnedJoinedTables>>>;
|
|
27
27
|
};
|
package/dist/esm/query/join.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { QueryBuilder } from './index.js';
|
|
2
|
+
import { AstType } from './constants.js';
|
|
2
3
|
|
|
3
4
|
// src/query/join.ts
|
|
4
5
|
function addNoOnJoin(query, joinType, joinTable, alias) {
|
|
5
6
|
if (!query.definition.joins) query.definition.joins = [];
|
|
6
|
-
query.definition.joins.push(
|
|
7
|
+
query.definition.joins.push({
|
|
8
|
+
type: AstType.JOIN,
|
|
9
|
+
alias,
|
|
10
|
+
join: joinType,
|
|
11
|
+
table: joinTable
|
|
12
|
+
});
|
|
7
13
|
if (!query.definition.joinedTables) {
|
|
8
14
|
query.definition.joinedTables = {};
|
|
9
15
|
}
|
|
@@ -15,21 +21,23 @@ function prepareJoin(query, joinType, joinTable, alias) {
|
|
|
15
21
|
on(callback) {
|
|
16
22
|
const sub = callback(new QueryBuilder(query.table));
|
|
17
23
|
const subDef = sub.definition;
|
|
18
|
-
if (!subDef.where
|
|
24
|
+
if (!subDef.where) {
|
|
19
25
|
return query;
|
|
20
26
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
if (!query.definition.joins) {
|
|
28
|
+
query.definition.joins = [];
|
|
29
|
+
}
|
|
30
|
+
const on = subDef.where;
|
|
31
|
+
query.definition.joins.push({
|
|
32
|
+
type: AstType.JOIN,
|
|
33
|
+
alias,
|
|
34
|
+
join: joinType,
|
|
35
|
+
table: joinTable,
|
|
36
|
+
on
|
|
37
|
+
});
|
|
26
38
|
if (subDef.joins?.length) {
|
|
27
39
|
query.definition.joins.push(...subDef.joins);
|
|
28
40
|
}
|
|
29
|
-
if (subDef.params?.length) {
|
|
30
|
-
if (!query.definition.params) query.definition.params = [];
|
|
31
|
-
query.definition.params.push(...subDef.params);
|
|
32
|
-
}
|
|
33
41
|
if (!query.definition.joinedTables) {
|
|
34
42
|
query.definition.joinedTables = {};
|
|
35
43
|
}
|
package/dist/esm/query/sql.d.ts
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, S as StrictColumnSelector, c as QueryBuilder, E as ExplainOptions } from '../index-CsVPGz2o.js';
|
|
3
3
|
import { Column } from '../column/index.js';
|
|
4
4
|
import { Dialect } from '../table/constants.js';
|
|
5
5
|
import '../types.js';
|
|
@@ -10,7 +10,7 @@ import '../column/types.js';
|
|
|
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;
|