@ignisia/sql 0.3.0 → 0.4.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.
Files changed (104) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/column/index.js +2 -9
  3. package/dist/cjs/database/alter.d.cts +2 -2
  4. package/dist/cjs/database/column.d.cts +2 -2
  5. package/dist/cjs/database/contract.d.cts +2 -2
  6. package/dist/cjs/database/index.d.cts +2 -2
  7. package/dist/cjs/database/index.js +1 -1
  8. package/dist/cjs/database/table.d.cts +2 -2
  9. package/dist/cjs/database/types.d.cts +1 -1
  10. package/dist/cjs/database/wrapper.d.cts +3 -3
  11. package/dist/cjs/database/wrapper.js +1 -17
  12. package/dist/cjs/{index-CnQVnCEI.d.cts → index-CHxuUiO4.d.cts} +178 -98
  13. package/dist/cjs/{index-2jl8MRfX.d.cts → index-CZhrzE5r.d.cts} +2 -2
  14. package/dist/cjs/index.d.cts +2 -2
  15. package/dist/cjs/migration/index.d.cts +2 -2
  16. package/dist/cjs/migration/type.d.cts +2 -2
  17. package/dist/cjs/query/builder.d.cts +3 -3
  18. package/dist/cjs/query/builder.js +1 -1
  19. package/dist/cjs/query/condition/common.d.cts +41 -0
  20. package/dist/cjs/query/condition/common.js +62 -0
  21. package/dist/cjs/query/condition/core.d.cts +8 -0
  22. package/dist/cjs/query/condition/core.js +57 -0
  23. package/dist/cjs/query/condition/index.d.cts +10 -0
  24. package/dist/cjs/query/condition/index.js +33 -0
  25. package/dist/cjs/query/condition/not.d.cts +34 -0
  26. package/dist/cjs/query/condition/not.js +51 -0
  27. package/dist/cjs/query/condition/raw.d.cts +8 -0
  28. package/dist/cjs/query/condition/raw.js +54 -0
  29. package/dist/cjs/query/constants.d.cts +27 -1
  30. package/dist/cjs/query/constants.js +28 -2
  31. package/dist/cjs/query/contract.d.cts +2 -2
  32. package/dist/cjs/query/explain.d.cts +12 -0
  33. package/dist/cjs/query/explain.js +65 -0
  34. package/dist/cjs/query/helper.d.cts +3 -3
  35. package/dist/cjs/query/helper.js +1 -1
  36. package/dist/cjs/query/index.d.cts +2 -2
  37. package/dist/cjs/query/index.js +59 -64
  38. package/dist/cjs/query/join.d.cts +18 -6
  39. package/dist/cjs/query/join.js +38 -9
  40. package/dist/cjs/query/sql.d.cts +5 -3
  41. package/dist/cjs/query/sql.js +46 -15
  42. package/dist/cjs/query/types.d.cts +2 -2
  43. package/dist/cjs/query/utilities.d.cts +5 -4
  44. package/dist/cjs/query/utilities.js +73 -2
  45. package/dist/cjs/table/index.d.cts +3 -3
  46. package/dist/cjs/table/types.d.cts +2 -2
  47. package/dist/cjs/table/utilities.d.cts +2 -2
  48. package/dist/cjs/types.d.cts +5 -1
  49. package/dist/cjs/utilities.d.cts +2 -1
  50. package/dist/cjs/utilities.js +22 -0
  51. package/dist/esm/column/index.js +3 -10
  52. package/dist/esm/database/alter.d.ts +2 -2
  53. package/dist/esm/database/column.d.ts +2 -2
  54. package/dist/esm/database/contract.d.ts +2 -2
  55. package/dist/esm/database/index.d.ts +2 -2
  56. package/dist/esm/database/index.js +2 -2
  57. package/dist/esm/database/table.d.ts +2 -2
  58. package/dist/esm/database/types.d.ts +1 -1
  59. package/dist/esm/database/wrapper.d.ts +3 -3
  60. package/dist/esm/database/wrapper.js +1 -17
  61. package/dist/esm/{index-BdpoD4zk.d.ts → index-CjurLJdK.d.ts} +178 -98
  62. package/dist/esm/{index-BXOAxB_h.d.ts → index-DgOs61lH.d.ts} +2 -2
  63. package/dist/esm/index.d.ts +2 -2
  64. package/dist/esm/migration/index.d.ts +2 -2
  65. package/dist/esm/migration/type.d.ts +2 -2
  66. package/dist/esm/query/builder.d.ts +3 -3
  67. package/dist/esm/query/builder.js +1 -1
  68. package/dist/esm/query/condition/common.d.ts +41 -0
  69. package/dist/esm/query/condition/common.js +56 -0
  70. package/dist/esm/query/condition/core.d.ts +8 -0
  71. package/dist/esm/query/condition/core.js +55 -0
  72. package/dist/esm/query/condition/index.d.ts +10 -0
  73. package/dist/esm/query/condition/index.js +4 -0
  74. package/dist/esm/query/condition/not.d.ts +34 -0
  75. package/dist/esm/query/condition/not.js +46 -0
  76. package/dist/esm/query/condition/raw.d.ts +8 -0
  77. package/dist/esm/query/condition/raw.js +50 -0
  78. package/dist/esm/query/constants.d.ts +27 -1
  79. package/dist/esm/query/constants.js +27 -3
  80. package/dist/esm/query/contract.d.ts +2 -2
  81. package/dist/esm/query/explain.d.ts +12 -0
  82. package/dist/esm/query/explain.js +64 -0
  83. package/dist/esm/query/helper.d.ts +3 -3
  84. package/dist/esm/query/helper.js +2 -2
  85. package/dist/esm/query/index.d.ts +2 -2
  86. package/dist/esm/query/index.js +62 -67
  87. package/dist/esm/query/join.d.ts +18 -6
  88. package/dist/esm/query/join.js +37 -9
  89. package/dist/esm/query/sql.d.ts +5 -3
  90. package/dist/esm/query/sql.js +46 -17
  91. package/dist/esm/query/types.d.ts +2 -2
  92. package/dist/esm/query/utilities.d.ts +5 -4
  93. package/dist/esm/query/utilities.js +73 -3
  94. package/dist/esm/table/index.d.ts +3 -3
  95. package/dist/esm/table/types.d.ts +2 -2
  96. package/dist/esm/table/utilities.d.ts +2 -2
  97. package/dist/esm/types.d.ts +5 -1
  98. package/dist/esm/utilities.d.ts +2 -1
  99. package/dist/esm/utilities.js +22 -1
  100. package/package.json +8 -2
  101. package/dist/cjs/query/condition.d.cts +0 -8
  102. package/dist/cjs/query/condition.js +0 -109
  103. package/dist/esm/query/condition.d.ts +0 -8
  104. package/dist/esm/query/condition.js +0 -101
