@ignisia/sql 0.1.0 → 0.2.1

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 (72) hide show
  1. package/README.md +8 -8
  2. package/dist/column/constants.js +97 -8
  3. package/dist/column/index.js +105 -8
  4. package/dist/column/types.js +1 -2
  5. package/dist/database/alter.d.ts +3 -3
  6. package/dist/database/alter.js +87 -15
  7. package/dist/database/column.d.ts +3 -3
  8. package/dist/database/column.js +33 -11
  9. package/dist/database/contract.d.ts +3 -3
  10. package/dist/database/contract.js +1 -0
  11. package/dist/database/index.d.ts +3 -3
  12. package/dist/database/index.js +92 -19
  13. package/dist/database/table.d.ts +3 -3
  14. package/dist/database/table.js +37 -19
  15. package/dist/database/types.d.ts +1 -1
  16. package/dist/database/types.js +1 -0
  17. package/dist/database/wrapper.d.ts +1 -1
  18. package/dist/database/wrapper.js +92 -9
  19. package/dist/{index-Dcm5xIpR.d.ts → index-DFrpzXEn.d.ts} +5 -1
  20. package/dist/{index-DJhQVUY3.d.ts → index-FMT0YEO7.d.ts} +17 -3
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +5 -32
  23. package/dist/migration/index.d.ts +3 -3
  24. package/dist/migration/index.js +48 -6
  25. package/dist/migration/runner.js +8 -21
  26. package/dist/migration/type.d.ts +3 -3
  27. package/dist/migration/type.js +1 -0
  28. package/dist/query/builder.d.ts +1 -1
  29. package/dist/query/builder.js +66 -16
  30. package/dist/query/condition.d.ts +1 -1
  31. package/dist/query/condition.js +97 -24
  32. package/dist/query/constants.d.ts +6 -1
  33. package/dist/query/constants.js +54 -17
  34. package/dist/query/contract.d.ts +1 -1
  35. package/dist/query/contract.js +1 -0
  36. package/dist/query/helper.d.ts +1 -1
  37. package/dist/query/helper.js +30 -18
  38. package/dist/query/index.d.ts +1 -1
  39. package/dist/query/index.js +195 -10
  40. package/dist/query/join.d.ts +1 -1
  41. package/dist/query/join.js +16 -6
  42. package/dist/query/sql.d.ts +1 -1
  43. package/dist/query/sql.js +99 -16
  44. package/dist/query/types.d.ts +1 -1
  45. package/dist/query/types.js +1 -0
  46. package/dist/query/utilities.d.ts +1 -1
  47. package/dist/query/utilities.js +175 -24
  48. package/dist/table/constants.js +5 -5
  49. package/dist/table/index.d.ts +1 -1
  50. package/dist/table/index.js +52 -14
  51. package/dist/table/types.d.ts +1 -1
  52. package/dist/table/types.js +1 -0
  53. package/dist/table/utilities.d.ts +1 -1
  54. package/dist/table/utilities.js +50 -15
  55. package/dist/types.js +1 -0
  56. package/dist/utilities.js +18 -8
  57. package/package.json +37 -2
  58. package/dist/chunk-4DQRB5XS.js +0 -94
  59. package/dist/chunk-CIWX3UCZ.js +0 -51
  60. package/dist/chunk-D2ASIT4Q.js +0 -44
  61. package/dist/chunk-FYSNJAGD.js +0 -19
  62. package/dist/chunk-G3LSCLIQ.js +0 -104
  63. package/dist/chunk-GLOHF5CP.js +0 -9
  64. package/dist/chunk-GY7R637S.js +0 -113
  65. package/dist/chunk-HKTHKQLK.js +0 -98
  66. package/dist/chunk-JF7OSNH4.js +0 -40
  67. package/dist/chunk-MG2S4V4N.js +0 -60
  68. package/dist/chunk-TQ2GXAE7.js +0 -663
  69. package/dist/chunk-V4OMHVJN.js +0 -96
  70. package/dist/chunk-W2DR3ZVK.js +0 -59
  71. package/dist/chunk-WVJGTZFI.js +0 -60
  72. package/dist/chunk-Y7FSRHH3.js +0 -22
