@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
@@ -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 };
@@ -0,0 +1,154 @@
1
+ import { Dialect } from '../table/constants.js';
2
+
3
+ // src/column/constants.ts
4
+ var AcceptedColumnTypes = {
5
+ INTEGER: "INTEGER",
6
+ STRING: "STRING",
7
+ BOOLEAN: "BOOLEAN",
8
+ DATE: "DATE",
9
+ FLOAT: "FLOAT",
10
+ DECIMAL: "DECIMAL",
11
+ BIGINT: "BIGINT",
12
+ TEXT: "TEXT",
13
+ BLOB: "BLOB",
14
+ JSON: "JSON",
15
+ VARCHAR: "VARCHAR",
16
+ TIME: "TIME",
17
+ TIMESTAMP: "TIMESTAMP",
18
+ DOUBLE: "DOUBLE",
19
+ DATETIME: "DATETIME",
20
+ DATEONLY: "DATEONLY",
21
+ ENUM: "ENUM",
22
+ SERIAL: "SERIAL"
23
+ };
24
+ var ColumnTypeMapping = {
25
+ [AcceptedColumnTypes.INTEGER]: {
26
+ [Dialect.SQLITE]: "INTEGER",
27
+ [Dialect.POSTGRES]: "INTEGER",
28
+ [Dialect.MYSQL]: "INT"
29
+ },
30
+ [AcceptedColumnTypes.STRING]: {
31
+ [Dialect.SQLITE]: "TEXT",
32
+ [Dialect.POSTGRES]: "VARCHAR",
33
+ [Dialect.MYSQL]: "VARCHAR"
34
+ },
35
+ [AcceptedColumnTypes.BOOLEAN]: {
36
+ [Dialect.SQLITE]: "INTEGER",
37
+ [Dialect.POSTGRES]: "BOOLEAN",
38
+ [Dialect.MYSQL]: "TINYINT"
39
+ },
40
+ [AcceptedColumnTypes.DATE]: {
41
+ [Dialect.SQLITE]: "TEXT",
42
+ [Dialect.POSTGRES]: "DATE",
43
+ [Dialect.MYSQL]: "DATE"
44
+ },
45
+ [AcceptedColumnTypes.FLOAT]: {
46
+ [Dialect.SQLITE]: "REAL",
47
+ [Dialect.POSTGRES]: "FLOAT",
48
+ [Dialect.MYSQL]: "FLOAT PRECISION"
49
+ },
50
+ [AcceptedColumnTypes.DECIMAL]: {
51
+ [Dialect.SQLITE]: "NUMERIC",
52
+ [Dialect.POSTGRES]: "DECIMAL",
53
+ [Dialect.MYSQL]: "DECIMAL"
54
+ },
55
+ [AcceptedColumnTypes.BIGINT]: {
56
+ [Dialect.SQLITE]: "INTEGER",
57
+ [Dialect.POSTGRES]: "BIGINT",
58
+ [Dialect.MYSQL]: "BIGINT"
59
+ },
60
+ [AcceptedColumnTypes.TEXT]: {
61
+ [Dialect.SQLITE]: "TEXT",
62
+ [Dialect.POSTGRES]: "TEXT",
63
+ [Dialect.MYSQL]: "TEXT"
64
+ },
65
+ [AcceptedColumnTypes.BLOB]: {
66
+ [Dialect.SQLITE]: "BLOB",
67
+ [Dialect.POSTGRES]: "BYTEA",
68
+ [Dialect.MYSQL]: "BLOB"
69
+ },
70
+ [AcceptedColumnTypes.JSON]: {
71
+ [Dialect.SQLITE]: "TEXT",
72
+ [Dialect.POSTGRES]: "JSONB",
73
+ [Dialect.MYSQL]: "JSON"
74
+ },
75
+ [AcceptedColumnTypes.VARCHAR]: {
76
+ [Dialect.SQLITE]: "VARCHAR",
77
+ [Dialect.POSTGRES]: "VARCHAR",
78
+ [Dialect.MYSQL]: "VARCHAR"
79
+ },
80
+ [AcceptedColumnTypes.TIME]: {
81
+ [Dialect.SQLITE]: "TEXT",
82
+ [Dialect.POSTGRES]: "TIME",
83
+ [Dialect.MYSQL]: "TIME"
84
+ },
85
+ [AcceptedColumnTypes.TIMESTAMP]: {
86
+ [Dialect.SQLITE]: "TEXT",
87
+ [Dialect.POSTGRES]: "TIMESTAMP",
88
+ [Dialect.MYSQL]: "DATETIME"
89
+ },
90
+ [AcceptedColumnTypes.DOUBLE]: {
91
+ [Dialect.SQLITE]: "REAL",
92
+ [Dialect.POSTGRES]: "DOUBLE PRECISION",
93
+ [Dialect.MYSQL]: "DOUBLE PRECISION"
94
+ },
95
+ [AcceptedColumnTypes.DATETIME]: {
96
+ [Dialect.SQLITE]: "TEXT",
97
+ [Dialect.POSTGRES]: "TIMESTAMP",
98
+ [Dialect.MYSQL]: "DATETIME"
99
+ },
100
+ [AcceptedColumnTypes.DATEONLY]: {
101
+ [Dialect.SQLITE]: "TEXT",
102
+ [Dialect.POSTGRES]: "DATE",
103
+ [Dialect.MYSQL]: "DATE"
104
+ },
105
+ [AcceptedColumnTypes.ENUM]: {
106
+ [Dialect.SQLITE]: "TEXT",
107
+ [Dialect.POSTGRES]: "TEXT",
108
+ [Dialect.MYSQL]: "TEXT"
109
+ },
110
+ [AcceptedColumnTypes.SERIAL]: {
111
+ [Dialect.SQLITE]: "INTEGER",
112
+ [Dialect.POSTGRES]: "SERIAL",
113
+ [Dialect.MYSQL]: "INT"
114
+ }
115
+ };
116
+ var ColumnProperties = {
117
+ NOT_NULL: "NOT_NULL",
118
+ UNIQUE: "UNIQUE",
119
+ DEFAULT: "DEFAULT",
120
+ AUTO_INCREMENT: "AUTO_INCREMENT",
121
+ PRIMARY_KEY: "PRIMARY_KEY"
122
+ };
123
+ var ColumnPropertyMapping = {
124
+ [ColumnProperties.NOT_NULL]: {
125
+ [Dialect.SQLITE]: "NOT NULL",
126
+ [Dialect.POSTGRES]: "NOT NULL",
127
+ [Dialect.MYSQL]: "NOT NULL"
128
+ },
129
+ [ColumnProperties.UNIQUE]: {
130
+ [Dialect.SQLITE]: "UNIQUE",
131
+ [Dialect.POSTGRES]: "UNIQUE",
132
+ [Dialect.MYSQL]: "UNIQUE"
133
+ },
134
+ [ColumnProperties.DEFAULT]: {
135
+ [Dialect.SQLITE]: "DEFAULT",
136
+ [Dialect.POSTGRES]: "DEFAULT",
137
+ [Dialect.MYSQL]: "DEFAULT"
138
+ },
139
+ [ColumnProperties.AUTO_INCREMENT]: {
140
+ // sqlite does not support AUTOINCREMENT
141
+ [Dialect.SQLITE]: "AUTOINCREMENT",
142
+ // postgres does not support AUTOINCREMENT
143
+ [Dialect.POSTGRES]: "AUTOINCREMENT",
144
+ // Exists only for mysql since mysql supports AUTOINCREMENT
145
+ [Dialect.MYSQL]: "AUTO_INCREMENT"
146
+ },
147
+ [ColumnProperties.PRIMARY_KEY]: {
148
+ [Dialect.SQLITE]: "PRIMARY KEY",
149
+ [Dialect.POSTGRES]: "PRIMARY KEY",
150
+ [Dialect.MYSQL]: "PRIMARY KEY"
151
+ }
152
+ };
153
+
154
+ export { AcceptedColumnTypes, ColumnProperties, ColumnPropertyMapping, ColumnTypeMapping };
@@ -31,6 +31,7 @@ declare class Column<Type extends AcceptedColumnTypes = AcceptedColumnTypes, Val
31
31
  dialect<DbDialect extends Dialect>(dialect: DbDialect): Column<Type, Values, Options, ColumnValue, Value, Definition & {
32
32
  dialect: DbDialect;
33
33
  }>;
