@ignisia/sql 0.2.2 → 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 (87) hide show
  1. package/dist/cjs/column/constants.d.cts +58 -5
  2. package/dist/cjs/column/constants.js +79 -22
  3. package/dist/cjs/column/index.d.cts +1 -0
  4. package/dist/cjs/column/index.js +30 -10
  5. package/dist/cjs/column/utils.d.cts +133 -0
  6. package/dist/cjs/column/utils.js +34 -0
  7. package/dist/cjs/database/alter.d.cts +3 -2
  8. package/dist/cjs/database/alter.js +15 -15
  9. package/dist/cjs/database/column.d.cts +3 -2
  10. package/dist/cjs/database/column.js +9 -7
  11. package/dist/cjs/database/contract.d.cts +3 -2
  12. package/dist/cjs/database/index.d.cts +3 -2
  13. package/dist/cjs/database/index.js +14 -1
  14. package/dist/cjs/database/table.d.cts +3 -2
  15. package/dist/cjs/database/table.js +12 -4
  16. package/dist/cjs/database/types.d.cts +2 -1
  17. package/dist/cjs/database/wrapper.d.cts +17 -21
  18. package/dist/cjs/database/wrapper.js +44 -52
  19. package/dist/cjs/{index---zaMa69.d.cts → index-2jl8MRfX.d.cts} +4 -2
  20. package/dist/cjs/{index-CwiFQh0I.d.cts → index-CnQVnCEI.d.cts} +80 -46
  21. package/dist/cjs/index.d.cts +3 -2
  22. package/dist/cjs/migration/index.d.cts +3 -2
  23. package/dist/cjs/migration/runner.js +1 -1
  24. package/dist/cjs/migration/type.d.cts +3 -2
  25. package/dist/cjs/query/builder.d.cts +2 -1
  26. package/dist/cjs/query/condition.d.cts +2 -1
  27. package/dist/cjs/query/condition.js +5 -2
  28. package/dist/cjs/query/contract.d.cts +3 -2
  29. package/dist/cjs/query/helper.d.cts +2 -1
  30. package/dist/cjs/query/index.d.cts +2 -1
  31. package/dist/cjs/query/index.js +16 -7
  32. package/dist/cjs/query/join.d.cts +2 -1
  33. package/dist/cjs/query/sql.d.cts +5 -4
  34. package/dist/cjs/query/sql.js +36 -8
  35. package/dist/cjs/query/types.d.cts +2 -1
  36. package/dist/cjs/query/utilities.d.cts +4 -1
  37. package/dist/cjs/query/utilities.js +15 -5
  38. package/dist/cjs/table/constants.d.cts +1 -0
  39. package/dist/cjs/table/constants.js +1 -0
  40. package/dist/cjs/table/index.d.cts +2 -1
  41. package/dist/cjs/table/index.js +29 -9
  42. package/dist/cjs/table/types.d.cts +2 -1
  43. package/dist/cjs/table/utilities.d.cts +2 -1
  44. package/dist/esm/column/constants.d.ts +58 -5
  45. package/dist/esm/column/constants.js +78 -23
  46. package/dist/esm/column/index.d.ts +1 -0
  47. package/dist/esm/column/index.js +30 -10
  48. package/dist/esm/column/utils.d.ts +133 -0
  49. package/dist/esm/column/utils.js +32 -0
  50. package/dist/esm/database/alter.d.ts +3 -2
  51. package/dist/esm/database/alter.js +15 -15
  52. package/dist/esm/database/column.d.ts +3 -2
  53. package/dist/esm/database/column.js +9 -7
  54. package/dist/esm/database/contract.d.ts +3 -2
  55. package/dist/esm/database/index.d.ts +3 -2
  56. package/dist/esm/database/index.js +15 -2
  57. package/dist/esm/database/table.d.ts +3 -2
  58. package/dist/esm/database/table.js +12 -4
  59. package/dist/esm/database/types.d.ts +2 -1
  60. package/dist/esm/database/wrapper.d.ts +17 -21
  61. package/dist/esm/database/wrapper.js +43 -53
  62. package/dist/esm/{index-DFrpzXEn.d.ts → index-BXOAxB_h.d.ts} +4 -2
  63. package/dist/esm/{index-FMT0YEO7.d.ts → index-BdpoD4zk.d.ts} +80 -46
  64. package/dist/esm/index.d.ts +3 -2
  65. package/dist/esm/migration/index.d.ts +3 -2
  66. package/dist/esm/migration/runner.js +1 -1
  67. package/dist/esm/migration/type.d.ts +3 -2
  68. package/dist/esm/query/builder.d.ts +2 -1
  69. package/dist/esm/query/condition.d.ts +2 -1
  70. package/dist/esm/query/condition.js +5 -2
  71. package/dist/esm/query/contract.d.ts +3 -2
  72. package/dist/esm/query/helper.d.ts +2 -1
  73. package/dist/esm/query/index.d.ts +2 -1
  74. package/dist/esm/query/index.js +16 -7
  75. package/dist/esm/query/join.d.ts +2 -1
  76. package/dist/esm/query/sql.d.ts +5 -4
  77. package/dist/esm/query/sql.js +36 -8
  78. package/dist/esm/query/types.d.ts +2 -1
  79. package/dist/esm/query/utilities.d.ts +4 -1
  80. package/dist/esm/query/utilities.js +15 -5
  81. package/dist/esm/table/constants.d.ts +1 -0
  82. package/dist/esm/table/constants.js +1 -0
  83. package/dist/esm/table/index.d.ts +2 -1
  84. package/dist/esm/table/index.js +29 -9
  85. package/dist/esm/table/types.d.ts +2 -1
  86. package/dist/esm/table/utilities.d.ts +2 -1
  87. package/package.json +1 -1