@@ -0,0 +1,56 @@
1
+ import { ConditionClause, LogicalOperator } from '../constants.js';
2
+ import { addCondition, addGroupCondition } from './core.js';
3
+
4
+ // src/query/condition/common.ts
5
+ function where(column, operator, value) {
6
+ return addCondition(
7
+ this,
8
+ ConditionClause.WHERE,
9
+ column,
10
+ operator,
11
+ value || null,
12
+ LogicalOperator.AND,
13
+ false
14
+ );
15
+ }
16
+ function or(column, operator, value) {
17
+ return addCondition(
18
+ this,
19
+ ConditionClause.WHERE,
20
+ column,
21
+ operator,
22
+ value || null,
23
+ LogicalOperator.OR,
24
+ false
25
+ );
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
+ function having(column, operator, value) {
39
+ return addCondition(
40
+ this,
41
+ ConditionClause.HAVING,
42
+ column,
43
+ operator,
44
+ value,
45
+ LogicalOperator.AND,
46
+ false
47
+ );
48
+ }
49
+ function whereGroup(callback) {
50
+ return addGroupCondition(this, LogicalOperator.AND, callback, false);
51
+ }
52
+ function orGroup(callback) {
53
+ return addGroupCondition(this, LogicalOperator.OR, callback, false);
54
+ }
55
+
56
+ export { having, on, or, orGroup, where, whereGroup };
@@ -0,0 +1,8 @@
1
+ export { a as addCondition, b as addGroupCondition } from '../../index-CjurLJdK.js';
2
+ import '../../column/index.js';
3
+ import '../constants.js';
4
+ import 'bun';
5
+ import '../../types.js';
6
+ import '../../column/constants.js';
7
+ import '../../table/constants.js';
8
+ import '../../column/types.js';
@@ -0,0 +1,55 @@
1
+ import { QueryBuilder } from '../index.js';
2
+ import { LogicalOperator, AcceptedOperator } from '../constants.js';
3
+ import { getCondition } from '../utilities.js';
4
+
5
+ // src/query/condition/core.ts
6
+ function addCondition(query, clause, column, operator, value, logical, negate) {
7
+ if (!query.table.dialect) {
8
+ throw new Error("No DB Dialect defined");
9
+ }
10
+ const isOn = logical === LogicalOperator.ON;
11
+ const validClause = clause.toLowerCase();
12
+ let condition = getCondition(query.table.dialect, column, operator, value);
13
+ if (isOn) {
14
+ condition = condition.replace("?", value);
15
+ }
16
+ if (!query.definition[validClause]) query.definition[validClause] = [];
17
+ const logicalPrefix = query.definition[validClause].length > 0 ? isOn ? LogicalOperator.AND : logical : "";
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;
24
+ }
25
+ if (!query.definition.params) query.definition.params = [];
26
+ if (!isOn) {
27
+ if (operator === AcceptedOperator.STARTS_WITH) {
28
+ query.definition.params.push(`${value}%`);
29
+ } else if (operator === AcceptedOperator.ENDS_WITH) {
30
+ query.definition.params.push(`%${value}`);
31
+ } else if (Array.isArray(value)) {
32
+ query.definition.params.push(...value);
33
+ } else {
34
+ query.definition.params.push(value);
35
+ }
36
+ }
37
+ return query;
38
+ }
39
+ function addGroupCondition(query, logical, callback, negate) {
40
+ const sub = callback(new QueryBuilder(query.table));
41
+ const subDef = sub.definition;
42
+ if (!subDef.where?.length) return query;
43
+ const not = negate ? "NOT " : "";
44
+ const grouped = `${not}(${subDef.where.join(" ")})`;
45
+ if (!query.definition.where) query.definition.where = [];
46
+ const logicalPrefix = query.definition.where.length > 0 ? logical : "";
47
+ query.definition.where.push(`${logicalPrefix} ${grouped}`.trim());
48
+ if (subDef.params?.length) {
49
+ if (!query.definition.params) query.definition.params = [];
50
+ query.definition.params.push(...subDef.params);
51
+ }
52
+ return query;
53
+ }
54
+
55
+ export { addCondition, addGroupCondition };
@@ -0,0 +1,10 @@
1
+ export { having, on, or, orGroup, where, whereGroup } from './common.js';
2
+ export { a as addCondition, b as addGroupCondition, c as addRawCondition, e as rawHaving, d as rawOr, r as rawWhere } from '../../index-CjurLJdK.js';
3
+ export { havingNot, orNot, orNotGroup, whereNot, whereNotGroup } from './not.js';
4
+ import '../../column/index.js';
5
+ import '../../table/constants.js';
6
+ import '../../column/constants.js';
7
+ import '../../column/types.js';
8
+ import '../constants.js';
9
+ import 'bun';
10
+ import '../../types.js';
@@ -0,0 +1,4 @@
1
+ export * from './common.js';
2
+ export * from './core.js';
3
+ export * from './not.js';
4
+ export * from './raw.js';
@@ -0,0 +1,34 @@
1
+ import { T as Table, Q as QueryDefinition, C as ColumnSelector, k as StrictColumnSelector, W as WhereValue, l as QueryBuilder, n as QueryTransformerContract, o as QueryConditionContract } from '../../index-CjurLJdK.js';
2
+ import { Column } from '../../column/index.js';
3
+ import { AcceptedOperator } from '../constants.js';
4
+ import 'bun';
5
+ import '../../types.js';
6
+ import '../../column/constants.js';
7
+ import '../../table/constants.js';
8
+ import '../../column/types.js';
9
+
10
+ declare function whereNot<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, "where"> & {
11
+ where: string[];
12
+ }, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>, QueryTransformerContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
13
+ where: string[];
14
+ }, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>, QueryConditionContract<Alias, TableRef, JoinedTables, Omit<Definition, "where"> & {
15
+ where: string[];
16
+ }, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>>;
17
+ declare function havingNot<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"> & {
18
+ having: string[];
19
+ }, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>, QueryTransformerContract<Alias, TableRef, JoinedTables, Omit<Definition, "having"> & {
20
+ having: string[];
21
+ }, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>, QueryConditionContract<Alias, TableRef, JoinedTables, Omit<Definition, "having"> & {
22
+ having: string[];
23
+ }, ColumnSelector<Alias, TableRef, JoinedTables>, StrictColumnSelector<Alias, TableRef, JoinedTables>>>;
24
+ declare function orNot<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, "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
+ 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, Definition, AllowedColumn, StrictAllowedColumn, QueryTransformerContract<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, QueryConditionContract<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>>;
32
+ 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, Definition, AllowedColumn, StrictAllowedColumn, QueryTransformerContract<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, QueryConditionContract<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>>;
33
+
34
+ export { havingNot, orNot, orNotGroup, whereNot, whereNotGroup };
@@ -0,0 +1,46 @@
1
+ import '../index.js';
2
+ import { ConditionClause, LogicalOperator } from '../constants.js';
3
+ import { addCondition, addGroupCondition } from './core.js';
4
+
5
+ // src/query/condition/not.ts
6
+ function whereNot(column, operator, value) {
7
+ return addCondition(
8
+ this,
9
+ ConditionClause.WHERE,
10
+ column,
11
+ operator,
12
+ value || null,
13
+ LogicalOperator.AND,
14
+ true
15
+ );
16
+ }
17
+ function havingNot(column, operator, value) {
18
+ return addCondition(
19
+ this,
20
+ ConditionClause.HAVING,
21
+ column,
22
+ operator,
23
+ value,
24
+ LogicalOperator.AND,
25
+ true
26
+ );
27
+ }
28
+ function orNot(column, operator, value) {
29
+ return addCondition(
30
+ this,
31
+ ConditionClause.WHERE,
32
+ column,
33
+ operator,
34
+ value || null,
35
+ LogicalOperator.OR,
36
+ true
37
+ );
38
+ }
39
+ function whereNotGroup(callback) {
40
+ return addGroupCondition(this, LogicalOperator.AND, callback, true);
41
+ }
42
+ function orNotGroup(callback) {
43
+ return addGroupCondition(this, LogicalOperator.OR, callback, true);
44
+ }
45
+
46
+ export { havingNot, orNot, orNotGroup, whereNot, whereNotGroup };
@@ -0,0 +1,8 @@
1
+ export { c as addRawCondition, e as rawHaving, d as rawOr, r as rawWhere } from '../../index-CjurLJdK.js';
2
+ import '../../column/index.js';
3
+ import '../constants.js';
4
+ import 'bun';
5
+ import '../../types.js';
6
+ import '../../column/constants.js';
7
+ import '../../table/constants.js';
8
+ import '../../column/types.js';
@@ -0,0 +1,50 @@
1
+ import { LogicalOperator, ConditionClause } from '../constants.js';
2
+ import { rawCol } from '../helper.js';
3
+
4
+ // src/query/condition/raw.ts
5
+ function addRawCondition(query, clause, column, logical, params) {
6
+ const validClause = clause.toLowerCase();
7
+ if (!query.definition[validClause]) query.definition[validClause] = [];
8
+ const condition = column(rawCol);
9
+ const logicalPrefix = query.definition[validClause].length > 0 ? logical : "";
10
+ query.definition[validClause].push(`${logicalPrefix} ${condition}`.trim());
11
+ if (!query.definition.params) query.definition.params = [];
12
+ if (typeof params === "undefined") {
13
+ return query;
14
+ }
15
+ if (Array.isArray(params)) {
16
+ query.definition.params.push(...params);
17
+ } else {
18
+ query.definition.params.push(params);
19
+ }
20
+ return query;
21
+ }
22
+ function rawWhere(column, params) {
23
+ return addRawCondition(
24
+ this,
25
+ ConditionClause.WHERE,
26
+ column,
27
+ LogicalOperator.AND,
28
+ params
29
+ );
30
+ }
31
+ function rawOr(column, params) {
32
+ return addRawCondition(
33
+ this,
34
+ ConditionClause.WHERE,
35
+ column,
36
+ LogicalOperator.OR,
37
+ params
38
+ );
39
+ }
40
+ function rawHaving(column, params) {
41
+ return addRawCondition(
42
+ this,
43
+ ConditionClause.HAVING,
44
+ column,
45
+ LogicalOperator.AND,
46
+ params
47
+ );
48
+ }
49
+
50
+ export { addRawCondition, rawHaving, rawOr, rawWhere };
@@ -1,6 +1,7 @@
1
1
  declare const LogicalOperator: {
2
2
  readonly AND: "AND";
3
3
  readonly OR: "OR";
4
+ readonly ON: "ON";
4
5
  };