34
+ clone(): Column<Type, Values, Options, ColumnValue, Value, {}>;
34
35
  toQuery(): {
35
36
  query: string;
36
37
  params: never[];
@@ -1,7 +1,10 @@
1
- import { Dialect } from '../table/constants';
2
- import { ColumnTypeMapping, AcceptedColumnTypes } from './constants';
1
+ import { Dialect } from '../table/constants.js';
2
+ import { deepClone } from '../utilities.js';
3
+ import { ColumnTypeMapping, AcceptedColumnTypes } from './constants.js';
4
+ import { columnProperty } from './utils.js';
3
5
 
4
- class Column {
6
+ // src/column/index.ts
7
+ var Column = class _Column {
5
8
  definition;
6
9
  type;
7
10
  length;
@@ -27,7 +30,7 @@ class Column {
27
30
  };
28
31
  }
29
32
  static define(options) {
30
- return new Column(options);
33
+ return new _Column(options);
31
34
  }
32
35
  autoIncrement() {
33
36
  this.definition.autoIncrement = true;
@@ -57,40 +60,58 @@ class Column {
57
60
  this.definition.dialect = dialect;
58
61
  return this;
59
62
  }
63
+ clone() {
64
+ const column = new _Column({
65
+ type: this.type,
66
+ ...this.length && { length: this.length },
67
+ ...this.enums.length && { values: this.enums }
68
+ });
69
+ Object.assign(column.definition, deepClone(this.definition));
70
+ return column;
71
+ }
60
72
  toQuery() {
61
73
  if (!this.definition.dialect) {
62
74
  throw new Error("No DB Dialect defined");
63
75
  }
64
- const correctType = ColumnTypeMapping[this.type][this.definition.dialect];
65
- let sql = correctType + (this.length ? `(${this.length})` : "");
76
+ const type = ColumnTypeMapping[this.type][this.definition.dialect];
77
+ const properties = columnProperty(this.definition.dialect);
78
+ let sql = type + (this.length ? `(${this.length})` : "");
66
79
  if (this.definition.primaryKey) {
67
- sql += " PRIMARY KEY";
80
+ sql += ` ${properties.PRIMARY_KEY}`;
68
81
  }
69
82
  if (this.definition.autoIncrement || this.type === AcceptedColumnTypes.SERIAL) {
70
83
  const isPrimaryKey = !!this.definition.primaryKey;
84
+ const sqls = [];
71
85
  if (this.definition.dialect === Dialect.POSTGRES) {
72
- sql = `SERIAL${isPrimaryKey ? " PRIMARY KEY" : ""}`;
86
+ sqls.push(type);
87
+ if (isPrimaryKey) {
88
+ sqls.push(properties.PRIMARY_KEY);
89
+ }
90
+ sql = sqls.join(" ");
73
91
  } else {
74
92
  if (this.type !== AcceptedColumnTypes.SERIAL) {
75
- sql += " AUTOINCREMENT";
93
+ sql += ` ${properties.AUTO_INCREMENT}`;
76
94
  } else {
77
- const sqls = ["INTEGER", "PRIMARY KEY", "AUTOINCREMENT"];
78
- if (!isPrimaryKey) sqls.splice(1, 1);
95
+ sqls.push(type);
96
+ if (isPrimaryKey) {
97
+ sqls.push(properties.PRIMARY_KEY);
98
+ }
99
+ sqls.push(properties.AUTO_INCREMENT);
79
100
  sql = sqls.join(" ");
80
101
  }
81
102
  }
82
103
  }
83
104
  if (this.definition.notNull) {
84
- sql += " NOT NULL";
105
+ sql += ` ${properties.NOT_NULL}`;
85
106
  }
86
107
  if (this.definition.unique) {
87
- sql += " UNIQUE";
108
+ sql += ` ${properties.UNIQUE}`;
88
109
  }
89
110
  if (this.definition.default !== void 0) {
90
111
  const value = this.definition.default;
91
112
  const isString = typeof this.definition.default === "string";
92
113
  const finalValue = isString ? `'${value}'` : value;
93
- sql += ` DEFAULT ${finalValue}`;
114
+ sql += ` ${properties.DEFAULT} ${finalValue}`;
94
115
  }
95
116
  return { query: sql, params: [] };
96
117
  }
@@ -100,6 +121,6 @@ class Column {
100
121
  infer() {
101
122
  return null;
102
123
  }
103
- }
124
+ };
104
125
 
105
126
  export { Column };
@@ -0,0 +1 @@
1
+ import './constants.js';
@@ -0,0 +1,133 @@
1
+ import { Dialect } from '../table/constants.js';
2
+ import { ColumnProperties } from './constants.js';
3
+
4
+ declare function getColumnProperty<DbDialect extends Dialect>(dialect: DbDialect, property: ColumnProperties): ({
5
+ sqlite: string;
6
+ postgres: string;
7
+ mysql: string;
8
+ } | {
9
+ sqlite: string;
10
+ postgres: string;
11
+ mysql: string;
12
+ } | {
13
+ sqlite: string;
14
+ postgres: string;
15
+ mysql: string;
16
+ } | {
17
+ sqlite: string;
18
+ postgres: string;
19
+ mysql: string;
20
+ } | {
21
+ sqlite: string;
22
+ postgres: string;
23
+ mysql: string;
24
+ })[DbDialect];
25
+ declare function columnProperty<DbDialect extends Dialect>(dialect: DbDialect): {
26
+ NOT_NULL: ({
27
+ sqlite: string;
28
+ postgres: string;
29
+ mysql: string;
30
+ } | {
31
+ sqlite: string;
32
+ postgres: string;
33
+ mysql: string;
34
+ } | {
35
+ sqlite: string;
36
+ postgres: string;
37
+ mysql: string;
38
+ } | {
39
+ sqlite: string;
40
+ postgres: string;
41
+ mysql: string;
42
+ } | {
43
+ sqlite: string;
44
+ postgres: string;
45
+ mysql: string;
46
+ })[DbDialect];
47
+ UNIQUE: ({
48
+ sqlite: string;
49
+ postgres: string;
50
+ mysql: string;
51
+ } | {
52
+ sqlite: string;
53
+ postgres: string;
54
+ mysql: string;
55
+ } | {
56
+ sqlite: string;
57
+ postgres: string;
58
+ mysql: string;
59
+ } | {
60
+ sqlite: string;
61
+ postgres: string;
62
+ mysql: string;
63
+ } | {
64
+ sqlite: string;
65
+ postgres: string;
66
+ mysql: string;
67
+ })[DbDialect];
68
+ DEFAULT: ({
69
+ sqlite: string;
70
+ postgres: string;
71
+ mysql: string;
72
+ } | {
73
+ sqlite: string;
74
+ postgres: string;
75
+ mysql: string;
76
+ } | {
77
+ sqlite: string;
78
+ postgres: string;
79
+ mysql: string;
80
+ } | {
81
+ sqlite: string;
82
+ postgres: string;
83
+ mysql: string;
84
+ } | {
85
+ sqlite: string;
86
+ postgres: string;
87
+ mysql: string;
88
+ })[DbDialect];
89
+ AUTO_INCREMENT: ({
90
+ sqlite: string;
91
+ postgres: string;
92
+ mysql: string;
93
+ } | {
94
+ sqlite: string;
95
+ postgres: string;
96
+ mysql: string;
97
+ } | {
98
+ sqlite: string;
99
+ postgres: string;
100
+ mysql: string;
101
+ } | {
102
+ sqlite: string;
103
+ postgres: string;
104
+ mysql: string;
105
+ } | {
106
+ sqlite: string;
107
+ postgres: string;
108
+ mysql: string;
109
+ })[DbDialect];
110
+ PRIMARY_KEY: ({
111
+ sqlite: string;
112
+ postgres: string;
113
+ mysql: string;
114
+ } | {
115
+ sqlite: string;
116
+ postgres: string;
117
+ mysql: string;
118
+ } | {
119
+ sqlite: string;
120
+ postgres: string;
121
+ mysql: string;
122
+ } | {
123
+ sqlite: string;
124
+ postgres: string;
125
+ mysql: string;
126
+ } | {
127
+ sqlite: string;
128
+ postgres: string;
129
+ mysql: string;
130
+ })[DbDialect];
131
+ };
132
+
133
+ export { columnProperty, getColumnProperty };
@@ -0,0 +1,32 @@
1
+ import { ColumnPropertyMapping, ColumnProperties } from './constants.js';
2
+
3
+ // src/column/utils.ts
4
+ function getColumnProperty(dialect, property) {
5
+ return ColumnPropertyMapping[property][dialect];
6
+ }
7
+ function columnProperty(dialect) {
8
+ return {
9
+ [ColumnProperties.NOT_NULL]: getColumnProperty(
10
+ dialect,
11
+ ColumnProperties.NOT_NULL
12
+ ),
13
+ [ColumnProperties.UNIQUE]: getColumnProperty(
14
+ dialect,
15
+ ColumnProperties.UNIQUE
16
+ ),
17
+ [ColumnProperties.DEFAULT]: getColumnProperty(
18
+ dialect,
19
+ ColumnProperties.DEFAULT
20
+ ),
21
+ [ColumnProperties.AUTO_INCREMENT]: getColumnProperty(
22
+ dialect,
23
+ ColumnProperties.AUTO_INCREMENT
24
+ ),
25
+ [ColumnProperties.PRIMARY_KEY]: getColumnProperty(
26
+ dialect,
27
+ ColumnProperties.PRIMARY_KEY
28
+ )
29
+ };
30
+ }
31
+
32
+ export { columnProperty, getColumnProperty };
@@ -1,8 +1,9 @@
1
- import { D as Database } from '../index-DFrpzXEn.js';
1
+ import { D as Database } from '../index-BXOAxB_h.js';
2
2
  import { Column } from '../column/index.js';
3
3
  import { AcceptedColumnTypes } from '../column/constants.js';
4
- import { T as Table, D as DatabaseDefinition } from '../index-FMT0YEO7.js';
4
+ import { T as Table, D as DatabaseDefinition } from '../index-BdpoD4zk.js';
5
5
  import { Dialect } from '../table/constants.js';
6
+ import 'bun';
6
7
  import '../query/constants.js';
7
8
  import '../column/types.js';
8
9
  import '../types.js';
@@ -1,12 +1,13 @@
1
- import { Dialect } from '../table/constants';
1
+ import { Dialect } from '../table/constants.js';
2
2
 
3
+ // src/database/alter.ts
3
4
  async function alterColumnType(tableName, columnName, newType) {
4
5
  if (this.dialect === Dialect.SQLITE) {
5
6
  throw new Error("SQLite does not support ALTER COLUMN TYPE directly.");
6
7
  }
7
- await this.client.exec(
8
- `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} TYPE ${newType}`
9
- );
8
+ await this.client.exec({
9
+ sql: `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} TYPE ${newType}`
10
+ });
10
11
  if (!this.tables[tableName]) return this;
11
12
  this.tables[tableName].columns[columnName].type = newType;
12
13
  return this;
@@ -15,9 +16,9 @@ async function setColumnDefault(tableName, columnName, value) {
15
16
  if (this.dialect === Dialect.SQLITE) {
16
17
  throw new Error("SQLite does not support ALTER COLUMN DEFAULT directly.");
17
18
  }
18
- await this.client.exec(
19
- `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET DEFAULT ${value}`
20
- );
19
+ await this.client.exec({
20
+ sql: `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET DEFAULT ${value}`
21
+ });
21
22
  if (!this.tables[tableName]) return this;
22
23
  if (
23
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -32,9 +33,9 @@ async function dropColumnDefault(tableName, columnName) {
32
33
  if (this.dialect === Dialect.SQLITE) {
33
34
  throw new Error("SQLite does not support DROP DEFAULT directly.");
34
35
  }
35
- await this.client.exec(
36
- `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP DEFAULT`
37
- );
36
+ await this.client.exec({
37
+ sql: `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP DEFAULT`
38
+ });
38
39
  if (!this.tables[tableName]) return this;
39
40
  if (
40
41
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -51,9 +52,9 @@ async function setColumnNotNull(tableName, columnName) {
51
52
  "SQLite does not support SET NOT NULL (requires table rebuild)"
52
53
  );
53
54
  }
54
- await this.client.exec(
55
- `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET NOT NULL`
56
- );
55
+ await this.client.exec({
56
+ sql: `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET NOT NULL`
57
+ });
57
58
  if (!this.tables[tableName]) return this;
58
59
  if (
59
60
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -70,9 +71,9 @@ async function dropColumnNotNull(tableName, columnName) {
70
71
  "SQLite does not support DROP NOT NULL (requires table rebuild)"
71
72
  );
72
73
  }
73
- await this.client.exec(
74
- `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP NOT NULL`
75
- );
74
+ await this.client.exec({
75
+ sql: `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP NOT NULL`
76
+ });
76
77
  if (!this.tables[tableName]) return this;
77
78
  if (
78
79
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1,7 +1,8 @@
1
- import { D as Database } from '../index-DFrpzXEn.js';
1
+ import { D as Database } from '../index-BXOAxB_h.js';
2
2
  import { Column } from '../column/index.js';
3
- import { T as Table, D as DatabaseDefinition } from '../index-FMT0YEO7.js';
3
+ import { T as Table, D as DatabaseDefinition } from '../index-BdpoD4zk.js';
4
4
  import { Dialect } from '../table/constants.js';
5
+ import 'bun';
5
6
  import '../query/constants.js';
6
7
  import '../column/constants.js';
7
8
  import '../column/types.js';