@@ -1,96 +0,0 @@
1
- import {
2
- Dialect
3
- } from "./chunk-GLOHF5CP.js";
4
-
5
- // src/database/alter.ts
6
- async function alterColumnType(tableName, columnName, newType) {
7
- if (this.dialect === Dialect.SQLITE) {
8
- throw new Error("SQLite does not support ALTER COLUMN TYPE directly.");
9
- }
10
- await this.client.exec(
11
- `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} TYPE ${newType}`
12
- );
13
- if (!this.tables[tableName]) return this;
14
- this.tables[tableName].columns[columnName].type = newType;
15
- return this;
16
- }
17
- async function setColumnDefault(tableName, columnName, value) {
18
- if (this.dialect === Dialect.SQLITE) {
19
- throw new Error("SQLite does not support ALTER COLUMN DEFAULT directly.");
20
- }
21
- await this.client.exec(
22
- `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET DEFAULT ${value}`
23
- );
24
- if (!this.tables[tableName]) return this;
25
- if (
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
- !this.tables[tableName].columns[columnName].definition
28
- ) {
29
- this.tables[tableName].columns[columnName].definition = {};
30
- }
31
- this.tables[tableName].columns[columnName].definition.default = value;
32
- return this;
33
- }
34
- async function dropColumnDefault(tableName, columnName) {
35
- if (this.dialect === Dialect.SQLITE) {
36
- throw new Error("SQLite does not support DROP DEFAULT directly.");
37
- }
38
- await this.client.exec(
39
- `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP DEFAULT`
40
- );
41
- if (!this.tables[tableName]) return this;
42
- if (
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- !this.tables[tableName].columns[columnName].definition
45
- ) {
46
- this.tables[tableName].columns[columnName].definition = {};
47
- }
48
- delete this.tables[tableName].columns[columnName].definition.default;
49
- return this;
50
- }
51
- async function setColumnNotNull(tableName, columnName) {
52
- if (this.dialect === Dialect.SQLITE) {
53
- throw new Error(
54
- "SQLite does not support SET NOT NULL (requires table rebuild)"
55
- );
56
- }
57
- await this.client.exec(
58
- `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET NOT NULL`
59
- );
60
- if (!this.tables[tableName]) return this;
61
- if (
62
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
- !this.tables[tableName].columns[columnName].definition
64
- ) {
65
- this.tables[tableName].columns[columnName].definition = {};
66
- }
67
- this.tables[tableName].columns[columnName].definition.notNull = true;
68
- return this;
69
- }
70
- async function dropColumnNotNull(tableName, columnName) {
71
- if (this.dialect === Dialect.SQLITE) {
72
- throw new Error(
73
- "SQLite does not support DROP NOT NULL (requires table rebuild)"
74
- );
75
- }
76
- await this.client.exec(
77
- `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP NOT NULL`
78
- );
79
- if (!this.tables[tableName]) return this;
80
- if (
81
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
- !this.tables[tableName].columns[columnName].definition
83
- ) {
84
- this.tables[tableName].columns[columnName].definition = {};
85
- }
86
- this.tables[tableName].columns[columnName].definition.notNull = null;
87
- return this;
88
- }
89
-
90
- export {
91
- alterColumnType,
92
- setColumnDefault,
93
- dropColumnDefault,
94
- setColumnNotNull,
95
- dropColumnNotNull
96
- };
@@ -1,59 +0,0 @@
1
- import {
2
- QueryBuilder
3
- } from "./chunk-TQ2GXAE7.js";
4
- import {
5
- defineColumns
6
- } from "./chunk-WVJGTZFI.js";
7
-
8
- // src/table/index.ts
9
- var Table = class _Table {
10
- database;
11
- dialect;
12
- name;
13
- columns;
14
- timestamp;
15
- paranoid;
16
- _output;
17
- constructor(options) {
18
- this.dialect = options.dialect;
19
- this.name = options.name;
20
- this.columns = options.columns;
21
- this.paranoid = options.paranoid || null;
22
- this.timestamp = options.timestamp || null;
23
- this.database = null;
24
- for (const column of Object.values(this.columns)) {
25
- column.dialect(options.dialect);
26
- }
27
- }
28
- infer() {
29
- return null;
30
- }
31
- static define(options) {
32
- const columns = defineColumns(options);
33
- return new _Table({
34
- ...options,
35
- columns
36
- });
37
- }
38
- async create(db = this.database) {
39
- if (!db) throw new Error("Database client not defined");
40
- const sql = `CREATE TABLE IF NOT EXISTS ${this.name} (${Object.entries(
41
- this.columns
42
- ).map(([name, column]) => `${name} ${column.toQuery().query}`).join(", ")});`;
43
- await db.exec(sql);
44
- return this;
45
- }
46
- async drop(db = this.database) {
47
- if (!db) throw new Error("Database client not defined");
48
- const sql = `DROP TABLE IF EXISTS ${this.name};`;
49
- await db.exec(sql);
50
- return this;
51
- }
52
- query() {
53
- return new QueryBuilder(this);
54
- }
55
- };
56
-
57
- export {
58
- Table
59
- };
@@ -1,60 +0,0 @@
1
- import {
2
- Column
3
- } from "./chunk-GY7R637S.js";
4
-
5
- // src/table/utilities.ts
6
- var createdAt = Column.define({
7
- type: "DATETIME"
8
- }).default("CURRENT_TIMESTAMP");
9
- var updatedAt = Column.define({
10
- type: "DATETIME"
11
- });
12
- var deletedAt = Column.define({
13
- type: "DATETIME"
14
- });
15
- function defineColumns(options) {
16
- const columns = {
17
- ...options.columns
18
- };
19
- const tracker = {
20
- createdAt: "createdAt",
21
- updatedAt: "updatedAt",
22
- deletedAt: "deletedAt"
23
- };
24
- if (options.timestamp) {
25
- const timestamp = {
26
- createdAt: "createdAt",
27
- updatedAt: "updatedAt"
28
- };
29
- if (typeof options.timestamp === "object") {
30
- if (typeof options.timestamp.createdAt === "string") {
31
- timestamp.createdAt = options.timestamp.createdAt;
32
- }
33
- if (typeof options.timestamp.updatedAt === "string") {
34
- timestamp.updatedAt = options.timestamp.updatedAt;
35
- }
36
- }
37
- if (!columns[timestamp.createdAt]) {
38
- columns[timestamp.createdAt] = createdAt;
39
- }
40
- if (!columns[timestamp.updatedAt]) {
41
- columns[timestamp.updatedAt] = updatedAt;
42
- }
43
- }
44
- if (options.paranoid) {
45
- if (typeof options.paranoid !== "boolean") {
46
- tracker.deletedAt = options.paranoid;
47
- }
48
- if (!columns[tracker.deletedAt]) {
49
- columns[tracker.deletedAt] = deletedAt;
50
- }
51
- }
52
- return columns;
53
- }
54
-
55
- export {
56
- createdAt,
57
- updatedAt,
58
- deletedAt,
59
- defineColumns
60
- };
@@ -1,22 +0,0 @@
1
- // src/utilities.ts
2
- function deepClone(obj) {
3
- if (Array.isArray(obj)) {
4
- return obj.map((item) => deepClone(item));
5
- }
6
- if (obj && typeof obj === "object") {
7
- const clonedObj = {};
8
- for (const key in obj) {
9
- clonedObj[key] = deepClone(obj[key]);
10
- }
11
- return clonedObj;
12
- }
13
- return obj;
14
- }
15
- function quoteIdentifier(identifier) {
16
- return `"${identifier.replace(/"/g, '""')}"`;
17
- }
18
-
19
- export {
20
- deepClone,
21
- quoteIdentifier
22
- };