5
6
  type LogicalOperator = (typeof LogicalOperator)[keyof typeof LogicalOperator];
6
7
  declare const ConditionClause: {
@@ -25,6 +26,12 @@ declare const AcceptedOperator: {
25
26
  readonly IS_NOT_NULL: "isNotNull";
26
27
  readonly BETWEEN: "between";
27
28
  readonly NOT_BETWEEN: "notBetween";
29
+ readonly STARTS_WITH: "startsWith";
30
+ readonly ENDS_WITH: "endsWith";
31
+ readonly REG_EXP: "regExp";
32
+ readonly NOT_REG_EXP: "notRegExp";
33
+ readonly RLIKE: "rlike";
34
+ readonly NOT_RLIKE: "notRlike";
28
35
  };
29
36
  type AcceptedOperator = (typeof AcceptedOperator)[keyof typeof AcceptedOperator];
30
37
  declare const QueryType: {
@@ -51,6 +58,8 @@ declare const AcceptedJoin: {
51
58
  readonly INNER: "INNER";
52
59
  readonly LEFT: "LEFT";
53
60
  readonly RIGHT: "RIGHT";
61
+ readonly FULL: "FULL OUTER";
62
+ readonly CROSS: "CROSS";
54
63
  readonly NATURAL: "NATURAL";
55
64
  };
56
65
  type AcceptedJoin = (typeof AcceptedJoin)[keyof typeof AcceptedJoin];
@@ -59,5 +68,22 @@ declare const QueryHooksType: {
59
68
  readonly BEFORE: "before";
60
69
  };
61
70
  type QueryHooksType = (typeof QueryHooksType)[keyof typeof QueryHooksType];
71
+ declare const ExplainFormat: {
72
+ readonly JSON: "JSON";
73
+ readonly TEXT: "TEXT";
74
+ readonly YAML: "YAML";
75
+ readonly XML: "XML";
76
+ };
77
+ type ExplainFormat = (typeof ExplainFormat)[keyof typeof ExplainFormat];
78
+ declare const ExplainClause: {
79
+ readonly FORMAT: "FORMAT";
80
+ readonly ANALYZE: "ANALYZE";
81
+ readonly VERBOSE: "VERBOSE";
82
+ readonly COSTS: "COSTS";
83
+ readonly BUFFERS: "BUFFERS";
84
+ readonly SUMMARY: "SUMMARY";
85
+ readonly TIMING: "TIMING";
86
+ };
87
+ type ExplainClause = (typeof ExplainClause)[keyof typeof ExplainClause];
62
88
 
63
- export { AcceptedJoin, AcceptedOperator, AggregationFunction, ConditionClause, LogicalOperator, OrderBy, QueryHooksType, QueryType };
89
+ export { AcceptedJoin, AcceptedOperator, AggregationFunction, ConditionClause, ExplainClause, ExplainFormat, LogicalOperator, OrderBy, QueryHooksType, QueryType };
@@ -1,7 +1,8 @@
1
1
  // src/query/constants.ts
2
2
  var LogicalOperator = {
3
3
  AND: "AND",
4
- OR: "OR"
4
+ OR: "OR",
5
+ ON: "ON"
5
6
  };
6
7
  var ConditionClause = {
7
8
  WHERE: "WHERE",
@@ -23,7 +24,13 @@ var AcceptedOperator = {
23
24
  IS_NULL: "isNull",
24
25
  IS_NOT_NULL: "isNotNull",
25
26
  BETWEEN: "between",
26
- NOT_BETWEEN: "notBetween"
27
+ NOT_BETWEEN: "notBetween",
28
+ STARTS_WITH: "startsWith",
29
+ ENDS_WITH: "endsWith",
30
+ REG_EXP: "regExp",
31
+ NOT_REG_EXP: "notRegExp",
32
+ RLIKE: "rlike",
33
+ NOT_RLIKE: "notRlike"
27
34
  };
28
35
  var QueryType = {
29
36
  SELECT: "SELECT",
@@ -46,11 +53,28 @@ var AcceptedJoin = {
46
53
  INNER: "INNER",
47
54
  LEFT: "LEFT",
48
55
  RIGHT: "RIGHT",
56
+ FULL: "FULL OUTER",
57
+ CROSS: "CROSS",
49
58
  NATURAL: "NATURAL"
50
59
  };
51
60
  var QueryHooksType = {
52
61
  AFTER: "after",
53
62
  BEFORE: "before"
54
63
  };
64
+ var ExplainFormat = {
65
+ JSON: "JSON",
66
+ TEXT: "TEXT",
67
+ YAML: "YAML",
68
+ XML: "XML"
69
+ };
70
+ var ExplainClause = {
71
+ FORMAT: "FORMAT",
72
+ ANALYZE: "ANALYZE",
73
+ VERBOSE: "VERBOSE",
74
+ COSTS: "COSTS",
75
+ BUFFERS: "BUFFERS",
76
+ SUMMARY: "SUMMARY",
77
+ TIMING: "TIMING"
78
+ };
55
79
 
56
- export { AcceptedJoin, AcceptedOperator, AggregationFunction, ConditionClause, LogicalOperator, OrderBy, QueryHooksType, QueryType };
80
+ export { AcceptedJoin, AcceptedOperator, AggregationFunction, ConditionClause, ExplainClause, ExplainFormat, LogicalOperator, OrderBy, QueryHooksType, QueryType };
@@ -1,8 +1,8 @@
1
1
  import 'bun';
2
- export { Y as QueryConditionContract, X as QueryTransformerContract } from '../index-BdpoD4zk.js';
2
+ export { o as QueryConditionContract, n as QueryTransformerContract } from '../index-CjurLJdK.js';
3
3
  import '../column/index.js';
4
4
  import '../table/constants.js';
5
5
  import './constants.js';
6
- import '../column/constants.js';
7
6
  import '../types.js';
7
+ import '../column/constants.js';
8
8
  import '../column/types.js';
@@ -0,0 +1,12 @@
1
+ import { T as Table, Q as QueryDefinition, C as ColumnSelector, k as StrictColumnSelector, l as QueryBuilder, E as ExplainOptions } from '../index-CjurLJdK.js';
2
+ import { Column } from '../column/index.js';
3
+ import 'bun';
4
+ import '../types.js';
5
+ import './constants.js';
6
+ import '../column/constants.js';
7
+ import '../table/constants.js';
8
+ import '../column/types.js';
9
+
10
+ declare function buildExplainQuery<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>>(q: QueryBuilder<Alias, TableRef, JoinedTables, Definition, AllowedColumn, StrictAllowedColumn>, options: Partial<ExplainOptions>): string;
11
+
12
+ export { buildExplainQuery };
@@ -0,0 +1,64 @@
1
+ import { Dialect } from '../table/constants.js';
2
+ import { ExplainClause } from './constants.js';
3
+
4
+ // src/query/explain.ts
5
+ function buildPostgresExplainQuery(options) {
6
+ const clauses = [];
7
+ if (options?.format) {
8
+ clauses.push(`${ExplainClause.FORMAT} ${options.format}`);
9
+ }
10
+ if (options?.analyze) {
11
+ clauses.push(ExplainClause.ANALYZE);
12
+ if (options?.summary != null) {
13
+ clauses.push(
14
+ `${ExplainClause.SUMMARY} ${options.summary ? "ON" : "OFF"}`
15
+ );
16
+ }
17
+ if (options?.timing != null)
18
+ clauses.push(`${ExplainClause.TIMING} ${options.timing ? "ON" : "OFF"}`);
19
+ }
20
+ if (options?.verbose) {
21
+ clauses.push(`${ExplainClause.VERBOSE} ${options.verbose ? "ON" : "OFF"}`);
22
+ }
23
+ if (options?.costs != null) {
24
+ clauses.push(`${ExplainClause.COSTS} ${options.costs ? "ON" : "OFF"}`);
25
+ }
26
+ if (options?.buffers != null) {
27
+ clauses.push(`${ExplainClause.BUFFERS} ${options.buffers ? "ON" : "OFF"}`);
28
+ }
29
+ if (clauses.length === 0) {
30
+ return "EXPLAIN ";
31
+ }
32
+ return `EXPLAIN (${clauses.join(", ")})`;
33
+ }
34
+ function buildMySqlExplainQuery(options) {
35
+ const clauses = [];
36
+ if (options.analyze) {
37
+ clauses.push(ExplainClause.ANALYZE);
38
+ }
39
+ if (options.format) {
40
+ clauses.push(`${ExplainClause.FORMAT}=${options.format}`);
41
+ }
42
+ if (clauses.length > 1) {
43
+ throw new Error("Only one explain clause is allowed");
44
+ }
45
+ return `EXPLAIN ${clauses.join(" ")}`;
46
+ }
47
+ function buildSqliteExplainQuery() {
48
+ const clauses = ["QUERY PLAN"];
49
+ return `EXPLAIN ${clauses.join(" ")}`;
50
+ }
51
+ function buildExplainQuery(q, options) {
52
+ switch (q.table.dialect) {
53
+ case Dialect.POSTGRES:
54
+ return buildPostgresExplainQuery(options);
55
+ case Dialect.MYSQL:
56
+ return buildMySqlExplainQuery(options);
57
+ case Dialect.SQLITE:
58
+ return buildSqliteExplainQuery();
59
+ default:
60
+ throw new Error(`Dialect ${q.table.dialect} is not supported`);
61
+ }
62
+ }
63
+
64
+ export { buildExplainQuery };
@@ -1,8 +1,8 @@
1
- export { H as aggregateCol, z as alias, B as clone, G as col, F as rawCol } from '../index-BdpoD4zk.js';
1
+ export { I as aggregateCol, B as alias, F as clone, H as col, G as rawCol } from '../index-CjurLJdK.js';
2
2
  import '../column/index.js';
3
3
  import './constants.js';
4
- import '../column/constants.js';
5
- import '../types.js';
6
4
  import 'bun';
5
+ import '../types.js';
6
+ import '../column/constants.js';
7
7
  import '../table/constants.js';
8
8
  import '../column/types.js';
@@ -1,5 +1,5 @@
1
1
  import { QueryBuilder } from './index.js';
2
- import { deepClone } from '../utilities.js';
2
+ import { cloneDefinition } from '../utilities.js';
3
3
 
4
4
  // src/query/helper.ts
5
5
  function alias(alias2) {
@@ -8,7 +8,7 @@ function alias(alias2) {
8
8
  }
9
9
  function clone() {
10
10
  const query = new QueryBuilder(this.table);
11
- Object.assign(query.definition, deepClone(this.definition));
11
+ Object.assign(query.definition, cloneDefinition(this.definition));
12
12
  return query;
13
13
  }
14
14
  function rawCol(column) {
@@ -1,8 +1,8 @@
1
1
  import '../column/index.js';
2
- export { f as QueryBuilder } from '../index-BdpoD4zk.js';
2
+ export { l as QueryBuilder } from '../index-CjurLJdK.js';
3
+ import '../types.js';
3
4
  import './constants.js';
4
5
  import '../table/constants.js';
5
6
  import '../column/constants.js';
6
7
  import '../column/types.js';
7
- import '../types.js';
8
8
  import 'bun';