@@ -1,7 +1,8 @@
1
- export { H as addCondition, B as addRawCondition, K as having, J as or, G as rawHaving, F as rawOr, E as rawWhere, I as where } from '../index-CwiFQh0I.cjs';
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-CnQVnCEI.cjs';
2
2
  import '../column/index.cjs';
3
3
  import './constants.cjs';
4
4
  import '../column/constants.cjs';
5
5
  import '../types.cjs';
6
+ import 'bun';
6
7
  import '../table/constants.cjs';
7
8
  import '../column/types.cjs';
@@ -49,6 +49,9 @@ function rawHaving(column, params) {
49
49
  );
50
50
  }
51
51
  function addCondition(query, clause, column, operator, value, logical) {
52
+ if (!query.table.dialect) {
53
+ throw new Error("No DB Dialect defined");
54
+ }
52
55
  const validClause = clause.toLowerCase();
53
56
  const condition = utilities.getCondition(query.table.dialect, column, operator, value);
54
57
  if (!query.definition[validClause]) query.definition[validClause] = [];
@@ -71,7 +74,7 @@ function where(column, operator, value) {
71
74
  constants.ConditionClause.WHERE,
72
75
  column,
73
76
  operator,
74
- value,
77
+ value || null,
75
78
  constants.LogicalOperator.AND
76
79
  );
77
80
  }
@@ -81,7 +84,7 @@ function or(column, operator, value) {
81
84
  constants.ConditionClause.WHERE,
82
85
  column,
83
86
  operator,
84
- value,
87
+ value || null,
85
88
  constants.LogicalOperator.OR
86
89
  );
87
90
  }
@@ -1,7 +1,8 @@
1
- export { N as QueryConditionContract, L as QueryTransformerContract } from '../index-CwiFQh0I.cjs';
1
+ import 'bun';
2
+ export { Y as QueryConditionContract, X as QueryTransformerContract } from '../index-CnQVnCEI.cjs';
2
3
  import '../column/index.cjs';
4
+ import '../table/constants.cjs';
3
5
  import './constants.cjs';
4
6
  import '../column/constants.cjs';
5
7
  import '../types.cjs';
6
- import '../table/constants.cjs';
7
8
  import '../column/types.cjs';
