@ignisia/sql 0.2.1 → 0.3.0

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