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