@@ -1,7 +1,8 @@
1
- export { z as aggregateCol, v as alias, w as clone, y as col, x as rawCol } from '../index-CwiFQh0I.cjs';
1
+ export { H as aggregateCol, z as alias, B as clone, G as col, F as rawCol } from '../index-CnQVnCEI.cjs';
2
2
  import '../column/index.cjs';
3
3
  import './constants.cjs';
4
4
  import '../column/constants.cjs';
5
5
  import '../types.cjs';
6
+ import 'bun';
6
7
  import '../table/constants.cjs';
7
8
  import '../column/types.cjs';
@@ -1,7 +1,8 @@
1
1
  import '../column/index.cjs';
2
- export { d as QueryBuilder } from '../index-CwiFQh0I.cjs';
2
+ export { f as QueryBuilder } from '../index-CnQVnCEI.cjs';
3
3
  import './constants.cjs';
4
4
  import '../table/constants.cjs';
5
5
  import '../column/constants.cjs';
6
6
  import '../column/types.cjs';
7
7
  import '../types.cjs';
8
+ import 'bun';
@@ -154,22 +154,31 @@ class QueryBuilder {
154
154
  insert(...values) {
155
155
  this.definition.queryType = constants.QueryType.INSERT;
156
156
  if (!this.definition.insertValues) this.definition.insertValues = [];
157
- const { isWithTimestamp, createdAt, updatedAt, timestamp } = utilities$1.getTimestamp(
158
- this.table
159
- );
157
+ const {
158
+ isWithTimestamp,
159
+ isHasCreatedAt,
160
+ isHasUpdatedAt,
161
+ createdAt,
162
+ updatedAt,
163
+ timestamp
164
+ } = utilities$1.getTimestamp(this.table);
160
165
  if (isWithTimestamp) {
161
166
  values = values.map((row) => ({
162
167
  ...row,
163
- [createdAt]: row[createdAt] ?? timestamp,
164
- [updatedAt]: row[updatedAt] ?? timestamp
168
+ ...isHasCreatedAt && {
169
+ [createdAt]: row[createdAt] ?? timestamp
170
+ },
171
+ ...isHasUpdatedAt && {
172
+ [updatedAt]: row[updatedAt] ?? timestamp
173
+ }
165
174
  }));
166
175
  }
167
176
  this.definition.insertValues = values;
168
177
  return this;
169
178
  }
170
179
  update(values) {
171
- const { isWithTimestamp, updatedAt, timestamp } = utilities$1.getTimestamp(this.table);
172
- if (isWithTimestamp) {
180
+ const { isWithTimestamp, isHasUpdatedAt, updatedAt, timestamp } = utilities$1.getTimestamp(this.table);
181
+ if (isWithTimestamp && isHasUpdatedAt) {
173
182
  values = {
174
183
  ...values,
175
184
  [updatedAt]: values[updatedAt] ?? timestamp
@@ -1,8 +1,9 @@
1
- import { T as Table, Q as QueryDefinition, C as ColumnSelector, c as StrictColumnSelector, d as QueryBuilder } from '../index-CwiFQh0I.cjs';
1
+ import { T as Table, Q as QueryDefinition, C as ColumnSelector, e as StrictColumnSelector, f as QueryBuilder } from '../index-CnQVnCEI.cjs';
2
2
  import { Column } from '../column/index.cjs';
3
3
  import { AcceptedJoin } from './constants.cjs';
4
4
  import '../column/constants.cjs';
5
5
  import '../types.cjs';
6
+ import 'bun';
6
7
  import '../table/constants.cjs';
7
8
  import '../column/types.cjs';
8
9
 
@@ -1,17 +1,18 @@
1
- import { T as Table, Q as QueryDefinition, C as ColumnSelector, c as StrictColumnSelector, d as QueryBuilder } from '../index-CwiFQh0I.cjs';
1
+ import { TransactionSQL } from 'bun';
2
+ import { T as Table, Q as QueryDefinition, C as ColumnSelector, e as StrictColumnSelector, f as QueryBuilder } from '../index-CnQVnCEI.cjs';
2
3
  import { Column } from '../column/index.cjs';
4
+ import { Dialect } from '../table/constants.cjs';
3
5
  import '../column/constants.cjs';
4
6
  import '../types.cjs';
5
7
  import './constants.cjs';
6
- import '../table/constants.cjs';
7
8
  import '../column/types.cjs';
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,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var constants$1 = require('../table/constants');
3
4
  var builder = require('./builder');
4
5
  var constants = require('./constants');
5
6
  var utilities = require('./utilities');
@@ -11,7 +12,7 @@ function buildQuery(query) {
11
12
  return `$${index}`;
12
13
  });
13
14
  }
14
- function toQuery() {
15
+ function toQuery(dialect) {
15
16
  let sql = "";
16
17
  switch (this.definition.queryType) {
17
18
  case constants.QueryType.SELECT:
@@ -57,7 +58,9 @@ function toQuery() {
57
58
  this.definition.params.push(this.definition.offset);
58
59
  }
59
60
  if (this.definition.queryType === constants.QueryType.UPDATE || this.definition.queryType === constants.QueryType.DELETE) {
60
- sql += ` RETURNING *`;
61
+ if (dialect !== constants$1.Dialect.MYSQL) {
62
+ sql += ` RETURNING *`;
63
+ }
61
64
  }
62
65
  sql = buildQuery(sql);
63
66
  return { query: sql + ";", params: this.definition.params };
@@ -65,26 +68,51 @@ function toQuery() {
65
68
  function toString() {
66
69
  return this.toQuery().query;
67
70
  }
68
- async function exec() {
69
- if (!this.table.client) throw new Error("Database client not defined");
70
- const { query, params } = this.toQuery();
71
+ async function exec(tx) {
72
+ const client = this.table.client;
73
+ const dialect = this.table.dialect;
74
+ const queryType = this.definition.queryType;
75
+ const isUpdate = queryType === constants.QueryType.UPDATE;
76
+ const isDelete = queryType === constants.QueryType.DELETE;
77
+ const isReturning = isUpdate || isDelete;
78
+ const isMySQL = dialect === constants$1.Dialect.MYSQL;
79
+ if (!client) {
80
+ throw new Error("Database client not defined");
81
+ }
82
+ if (!queryType) {
83
+ throw new Error("No query type defined");
84
+ }
85
+ const { query, params } = this.toQuery(dialect);
71
86
  if (this.hooks?.before?.size) {
72
87
  for (const hook of this.hooks.before.values()) {
73
88
  hook({
74
89
  query,
75
90
  params,
76
- type: this.definition.queryType,
91
+ type: queryType,
77
92
  hook: constants.QueryHooksType.BEFORE
78
93
  });
79
94
  }
80
95
  }
81
- const result = await this.table.client.exec(query, params);
96
+ let result = await client.exec({
97
+ sql: query,
98
+ params,
99
+ tx
100
+ });
101
+ if (isMySQL && isReturning) {
102
+ const query2 = this.clone();
103
+ query2.definition.queryType = constants.QueryType.SELECT;
104
+ result = await client.exec({
105
+ sql: query2.toQuery().query,
106
+ params,
107
+ tx
108
+ });
109
+ }
82
110
  if (this.hooks?.after?.size) {
83
111
  for (const hook of this.hooks.after.values()) {
84
112
  hook({
85
113
  query,
86
114
  params,
87
- type: this.definition.queryType,
115
+ type: queryType,
88
116
  hook: constants.QueryHooksType.AFTER
89
117
  });
90
118
  }
@@ -1,7 +1,8 @@
1
1
  import '../column/index.cjs';
2
2
  import '../column/constants.cjs';
3
- export { j as AcceptedInsertValues, i as AcceptedOrderBy, k as AcceptedUpdateValues, l as AggregateColumn, A as AliasedColumn, C as ColumnSelector, f as QuerHooks, Q as QueryDefinition, n as QueryOutput, h as QueryRunHooks, o as QueryRunHooksOptions, R as RawColumn, m as SelectQueryOutput, e as SelectableColumn, c as StrictColumnSelector, W as WhereValue } from '../index-CwiFQh0I.cjs';
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-CnQVnCEI.cjs';
4
4
  import '../types.cjs';
5
5
  import './constants.cjs';
6
6
  import '../table/constants.cjs';
7
7
  import '../column/types.cjs';
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-CwiFQh0I.cjs';
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-CnQVnCEI.cjs';
2
2
  import { Column } from '../column/index.cjs';
3
3
  import { Dialect } from '../table/constants.cjs';
4
4
  import { AcceptedOperator } from './constants.cjs';
5
5
  import '../column/constants.cjs';
6
6
  import '../types.cjs';
7
+ import 'bun';
7
8
  import '../column/types.cjs';
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;
@@ -62,22 +62,32 @@ function getCondition(dialect, column, operator, value) {
62
62
  function getTimestamp(table) {
63
63
  const isWithTimestamp = !!table.timestamp;
64
64
  const timestamp = /* @__PURE__ */ new Date();
65
+ let isHasCreatedAt = true;
66
+ let isHasUpdatedAt = true;
65
67
  let createdAt = "createdAt";
66
68
  let updatedAt = "updatedAt";
67
69
  if (isWithTimestamp) {
68
70
  const isCustomTimestamp = typeof table.timestamp === "object";
69
- if (isCustomTimestamp && table.timestamp.createdAt) {
70
- createdAt = table.timestamp.createdAt;
71
+ if (isCustomTimestamp) {
72
+ if (typeof table.timestamp.createdAt === "string") {
73
+ createdAt = table.timestamp.createdAt;
74
+ }
75
+ isHasCreatedAt = table.timestamp.createdAt === false;
71
76
  }
72
- if (isCustomTimestamp && table.timestamp.updatedAt) {
73
- updatedAt = table.timestamp.updatedAt;
77
+ if (isCustomTimestamp) {
78
+ if (typeof table.timestamp.updatedAt === "string") {
79
+ updatedAt = table.timestamp.updatedAt;
80
+ }
81
+ isHasUpdatedAt = table.timestamp.updatedAt === false;
74
82
  }
75
83
  }
76
84
  return {
77
85
  isWithTimestamp,
78
86
  timestamp,
79
87
  createdAt,
80
- updatedAt
88
+ updatedAt,
89
+ isHasUpdatedAt,
90
+ isHasCreatedAt
81
91
  };
82
92
  }
83
93
  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];
@@ -2,6 +2,7 @@
2
2
 
3
3
  const Dialect = {
4
4
  POSTGRES: "postgres",
5
+ MYSQL: "mysql",
5
6
  SQLITE: "sqlite"
6
7
  };
7
8
 
@@ -1,7 +1,8 @@
1
- export { T as Table } from '../index-CwiFQh0I.cjs';
1
+ export { T as Table } from '../index-CnQVnCEI.cjs';
2
2
  import '../column/index.cjs';
3
3
  import './constants.cjs';
4
4
  import '../column/constants.cjs';
5
5
  import '../types.cjs';
6
6
  import '../query/constants.cjs';
7
+ import 'bun';
7
8
  import '../column/types.cjs';
@@ -5,22 +5,21 @@ var utilities = require('./utilities');
5
5
 
6
6
  class Table {
7
7
  client;
8
- dialect;
8
+ _dialect;
9
9
  name;
10
10
  columns;
11
11
  timestamp;
12
12
  paranoid;
13
13
  _output;
14
14
  constructor(options) {
15
- this.dialect = options.dialect;
15
+ this._dialect = options.dialect || null;
16
16
  this.name = options.name;
17
17
  this.columns = options.columns;
18
18
  this.paranoid = options.paranoid || null;
19
19
  this.timestamp = options.timestamp || null;
20
20
  this.client = null;
21
- for (const column of Object.values(this.columns)) {
22
- column.dialect(options.dialect);
23
- }
21
+ if (!this._dialect) return;
22
+ this.setColumnDialect(this._dialect);
24
23
  }
25
24
  infer() {
26
25
  return null;
@@ -32,18 +31,39 @@ class Table {
32
31
  columns
33
32
  });
34
33
  }
35
- async create(db = this.client) {
34
+ setColumnDialect(dialect) {
35
+ for (const column of Object.values(this.columns)) {
36
+ column.dialect(dialect);
37
+ }
38
+ }
39
+ get dialect() {
40
+ return this._dialect;
41
+ }
42
+ setDialect(dialect) {
43
+ this._dialect = dialect;
44
+ this.setColumnDialect(dialect);
45
+ return this;
46
+ }
47
+ async create(options = {}) {
48
+ const db = options.db || this.client;
36
49
  if (!db) throw new Error("Database client not defined");
37
50
  const sql = `CREATE TABLE IF NOT EXISTS ${this.name} (${Object.entries(
38
51
  this.columns
39
52
  ).map(([name, column]) => `${name} ${column.toQuery().query}`).join(", ")});`;
40
- await db.exec(sql);
53
+ await db.exec({
54
+ sql,
55
+ tx: options.tx
56
+ });
41
57
  return this;
42
58
  }
43
- async drop(db = this.client) {
59
+ async drop(options = {}) {
60
+ const db = options.db || this.client;
44
61
  if (!db) throw new Error("Database client not defined");
45
62
  const sql = `DROP TABLE IF EXISTS ${this.name};`;
46
- await db.exec(sql);
63
+ await db.exec({
64
+ sql,
65
+ tx: options.tx
66
+ });
47
67
  return this;
48
68
  }
49
69
  query() {
@@ -1,4 +1,5 @@
1
- export { M as MergeTimestampParanoid, s as TableOptions, t as TableOutput, a as TimestampOptions } from '../index-CwiFQh0I.cjs';
1
+ import 'bun';
2
+ export { E as ExecOptions, M as MergeTimestampParanoid, x as TableOptions, y as TableOutput, a as TimestampOptions } from '../index-CnQVnCEI.cjs';
2
3
  import '../column/index.cjs';
3
4
  import './constants.cjs';
4
5
  import '../column/constants.cjs';
@@ -1,7 +1,8 @@
1
1
  import '../column/constants.cjs';
2
2
  import '../column/index.cjs';
3
3
  import './constants.cjs';
4
- export { p as createdAt, r as defineColumns, q as deletedAt, u as updatedAt } from '../index-CwiFQh0I.cjs';
4
+ export { t as createdAt, w as defineColumns, v as deletedAt, u as updatedAt } from '../index-CnQVnCEI.cjs';
5
5
  import '../column/types.cjs';
6
6
  import '../types.cjs';
7
7
  import '../query/constants.cjs';
8
+ import 'bun';
@@ -23,75 +23,128 @@ declare const ColumnTypeMapping: {
23
23
  readonly INTEGER: {
24
24
  readonly sqlite: "INTEGER";
25
25
  readonly postgres: "INTEGER";
26
+ readonly mysql: "INT";
26
27
  };
27
28
  readonly STRING: {
28
29
  readonly sqlite: "TEXT";
29
30
  readonly postgres: "VARCHAR";
31
+ readonly mysql: "VARCHAR";
30
32
  };
31
33
  readonly BOOLEAN: {
32
34
  readonly sqlite: "INTEGER";
33
35
  readonly postgres: "BOOLEAN";
36
+ readonly mysql: "TINYINT";
34
37
  };
35
38
  readonly DATE: {
36
39
  readonly sqlite: "TEXT";
37
40
  readonly postgres: "DATE";
41
+ readonly mysql: "DATE";
38
42
  };
39
43
  readonly FLOAT: {
40
44
  readonly sqlite: "REAL";
41
45
  readonly postgres: "FLOAT";
46
+ readonly mysql: "FLOAT PRECISION";
42
47
  };
43
48
  readonly DECIMAL: {
44
- readonly sqlite: "TEXT";
49
+ readonly sqlite: "NUMERIC";
45
50
  readonly postgres: "DECIMAL";
51
+ readonly mysql: "DECIMAL";
46
52
  };
47
53
  readonly BIGINT: {
48
- readonly sqlite: "TEXT";
54
+ readonly sqlite: "INTEGER";
49
55
  readonly postgres: "BIGINT";
56
+ readonly mysql: "BIGINT";
50
57
  };
51
58
  readonly TEXT: {
52
59
  readonly sqlite: "TEXT";
53
60
  readonly postgres: "TEXT";
61
+ readonly mysql: "TEXT";
54
62
  };
55
63
  readonly BLOB: {
56
64
  readonly sqlite: "BLOB";
57
65
  readonly postgres: "BYTEA";
66
+ readonly mysql: "BLOB";
58
67
  };
59
68
  readonly JSON: {
60
69
  readonly sqlite: "TEXT";
61
70
  readonly postgres: "JSONB";
71
+ readonly mysql: "JSON";
62
72
  };
63
73
  readonly VARCHAR: {
64
- readonly sqlite: "TEXT";
74
+ readonly sqlite: "VARCHAR";
65
75
  readonly postgres: "VARCHAR";
76
+ readonly mysql: "VARCHAR";
66
77
  };
67
78
  readonly TIME: {
68
79
  readonly sqlite: "TEXT";
69
80
  readonly postgres: "TIME";
81
+ readonly mysql: "TIME";
70
82
  };
71
83
  readonly TIMESTAMP: {
72
84
  readonly sqlite: "TEXT";
73
85
  readonly postgres: "TIMESTAMP";
86
+ readonly mysql: "DATETIME";
74
87
  };
75
88
  readonly DOUBLE: {
76
89
  readonly sqlite: "REAL";
77
90
  readonly postgres: "DOUBLE PRECISION";
91
+ readonly mysql: "DOUBLE PRECISION";
78
92
  };
79
93
  readonly DATETIME: {
80
94
  readonly sqlite: "TEXT";
81
95
  readonly postgres: "TIMESTAMP";
96
+ readonly mysql: "DATETIME";
82
97
  };
83
98
  readonly DATEONLY: {
84
99
  readonly sqlite: "TEXT";
85
100
  readonly postgres: "DATE";
101
+ readonly mysql: "DATE";
86
102
  };
87
103
  readonly ENUM: {
88
104
  readonly sqlite: "TEXT";
89
105
  readonly postgres: "TEXT";
106
+ readonly mysql: "TEXT";
90
107
  };
91
108
  readonly SERIAL: {
92
- readonly sqlite: "INTEGER AUTOINCREMENT";
109
+ readonly sqlite: "INTEGER";
93
110
  readonly postgres: "SERIAL";
111
+ readonly mysql: "INT";
112
+ };
113
+ };
114
+ declare const ColumnProperties: {
115
+ readonly NOT_NULL: "NOT_NULL";
116
+ readonly UNIQUE: "UNIQUE";
117
+ readonly DEFAULT: "DEFAULT";
118
+ readonly AUTO_INCREMENT: "AUTO_INCREMENT";
119
+ readonly PRIMARY_KEY: "PRIMARY_KEY";
120
+ };
121
+ type ColumnProperties = (typeof ColumnProperties)[keyof typeof ColumnProperties];
122
+ declare const ColumnPropertyMapping: {
123
+ NOT_NULL: {
124
+ sqlite: string;
125
+ postgres: string;
126
+ mysql: string;
127
+ };
128
+ UNIQUE: {
129
+ sqlite: string;
130
+ postgres: string;
131
+ mysql: string;
132
+ };
133
+ DEFAULT: {
134
+ sqlite: string;
135
+ postgres: string;
136
+ mysql: string;
137
+ };
138
+ AUTO_INCREMENT: {
139
+ sqlite: string;
140
+ postgres: string;
141
+ mysql: string;
142
+ };
143
+ PRIMARY_KEY: {
144
+ sqlite: string;
145
+ postgres: string;
146
+ mysql: string;
94
147
  };
95
148
  };
96
149
 
97
- export { AcceptedColumnTypes, ColumnTypeMapping };
150
+ export { AcceptedColumnTypes, ColumnProperties, ColumnPropertyMapping, ColumnTypeMapping };