durcno 1.0.0-alpha.1 → 1.0.0-alpha.3
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.
- package/README.md +6 -3
- package/dist/bin.cjs +82 -80
- package/dist/src/columns/bigint.d.mts +1 -0
- package/dist/src/columns/bigint.mjs +3 -0
- package/dist/src/columns/bigserial.d.mts +1 -0
- package/dist/src/columns/bigserial.mjs +3 -0
- package/dist/src/columns/boolean.d.mts +1 -0
- package/dist/src/columns/boolean.mjs +3 -0
- package/dist/src/columns/bytea.d.mts +1 -0
- package/dist/src/columns/bytea.mjs +3 -0
- package/dist/src/columns/char.d.mts +1 -0
- package/dist/src/columns/char.mjs +3 -0
- package/dist/src/columns/cidr.d.mts +1 -0
- package/dist/src/columns/cidr.mjs +3 -0
- package/dist/src/columns/common.d.mts +8 -2
- package/dist/src/columns/common.mjs +21 -7
- package/dist/src/columns/date.d.mts +1 -0
- package/dist/src/columns/date.mjs +3 -0
- package/dist/src/columns/enum.d.mts +1 -0
- package/dist/src/columns/enum.mjs +3 -0
- package/dist/src/columns/inet.d.mts +1 -0
- package/dist/src/columns/inet.mjs +3 -0
- package/dist/src/columns/integer.d.mts +1 -0
- package/dist/src/columns/integer.mjs +3 -0
- package/dist/src/columns/json.d.mts +1 -0
- package/dist/src/columns/json.mjs +3 -0
- package/dist/src/columns/jsonb.d.mts +1 -0
- package/dist/src/columns/jsonb.mjs +3 -0
- package/dist/src/columns/macaddr.d.mts +1 -0
- package/dist/src/columns/macaddr.mjs +3 -0
- package/dist/src/columns/numeric.d.mts +1 -0
- package/dist/src/columns/numeric.mjs +3 -0
- package/dist/src/columns/postgis/geography/linestring.d.mts +1 -0
- package/dist/src/columns/postgis/geography/linestring.mjs +3 -0
- package/dist/src/columns/postgis/geography/multilinestring.d.mts +1 -0
- package/dist/src/columns/postgis/geography/multilinestring.mjs +3 -0
- package/dist/src/columns/postgis/geography/multipoint.d.mts +1 -0
- package/dist/src/columns/postgis/geography/multipoint.mjs +3 -0
- package/dist/src/columns/postgis/geography/multipolygon.d.mts +1 -0
- package/dist/src/columns/postgis/geography/multipolygon.mjs +3 -0
- package/dist/src/columns/postgis/geography/point.d.mts +1 -0
- package/dist/src/columns/postgis/geography/point.mjs +3 -0
- package/dist/src/columns/postgis/geography/polygon.d.mts +1 -0
- package/dist/src/columns/postgis/geography/polygon.mjs +3 -0
- package/dist/src/columns/serial.d.mts +1 -0
- package/dist/src/columns/serial.mjs +3 -0
- package/dist/src/columns/smallint.d.mts +1 -0
- package/dist/src/columns/smallint.mjs +3 -0
- package/dist/src/columns/smallserial.d.mts +1 -0
- package/dist/src/columns/smallserial.mjs +3 -0
- package/dist/src/columns/text.d.mts +1 -0
- package/dist/src/columns/text.mjs +3 -0
- package/dist/src/columns/time.d.mts +1 -0
- package/dist/src/columns/time.mjs +3 -0
- package/dist/src/columns/timestamp.d.mts +1 -0
- package/dist/src/columns/timestamp.mjs +3 -0
- package/dist/src/columns/uuid.d.mts +1 -0
- package/dist/src/columns/uuid.mjs +3 -0
- package/dist/src/columns/varchar.d.mts +1 -0
- package/dist/src/columns/varchar.mjs +3 -0
- package/dist/src/connectors/bun.d.mts +2 -2
- package/dist/src/connectors/bun.mjs +15 -15
- package/dist/src/connectors/common.d.mts +86 -25
- package/dist/src/connectors/common.mjs +76 -28
- package/dist/src/connectors/pg.d.mts +3 -2
- package/dist/src/connectors/pg.mjs +18 -15
- package/dist/src/connectors/pglite.d.mts +4 -4
- package/dist/src/connectors/pglite.mjs +19 -19
- package/dist/src/connectors/postgres.d.mts +3 -2
- package/dist/src/connectors/postgres.mjs +17 -14
- package/dist/src/db.d.mts +8 -9
- package/dist/src/db.mjs +30 -39
- package/dist/src/filters/array.d.mts +2 -2
- package/dist/src/filters/custom.d.mts +1 -1
- package/dist/src/filters/index.d.mts +3 -3
- package/dist/src/index.d.mts +25 -50
- package/dist/src/index.mjs +14 -15
- package/dist/src/logger.d.mts +32 -0
- package/dist/src/logger.mjs +57 -0
- package/dist/src/migration/ddl.d.mts +17 -0
- package/dist/src/migration/ddl.mjs +52 -1
- package/dist/src/query-builders/aggregates.d.mts +3 -4
- package/dist/src/query-builders/aggregates.mjs +2 -4
- package/dist/src/query-builders/count.d.mts +3 -4
- package/dist/src/query-builders/count.mjs +2 -4
- package/dist/src/query-builders/delete.d.mts +3 -4
- package/dist/src/query-builders/delete.mjs +4 -6
- package/dist/src/query-builders/distinct.d.mts +3 -4
- package/dist/src/query-builders/distinct.mjs +2 -4
- package/dist/src/query-builders/exists.d.mts +3 -4
- package/dist/src/query-builders/exists.mjs +2 -4
- package/dist/src/query-builders/first.d.mts +3 -4
- package/dist/src/query-builders/first.mjs +2 -4
- package/dist/src/query-builders/insert-returning.d.mts +3 -4
- package/dist/src/query-builders/insert-returning.mjs +6 -30
- package/dist/src/query-builders/insert.d.mts +8 -9
- package/dist/src/query-builders/insert.mjs +26 -19
- package/dist/src/query-builders/pre.d.mts +6 -6
- package/dist/src/query-builders/pre.mjs +7 -6
- package/dist/src/query-builders/query.d.mts +9 -4
- package/dist/src/query-builders/query.mjs +14 -1
- package/dist/src/query-builders/raw.d.mts +1 -1
- package/dist/src/query-builders/rq.d.mts +4 -5
- package/dist/src/query-builders/rq.mjs +18 -17
- package/dist/src/query-builders/select.d.mts +4 -5
- package/dist/src/query-builders/select.mjs +10 -14
- package/dist/src/query-builders/update.d.mts +4 -5
- package/dist/src/query-builders/update.mjs +7 -15
- package/dist/src/sql.d.mts +1 -1
- package/dist/src/table.d.mts +0 -2
- package/dist/src/wkx/binarywriter.mjs +103 -108
- package/dist/src/wkx/geometry.mjs +88 -95
- package/dist/src/wkx/geometrycollection.mjs +3 -6
- package/dist/src/wkx/index.mjs +1 -4
- package/dist/src/wkx/linestring.mjs +4 -8
- package/dist/src/wkx/multilinestring.mjs +4 -8
- package/dist/src/wkx/multipoint.mjs +4 -8
- package/dist/src/wkx/multipolygon.mjs +4 -8
- package/dist/src/wkx/parser.mjs +4 -8
- package/dist/src/wkx/point.mjs +147 -157
- package/dist/src/wkx/polygon.mjs +4 -8
- package/dist/src/wkx/types.mjs +30 -35
- package/dist/src/wkx/wktparser.mjs +2 -5
- package/dist/src/wkx/zigzag.mjs +5 -10
- package/package.json +6 -2
- package/dist/src/_virtual/_rolldown/runtime.mjs +0 -28
- package/dist/src/cli/helpers.mjs +0 -16
package/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<
|
|
2
|
+
<a href="https://npmjs.com/package/durcno" target="_blank">
|
|
3
|
+
<img src="https://img.shields.io/npm/v/durcno?style=flat&logo=npm&color=339933" alt="npm version" />
|
|
4
|
+
</a>
|
|
5
|
+
<img src="https://img.shields.io/badge/Node.js-24%2B-339933?style=flat&logo=node.js&logoColor=white" alt="Node.js 24+" />
|
|
3
6
|
<img src="https://img.shields.io/badge/PostgreSQL-14%2B-336791?style=flat&logo=postgresql&logoColor=white" alt="PostgreSQL 14+" />
|
|
4
|
-
<img src="https://img.shields.io/badge/Node.js-25%2B-339933?style=flat&logo=node.js&logoColor=white" alt="Node.js" />
|
|
5
7
|
<img src="https://img.shields.io/badge/License-Apache%202.0-blue?style=flat" alt="License" />
|
|
8
|
+
<img src="https://img.shields.io/badge/vitest--green?logo=vitest" alt="License" />
|
|
6
9
|
</p>
|
|
7
10
|
|
|
8
11
|
<h1 align="center">Durcno</h1>
|
|
@@ -32,7 +35,7 @@ npm install durcno
|
|
|
32
35
|
```
|
|
33
36
|
|
|
34
37
|
```bash
|
|
35
|
-
|
|
38
|
+
npm exec durcno init
|
|
36
39
|
```
|
|
37
40
|
|
|
38
41
|
## Getting Started
|
package/dist/bin.cjs
CHANGED
|
@@ -8903,19 +8903,17 @@ function resolveConfigPath(argPath) {
|
|
|
8903
8903
|
}
|
|
8904
8904
|
return (0, import_node_path2.resolve)(process.cwd(), DURCNO_CONFIG_NAME);
|
|
8905
8905
|
}
|
|
8906
|
-
function
|
|
8907
|
-
const
|
|
8908
|
-
|
|
8909
|
-
const { default: setup } = mod;
|
|
8910
|
-
return setup;
|
|
8906
|
+
async function loadConfig(absPath) {
|
|
8907
|
+
const mod = await import(absPath);
|
|
8908
|
+
return mod.default;
|
|
8911
8909
|
}
|
|
8912
8910
|
|
|
8913
8911
|
// src/cli/commands/down.ts
|
|
8914
8912
|
var { bgGreen, dim, cyan: cyan2, yellow: yellow2, red: red2 } = source_default;
|
|
8915
8913
|
async function down(m, options) {
|
|
8916
8914
|
const configPath = resolveConfigPath(options.config);
|
|
8917
|
-
const
|
|
8918
|
-
|
|
8915
|
+
const config2 = await loadConfig(configPath);
|
|
8916
|
+
const { connector } = config2;
|
|
8919
8917
|
const migrationsDir = (0, import_node_path3.resolve)(
|
|
8920
8918
|
(0, import_node_path3.dirname)(configPath),
|
|
8921
8919
|
config2.out || DEFAULT_MIGRATIONS_DIR
|
|
@@ -8925,7 +8923,7 @@ async function down(m, options) {
|
|
|
8925
8923
|
const client = connector.getClient();
|
|
8926
8924
|
await client.connect();
|
|
8927
8925
|
if (await migrationsTableExists(client)) {
|
|
8928
|
-
const db = (0, import_durcno2.database)({ Migrations: import_durcno2.Migrations },
|
|
8926
|
+
const db = (0, import_durcno2.database)({ Migrations: import_durcno2.Migrations }, config2);
|
|
8929
8927
|
const migrations = await db.from(import_durcno2.Migrations).select();
|
|
8930
8928
|
const migrationDirsReversed = migrationDirNames.sort().reverse();
|
|
8931
8929
|
for (let i = 0; i < migrationDirsReversed.length; i++) {
|
|
@@ -8939,7 +8937,7 @@ async function down(m, options) {
|
|
|
8939
8937
|
migrationDirName,
|
|
8940
8938
|
isFirstMigration,
|
|
8941
8939
|
migrationsDir,
|
|
8942
|
-
|
|
8940
|
+
config2,
|
|
8943
8941
|
client
|
|
8944
8942
|
);
|
|
8945
8943
|
if (migration.name === m) {
|
|
@@ -8954,7 +8952,7 @@ async function down(m, options) {
|
|
|
8954
8952
|
await client.close();
|
|
8955
8953
|
process.exit(0);
|
|
8956
8954
|
}
|
|
8957
|
-
async function runDownMigration(migrationDirName, isFirstMigration, migrationsDirPath,
|
|
8955
|
+
async function runDownMigration(migrationDirName, isFirstMigration, migrationsDirPath, config2, client) {
|
|
8958
8956
|
const migrationName = (0, import_node_path3.basename)(migrationDirName);
|
|
8959
8957
|
const downPath = (0, import_node_path3.join)(migrationsDirPath, migrationName, "down.ts");
|
|
8960
8958
|
try {
|
|
@@ -8987,7 +8985,9 @@ async function runDownMigration(migrationDirName, isFirstMigration, migrationsDi
|
|
|
8987
8985
|
throw e;
|
|
8988
8986
|
}
|
|
8989
8987
|
if (!isFirstMigration) {
|
|
8990
|
-
|
|
8988
|
+
config2.connector.pool = { ...config2.connector.pool, max: 1 };
|
|
8989
|
+
config2.connector.logger = void 0;
|
|
8990
|
+
const db = (0, import_durcno2.database)({ Migrations: import_durcno2.Migrations }, config2);
|
|
8991
8991
|
await db.delete(import_durcno2.Migrations).where((0, import_durcno2.eq)(import_durcno2.Migrations.name, migrationName));
|
|
8992
8992
|
await db.close();
|
|
8993
8993
|
}
|
|
@@ -11695,8 +11695,11 @@ var Arg = class {
|
|
|
11695
11695
|
index = 0;
|
|
11696
11696
|
key = "";
|
|
11697
11697
|
handler;
|
|
11698
|
-
|
|
11698
|
+
/** PostgreSQL cast type suffix (e.g. `"boolean"`, `"geography"`), or `null` if no cast needed. */
|
|
11699
|
+
cast = null;
|
|
11700
|
+
constructor(handler, cast = null) {
|
|
11699
11701
|
this.handler = handler;
|
|
11702
|
+
this.cast = cast;
|
|
11700
11703
|
}
|
|
11701
11704
|
};
|
|
11702
11705
|
|
|
@@ -11802,6 +11805,14 @@ var Column = class {
|
|
|
11802
11805
|
const suffix = this.config.dimension.map((d) => d === null ? "[]" : `[${d}]`).join("");
|
|
11803
11806
|
return `${base}${suffix}`;
|
|
11804
11807
|
}
|
|
11808
|
+
/** Returns the full PostgreSQL cast type including array dimensions, or `null` if no cast is needed. */
|
|
11809
|
+
get sqlCast() {
|
|
11810
|
+
const base = this.sqlCastScalar;
|
|
11811
|
+
if (base === null) return null;
|
|
11812
|
+
if (!this.config.dimension) return base;
|
|
11813
|
+
const suffix = this.config.dimension.map((d) => d === null ? "[]" : `[${d}]`).join("");
|
|
11814
|
+
return `${base}${suffix}`;
|
|
11815
|
+
}
|
|
11805
11816
|
get zodType() {
|
|
11806
11817
|
let schema = this.zodTypeScaler;
|
|
11807
11818
|
if (!this.config.dimension) {
|
|
@@ -11852,29 +11863,33 @@ var Column = class {
|
|
|
11852
11863
|
* Converts a JavaScript value to SQL string literal.
|
|
11853
11864
|
* Handles array dimensions with ARRAY[...] syntax if configured.
|
|
11854
11865
|
*/
|
|
11855
|
-
toSQL(value) {
|
|
11866
|
+
toSQL(value, options) {
|
|
11867
|
+
if (value === null) return "NULL";
|
|
11856
11868
|
if (value instanceof Sql) return value.string;
|
|
11857
11869
|
if (!this.config.dimension) {
|
|
11858
|
-
return this.toSQLScalar(value);
|
|
11870
|
+
if (!options?.cast || !this.sqlCastScalar) return this.toSQLScalar(value);
|
|
11871
|
+
return `${this.toSQLScalar(value)}::${this.sqlCastScalar}`;
|
|
11859
11872
|
}
|
|
11860
|
-
return this.#toSQLArray(value, 0);
|
|
11873
|
+
return this.#toSQLArray(value, 0, options);
|
|
11861
11874
|
}
|
|
11862
11875
|
/**
|
|
11863
11876
|
* Helper to recursively process multi-dimensional arrays for toSQL.
|
|
11864
11877
|
*/
|
|
11865
|
-
#toSQLArray(arr, dimIndex) {
|
|
11878
|
+
#toSQLArray(arr, dimIndex, options) {
|
|
11866
11879
|
const dimensions = this.config.dimension;
|
|
11867
11880
|
if (arr.length === 0) {
|
|
11868
11881
|
return "'{}'";
|
|
11869
11882
|
}
|
|
11870
11883
|
if (dimIndex >= dimensions.length - 1) {
|
|
11871
|
-
const elements2 = arr.map(
|
|
11872
|
-
(
|
|
11873
|
-
|
|
11884
|
+
const elements2 = arr.map((item) => {
|
|
11885
|
+
if (!options?.cast || !this.sqlCastScalar)
|
|
11886
|
+
return this.toSQLScalar(item);
|
|
11887
|
+
return `${this.toSQLScalar(item)}::${this.sqlCastScalar}`;
|
|
11888
|
+
});
|
|
11874
11889
|
return `ARRAY[${elements2.join(", ")}]`;
|
|
11875
11890
|
}
|
|
11876
11891
|
const elements = arr.map(
|
|
11877
|
-
(item) => this.#toSQLArray(item, dimIndex + 1)
|
|
11892
|
+
(item) => this.#toSQLArray(item, dimIndex + 1, options)
|
|
11878
11893
|
);
|
|
11879
11894
|
return `ARRAY[${elements.join(", ")}]`;
|
|
11880
11895
|
}
|
|
@@ -12044,7 +12059,7 @@ var Column = class {
|
|
|
12044
12059
|
* @returns an `Arg` instance with the type of this column
|
|
12045
12060
|
*/
|
|
12046
12061
|
arg() {
|
|
12047
|
-
return new Arg(this.toDriver.bind(this));
|
|
12062
|
+
return new Arg(this.toDriver.bind(this), this.sqlCast);
|
|
12048
12063
|
}
|
|
12049
12064
|
};
|
|
12050
12065
|
|
|
@@ -12219,7 +12234,7 @@ async function promptColumnRenames(prev, curr, renamedTables) {
|
|
|
12219
12234
|
}
|
|
12220
12235
|
async function generate(options) {
|
|
12221
12236
|
const configPath = resolveConfigPath(options.config);
|
|
12222
|
-
const
|
|
12237
|
+
const config2 = await loadConfig(configPath);
|
|
12223
12238
|
const migrationsDir = (0, import_node_path4.resolve)(
|
|
12224
12239
|
(0, import_node_path4.dirname)(configPath),
|
|
12225
12240
|
config2.out || DEFAULT_MIGRATIONS_DIR
|
|
@@ -12231,7 +12246,7 @@ async function generate(options) {
|
|
|
12231
12246
|
const ssPrevious = (0, import_migration2.createEmptySnapshot)();
|
|
12232
12247
|
for (const migrationFolder of migrationFolderNames.sort()) {
|
|
12233
12248
|
const upTsPath = (0, import_node_path4.resolve)(migrationsDir, migrationFolder, "up.ts");
|
|
12234
|
-
const upModule =
|
|
12249
|
+
const upModule = await import(upTsPath);
|
|
12235
12250
|
const statements = upModule.statements;
|
|
12236
12251
|
for (const statement of statements) {
|
|
12237
12252
|
statement.applyToSnapshot(ssPrevious);
|
|
@@ -12241,7 +12256,7 @@ async function generate(options) {
|
|
|
12241
12256
|
configPath ? (0, import_node_path4.dirname)(configPath) : process.cwd(),
|
|
12242
12257
|
config2.schema
|
|
12243
12258
|
);
|
|
12244
|
-
const exports2 =
|
|
12259
|
+
const exports2 = await import(schemaFile);
|
|
12245
12260
|
ensureNoEntityCollisions(exports2);
|
|
12246
12261
|
const entities = Object.values(exports2);
|
|
12247
12262
|
const ssCurrent = (0, import_migration2.snapshot)(entities);
|
|
@@ -12584,6 +12599,22 @@ function generateAlterTableStmts(prevTable, currTable, tableName, curr, statemen
|
|
|
12584
12599
|
alterStatements.push(`.dropDefault("${colName}")`);
|
|
12585
12600
|
}
|
|
12586
12601
|
}
|
|
12602
|
+
const prevRefJson = JSON.stringify(prevCol.references ?? null);
|
|
12603
|
+
const currRefJson = JSON.stringify(currCol.references ?? null);
|
|
12604
|
+
if (prevRefJson !== currRefJson) {
|
|
12605
|
+
if (prevCol.references) {
|
|
12606
|
+
const constraintName = `${currTable.name}_${colName}_fkey`;
|
|
12607
|
+
alterStatements.push(
|
|
12608
|
+
`.dropForeignKey("${constraintName}", "${colName}")`
|
|
12609
|
+
);
|
|
12610
|
+
}
|
|
12611
|
+
if (currCol.references) {
|
|
12612
|
+
const constraintName = `${currTable.name}_${colName}_fkey`;
|
|
12613
|
+
alterStatements.push(
|
|
12614
|
+
`.addForeignKey("${constraintName}", "${colName}", ${JSON.stringify(currCol.references)})`
|
|
12615
|
+
);
|
|
12616
|
+
}
|
|
12617
|
+
}
|
|
12587
12618
|
}
|
|
12588
12619
|
}
|
|
12589
12620
|
for (const idxName in currTable.indexes) {
|
|
@@ -12772,12 +12803,14 @@ function generateConfigFile(config2) {
|
|
|
12772
12803
|
return `${envLoader}import { defineConfig } from "durcno";
|
|
12773
12804
|
import { ${funcName} } from "durcno/connectors/${connector}";
|
|
12774
12805
|
|
|
12775
|
-
export default defineConfig(
|
|
12806
|
+
export default defineConfig({
|
|
12776
12807
|
schema: "${schemaPath}",
|
|
12777
12808
|
out: "${migrationsDir}",
|
|
12778
|
-
|
|
12779
|
-
|
|
12780
|
-
|
|
12809
|
+
connector: ${funcName}({
|
|
12810
|
+
dbCredentials: {
|
|
12811
|
+
url: ${urlValue},
|
|
12812
|
+
},
|
|
12813
|
+
}),
|
|
12781
12814
|
});
|
|
12782
12815
|
`;
|
|
12783
12816
|
}
|
|
@@ -12799,40 +12832,11 @@ function generateIndexFile(schemaPath) {
|
|
|
12799
12832
|
const schemaImport = schemaPath.replace(/^db\//, "./");
|
|
12800
12833
|
return `import { database } from "durcno";
|
|
12801
12834
|
import * as schema from "${schemaImport}";
|
|
12802
|
-
import
|
|
12835
|
+
import config from "../durcno.config.ts";
|
|
12803
12836
|
|
|
12804
|
-
export const db = database(schema,
|
|
12837
|
+
export const db = database(schema, config);
|
|
12805
12838
|
`;
|
|
12806
12839
|
}
|
|
12807
|
-
function setTypeModule() {
|
|
12808
|
-
const pkgPath = (0, import_node_path5.resolve)(process.cwd(), "package.json");
|
|
12809
|
-
if (!(0, import_node_fs3.existsSync)(pkgPath)) {
|
|
12810
|
-
(0, import_node_fs3.writeFileSync)(pkgPath, `${JSON.stringify({ type: "module" }, null, 2)}
|
|
12811
|
-
`);
|
|
12812
|
-
console.log(
|
|
12813
|
-
bold(
|
|
12814
|
-
`${green("\u2714")} Created ${cyan4("package.json")} with "type": "module"`
|
|
12815
|
-
)
|
|
12816
|
-
);
|
|
12817
|
-
return;
|
|
12818
|
-
}
|
|
12819
|
-
try {
|
|
12820
|
-
const pkgContent = (0, import_node_fs3.readFileSync)(pkgPath, "utf-8");
|
|
12821
|
-
const pkg = JSON.parse(pkgContent);
|
|
12822
|
-
if (pkg.type !== "module") {
|
|
12823
|
-
pkg.type = "module";
|
|
12824
|
-
(0, import_node_fs3.writeFileSync)(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
12825
|
-
`);
|
|
12826
|
-
console.log(
|
|
12827
|
-
bold(
|
|
12828
|
-
`${green("\u2714")} Updated ${cyan4("package.json")} with "type": "module"`
|
|
12829
|
-
)
|
|
12830
|
-
);
|
|
12831
|
-
}
|
|
12832
|
-
} catch (err) {
|
|
12833
|
-
console.log(yellow4(`Warning: Failed to update package.json: ${err}`));
|
|
12834
|
-
}
|
|
12835
|
-
}
|
|
12836
12840
|
async function promptConfig() {
|
|
12837
12841
|
const response = await (0, import_prompts2.default)(
|
|
12838
12842
|
[
|
|
@@ -12925,7 +12929,6 @@ async function init(options) {
|
|
|
12925
12929
|
config2 = DEFAULTS;
|
|
12926
12930
|
}
|
|
12927
12931
|
await writeFiles(config2, options);
|
|
12928
|
-
setTypeModule();
|
|
12929
12932
|
console.log(green.bold("\n\u{1F4E6} Setup dependencies\n"));
|
|
12930
12933
|
const toInstall = [];
|
|
12931
12934
|
const toInstallDrivers = [];
|
|
@@ -12979,7 +12982,7 @@ Installation failed with exit code ${exitCode}`)
|
|
|
12979
12982
|
}
|
|
12980
12983
|
console.log(green.bold("\n\u2728 Durcno Setuped!\n"));
|
|
12981
12984
|
console.log(dim2("Next steps:"));
|
|
12982
|
-
const execCmd = pm === "npm" ? "
|
|
12985
|
+
const execCmd = pm === "npm" ? "npm exec" : pm === "pnpm" ? "pnpm exec" : pm === "bun" ? "bunx" : pm;
|
|
12983
12986
|
const nextSteps = [
|
|
12984
12987
|
["Edit your schema in", magenta.bold(config2.schemaPath)],
|
|
12985
12988
|
["Run", cyan4.bold(`${execCmd} durcno generate`), "to create migrations"],
|
|
@@ -13000,8 +13003,8 @@ var import_durcno3 = require("durcno");
|
|
|
13000
13003
|
var { bgGreen: bgGreen3, bgYellow, dim: dim3, gray: gray4, yellow: yellow5, green: green2, cyan: cyan5 } = source_default;
|
|
13001
13004
|
async function migrate(options) {
|
|
13002
13005
|
const configPath = resolveConfigPath(options.config);
|
|
13003
|
-
const
|
|
13004
|
-
|
|
13006
|
+
const config2 = await loadConfig(configPath);
|
|
13007
|
+
const { connector } = config2;
|
|
13005
13008
|
const migrationsDir = (0, import_node_path6.resolve)(
|
|
13006
13009
|
(0, import_node_path6.dirname)(configPath),
|
|
13007
13010
|
config2.out || DEFAULT_MIGRATIONS_DIR
|
|
@@ -13014,16 +13017,13 @@ async function migrate(options) {
|
|
|
13014
13017
|
try {
|
|
13015
13018
|
let previouslyApplied = [];
|
|
13016
13019
|
if (await migrationsTableExists(client)) {
|
|
13017
|
-
const db = (0, import_durcno3.database)({ Migrations: import_durcno3.Migrations },
|
|
13020
|
+
const db = (0, import_durcno3.database)({ Migrations: import_durcno3.Migrations }, config2);
|
|
13018
13021
|
const records = await db.from(import_durcno3.Migrations).select();
|
|
13019
13022
|
previouslyApplied = records.map((r) => r.name);
|
|
13020
13023
|
}
|
|
13021
13024
|
for (const migrationDirName of migrationDirNames.sort()) {
|
|
13022
13025
|
if (!previouslyApplied.includes(migrationDirName)) {
|
|
13023
|
-
await runUpMigration(migrationDirName, migrationsDir, client,
|
|
13024
|
-
connector,
|
|
13025
|
-
config: config2
|
|
13026
|
-
});
|
|
13026
|
+
await runUpMigration(migrationDirName, migrationsDir, client, config2);
|
|
13027
13027
|
appliedMigrations.push(migrationDirName);
|
|
13028
13028
|
}
|
|
13029
13029
|
}
|
|
@@ -13039,7 +13039,7 @@ async function migrate(options) {
|
|
|
13039
13039
|
migrationFolder,
|
|
13040
13040
|
isFirstMigration,
|
|
13041
13041
|
migrationsDir,
|
|
13042
|
-
|
|
13042
|
+
config2,
|
|
13043
13043
|
client
|
|
13044
13044
|
);
|
|
13045
13045
|
}
|
|
@@ -13053,7 +13053,7 @@ async function migrate(options) {
|
|
|
13053
13053
|
await client.close();
|
|
13054
13054
|
process.exit(0);
|
|
13055
13055
|
}
|
|
13056
|
-
async function runUpMigration(migrationDirName, migrationsDir, client,
|
|
13056
|
+
async function runUpMigration(migrationDirName, migrationsDir, client, config2) {
|
|
13057
13057
|
const upPath = (0, import_node_path6.join)(migrationsDir, migrationDirName, "up.ts");
|
|
13058
13058
|
const migrationModule = await import(upPath);
|
|
13059
13059
|
const statements = migrationModule.statements;
|
|
@@ -13080,7 +13080,9 @@ async function runUpMigration(migrationDirName, migrationsDir, client, setup) {
|
|
|
13080
13080
|
console.log(
|
|
13081
13081
|
bgGreen3.white.bold("[APPLIED]") + " " + green2(`Migration ${cyan5(migrationDirName)}`) + dim3(".")
|
|
13082
13082
|
);
|
|
13083
|
-
|
|
13083
|
+
config2.connector.pool = { ...config2.connector.pool, max: 1 };
|
|
13084
|
+
config2.connector.logger = void 0;
|
|
13085
|
+
const db = (0, import_durcno3.database)({ Migrations: import_durcno3.Migrations }, config2);
|
|
13084
13086
|
await db.insert(import_durcno3.Migrations).values({
|
|
13085
13087
|
name: migrationDirName,
|
|
13086
13088
|
createdAt: /* @__PURE__ */ new Date()
|
|
@@ -13105,7 +13107,7 @@ var import_node_readline = require("node:readline");
|
|
|
13105
13107
|
var { cyan: cyan6, green: green3, red: red4, yellow: yellow6, gray: gray5, bgCyan, bold: bold2 } = source_default;
|
|
13106
13108
|
async function shell(options) {
|
|
13107
13109
|
const configPath = resolveConfigPath(options.config);
|
|
13108
|
-
const { connector } =
|
|
13110
|
+
const { connector } = await loadConfig(configPath);
|
|
13109
13111
|
const client = connector.getClient();
|
|
13110
13112
|
console.log(gray5("Connecting to database..."));
|
|
13111
13113
|
await client.connect();
|
|
@@ -13351,7 +13353,7 @@ var import_migration3 = require("durcno/migration");
|
|
|
13351
13353
|
var { bgGreen: bgGreen4, bgRed: bgRed2, yellow: yellow7, red: red5, green: green4, cyan: cyan7, gray: gray6 } = source_default;
|
|
13352
13354
|
async function squash(start, end, options) {
|
|
13353
13355
|
const configPath = resolveConfigPath(options.config);
|
|
13354
|
-
const
|
|
13356
|
+
const config2 = await loadConfig(configPath);
|
|
13355
13357
|
const migrationsDir = (0, import_node_path7.resolve)(
|
|
13356
13358
|
(0, import_node_path7.dirname)(configPath),
|
|
13357
13359
|
config2.out || DEFAULT_MIGRATIONS_DIR
|
|
@@ -13389,7 +13391,7 @@ async function squash(start, end, options) {
|
|
|
13389
13391
|
let hasCustomStatements = false;
|
|
13390
13392
|
for (const migrationDirName of range) {
|
|
13391
13393
|
const upPath = (0, import_node_path7.join)(migrationsDir, migrationDirName, "up.ts");
|
|
13392
|
-
const upModule =
|
|
13394
|
+
const upModule = await import(upPath);
|
|
13393
13395
|
const statements = upModule.statements;
|
|
13394
13396
|
if (statements.some((st) => st.isCustom)) {
|
|
13395
13397
|
hasCustomStatements = true;
|
|
@@ -13407,7 +13409,7 @@ async function squash(start, end, options) {
|
|
|
13407
13409
|
const beforeSnapshot = (0, import_migration3.createEmptySnapshot)();
|
|
13408
13410
|
for (const migrationDirName of before) {
|
|
13409
13411
|
const upPath = (0, import_node_path7.join)(migrationsDir, migrationDirName, "up.ts");
|
|
13410
|
-
const upModule =
|
|
13412
|
+
const upModule = await import(upPath);
|
|
13411
13413
|
const statements = upModule.statements;
|
|
13412
13414
|
for (const statement of statements) {
|
|
13413
13415
|
statement.applyToSnapshot(beforeSnapshot);
|
|
@@ -13416,7 +13418,7 @@ async function squash(start, end, options) {
|
|
|
13416
13418
|
const afterRangeSnapshot = (0, import_migration3.createEmptySnapshot)();
|
|
13417
13419
|
for (const migrationDirName of [...before, ...range]) {
|
|
13418
13420
|
const upPath = (0, import_node_path7.join)(migrationsDir, migrationDirName, "up.ts");
|
|
13419
|
-
const upModule =
|
|
13421
|
+
const upModule = await import(upPath);
|
|
13420
13422
|
const statements = upModule.statements;
|
|
13421
13423
|
for (const statement of statements) {
|
|
13422
13424
|
statement.applyToSnapshot(afterRangeSnapshot);
|
|
@@ -13458,8 +13460,8 @@ var import_durcno4 = require("durcno");
|
|
|
13458
13460
|
var { dim: dim4, cyan: cyan8, yellow: yellow8, green: green5 } = source_default;
|
|
13459
13461
|
async function status(options) {
|
|
13460
13462
|
const configPath = resolveConfigPath(options.config);
|
|
13461
|
-
const
|
|
13462
|
-
|
|
13463
|
+
const config2 = await loadConfig(configPath);
|
|
13464
|
+
const { connector } = config2;
|
|
13463
13465
|
const migrationsDir = (0, import_node_path8.resolve)(
|
|
13464
13466
|
(0, import_node_path8.dirname)(configPath),
|
|
13465
13467
|
config2.out || DEFAULT_MIGRATIONS_DIR
|
|
@@ -13470,7 +13472,7 @@ async function status(options) {
|
|
|
13470
13472
|
console.log(source_default.yellow("No migrations found."));
|
|
13471
13473
|
process.exit(0);
|
|
13472
13474
|
}
|
|
13473
|
-
const db = (0, import_durcno4.database)({ Migrations: import_durcno4.Migrations },
|
|
13475
|
+
const db = (0, import_durcno4.database)({ Migrations: import_durcno4.Migrations }, config2);
|
|
13474
13476
|
const migrationsQuery = db.from(import_durcno4.Migrations).select();
|
|
13475
13477
|
let migrations;
|
|
13476
13478
|
const client = connector.getClient();
|
|
@@ -13503,7 +13505,7 @@ async function status(options) {
|
|
|
13503
13505
|
}
|
|
13504
13506
|
|
|
13505
13507
|
// src/cli/index.ts
|
|
13506
|
-
program.version("1.0.0-alpha.
|
|
13508
|
+
program.version("1.0.0-alpha.2");
|
|
13507
13509
|
var Options = {
|
|
13508
13510
|
config: ["--config <path>", "Path to the config file"]
|
|
13509
13511
|
};
|
|
@@ -8,6 +8,7 @@ type BigintConfig = ColumnConfig;
|
|
|
8
8
|
declare class BigintColumn<TConfig extends BigintConfig> extends Column<TConfig, BigintValType> {
|
|
9
9
|
static readonly id = "Column.Bigint";
|
|
10
10
|
get sqlTypeScalar(): string;
|
|
11
|
+
get sqlCastScalar(): null;
|
|
11
12
|
get zodTypeScaler(): z.ZodCoercedNumber<unknown>;
|
|
12
13
|
toDriverScalar(value: BigintValType | Sql | null): string | number | null;
|
|
13
14
|
toSQLScalar(value: number | Sql | null): string;
|
|
@@ -13,6 +13,7 @@ declare class BigserialColumn<TConfig extends BigserialConfig> extends Column<Bi
|
|
|
13
13
|
static readonly id = "Column.Bigserial";
|
|
14
14
|
constructor(config: TConfig);
|
|
15
15
|
get sqlTypeScalar(): string;
|
|
16
|
+
get sqlCastScalar(): null;
|
|
16
17
|
get zodTypeScaler(): z.ZodCoercedNumber<unknown>;
|
|
17
18
|
toDriverScalar(value: BigserialValType | Sql | null): string | number | null;
|
|
18
19
|
toSQLScalar(value: number | Sql | null): string;
|
|
@@ -8,6 +8,7 @@ type BooleanConfig = ColumnConfig;
|
|
|
8
8
|
declare class BooleanColumn<TConfig extends BooleanConfig> extends Column<TConfig, BooleanValType> {
|
|
9
9
|
static readonly id = "Column.Boolean";
|
|
10
10
|
get sqlTypeScalar(): string;
|
|
11
|
+
get sqlCastScalar(): string;
|
|
11
12
|
get zodTypeScaler(): z.ZodBoolean;
|
|
12
13
|
toDriverScalar(value: BooleanValType | Sql | null): string | null;
|
|
13
14
|
toSQLScalar(value: boolean | Sql | null): string;
|
|
@@ -8,6 +8,7 @@ type ByteaConfig = ColumnConfig;
|
|
|
8
8
|
declare class ByteaColumn<TConfig extends ByteaConfig> extends Column<TConfig, ByteaValType> {
|
|
9
9
|
static readonly id = "Column.Bytea";
|
|
10
10
|
get sqlTypeScalar(): string;
|
|
11
|
+
get sqlCastScalar(): string;
|
|
11
12
|
get zodTypeScaler(): z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
|
|
12
13
|
toDriverScalar(value: ByteaValType | Sql | null): string | null;
|
|
13
14
|
toSQLScalar(value: ByteaValType | Sql | null): string;
|
|
@@ -12,6 +12,7 @@ declare class CharColumn<TConfig extends CharConfig> extends Column<TConfig, Cha
|
|
|
12
12
|
static readonly id = "Column.Char";
|
|
13
13
|
constructor(config: TConfig);
|
|
14
14
|
get sqlTypeScalar(): string;
|
|
15
|
+
get sqlCastScalar(): null;
|
|
15
16
|
get zodTypeScaler(): z.ZodString;
|
|
16
17
|
toDriverScalar(value: CharValType | Sql | null): string | null;
|
|
17
18
|
toSQLScalar(value: string | Sql | null): string;
|
|
@@ -8,6 +8,7 @@ type CidrConfig = ColumnConfig;
|
|
|
8
8
|
declare class CidrColumn<TConfig extends CidrConfig> extends Column<TConfig, CidrValType> {
|
|
9
9
|
static readonly id = "Column.Cidr";
|
|
10
10
|
get sqlTypeScalar(): string;
|
|
11
|
+
get sqlCastScalar(): string;
|
|
11
12
|
get zodTypeScaler(): z.ZodUnion<readonly [z.ZodCIDRv4, z.ZodCIDRv6]>;
|
|
12
13
|
toDriverScalar(value: CidrValType | Sql | null): string | null;
|
|
13
14
|
toSQLScalar(value: string | Sql | null): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Sql } from "../sql.mjs";
|
|
2
2
|
import { entityType } from "../symbols.mjs";
|
|
3
|
-
import { Arg } from "../query-builders/pre.mjs";
|
|
4
3
|
import { StdTableColumn, TableColumn } from "../table.mjs";
|
|
4
|
+
import { Arg } from "../query-builders/pre.mjs";
|
|
5
5
|
import * as z from "zod";
|
|
6
6
|
|
|
7
7
|
//#region src/columns/common.d.ts
|
|
@@ -158,6 +158,10 @@ declare abstract class Column<TConfig extends ColumnConfig, TColVal> {
|
|
|
158
158
|
} ? true : false;
|
|
159
159
|
abstract get sqlTypeScalar(): string;
|
|
160
160
|
get sqlType(): string;
|
|
161
|
+
/** Returns the PostgreSQL cast type for this column's scalar value, or `null` if no cast is needed. */
|
|
162
|
+
abstract get sqlCastScalar(): string | null;
|
|
163
|
+
/** Returns the full PostgreSQL cast type including array dimensions, or `null` if no cast is needed. */
|
|
164
|
+
get sqlCast(): string | null;
|
|
161
165
|
abstract get zodTypeScaler(): z.ZodType;
|
|
162
166
|
get zodType(): GetZodTypeArray<this["zodTypeScaler"], this["config"]>;
|
|
163
167
|
/**
|
|
@@ -177,7 +181,9 @@ declare abstract class Column<TConfig extends ColumnConfig, TColVal> {
|
|
|
177
181
|
* Converts a JavaScript value to SQL string literal.
|
|
178
182
|
* Handles array dimensions with ARRAY[...] syntax if configured.
|
|
179
183
|
*/
|
|
180
|
-
toSQL(value: this["ValType"] | Sql | null
|
|
184
|
+
toSQL(value: this["ValType"] | Sql | null, options?: {
|
|
185
|
+
cast?: boolean;
|
|
186
|
+
}): string;
|
|
181
187
|
/**
|
|
182
188
|
* Converts a PostgreSQL result back to JavaScript value.
|
|
183
189
|
* Handles array dimensions if configured, otherwise delegates to scalar implementation.
|
|
@@ -77,6 +77,13 @@ var Column = class {
|
|
|
77
77
|
if (!this.config.dimension) return base;
|
|
78
78
|
return `${base}${this.config.dimension.map((d) => d === null ? "[]" : `[${d}]`).join("")}`;
|
|
79
79
|
}
|
|
80
|
+
/** Returns the full PostgreSQL cast type including array dimensions, or `null` if no cast is needed. */
|
|
81
|
+
get sqlCast() {
|
|
82
|
+
const base = this.sqlCastScalar;
|
|
83
|
+
if (base === null) return null;
|
|
84
|
+
if (!this.config.dimension) return base;
|
|
85
|
+
return `${base}${this.config.dimension.map((d) => d === null ? "[]" : `[${d}]`).join("")}`;
|
|
86
|
+
}
|
|
80
87
|
get zodType() {
|
|
81
88
|
let schema = this.zodTypeScaler;
|
|
82
89
|
if (!this.config.dimension) return schema;
|
|
@@ -112,19 +119,26 @@ var Column = class {
|
|
|
112
119
|
* Converts a JavaScript value to SQL string literal.
|
|
113
120
|
* Handles array dimensions with ARRAY[...] syntax if configured.
|
|
114
121
|
*/
|
|
115
|
-
toSQL(value) {
|
|
122
|
+
toSQL(value, options) {
|
|
123
|
+
if (value === null) return "NULL";
|
|
116
124
|
if (value instanceof Sql) return value.string;
|
|
117
|
-
if (!this.config.dimension)
|
|
118
|
-
|
|
125
|
+
if (!this.config.dimension) {
|
|
126
|
+
if (!options?.cast || !this.sqlCastScalar) return this.toSQLScalar(value);
|
|
127
|
+
return `${this.toSQLScalar(value)}::${this.sqlCastScalar}`;
|
|
128
|
+
}
|
|
129
|
+
return this.#toSQLArray(value, 0, options);
|
|
119
130
|
}
|
|
120
131
|
/**
|
|
121
132
|
* Helper to recursively process multi-dimensional arrays for toSQL.
|
|
122
133
|
*/
|
|
123
|
-
#toSQLArray(arr, dimIndex) {
|
|
134
|
+
#toSQLArray(arr, dimIndex, options) {
|
|
124
135
|
const dimensions = this.config.dimension;
|
|
125
136
|
if (arr.length === 0) return "'{}'";
|
|
126
|
-
if (dimIndex >= dimensions.length - 1) return `ARRAY[${arr.map((item) =>
|
|
127
|
-
|
|
137
|
+
if (dimIndex >= dimensions.length - 1) return `ARRAY[${arr.map((item) => {
|
|
138
|
+
if (!options?.cast || !this.sqlCastScalar) return this.toSQLScalar(item);
|
|
139
|
+
return `${this.toSQLScalar(item)}::${this.sqlCastScalar}`;
|
|
140
|
+
}).join(", ")}]`;
|
|
141
|
+
return `ARRAY[${arr.map((item) => this.#toSQLArray(item, dimIndex + 1, options)).join(", ")}]`;
|
|
128
142
|
}
|
|
129
143
|
/**
|
|
130
144
|
* Converts a PostgreSQL result back to JavaScript value.
|
|
@@ -269,7 +283,7 @@ var Column = class {
|
|
|
269
283
|
* @returns an `Arg` instance with the type of this column
|
|
270
284
|
*/
|
|
271
285
|
arg() {
|
|
272
|
-
return new Arg(this.toDriver.bind(this));
|
|
286
|
+
return new Arg(this.toDriver.bind(this), this.sqlCast);
|
|
273
287
|
}
|
|
274
288
|
};
|
|
275
289
|
//#endregion
|
|
@@ -8,6 +8,7 @@ type DateConfig = ColumnConfig;
|
|
|
8
8
|
declare class DateColumn<TConfig extends DateConfig> extends Column<TConfig, DateValType> {
|
|
9
9
|
static readonly id = "Column.Date";
|
|
10
10
|
get sqlTypeScalar(): string;
|
|
11
|
+
get sqlCastScalar(): string;
|
|
11
12
|
get zodTypeScaler(): z.ZodDate;
|
|
12
13
|
toDriverScalar(value: DateValType | Sql | null): string | null;
|
|
13
14
|
toSQLScalar(value: Date | Sql | null): string;
|
|
@@ -10,6 +10,7 @@ declare class EnumedColumn<TValue extends string, TConfig extends EnumedConfig>
|
|
|
10
10
|
static readonly id = "Column.Enumed";
|
|
11
11
|
constructor(enm: Enum<TValue>, config: TConfig);
|
|
12
12
|
get sqlTypeScalar(): string;
|
|
13
|
+
get sqlCastScalar(): string;
|
|
13
14
|
get zodTypeScaler(): z.ZodEnum<{ [k_1 in TValue]: k_1 } extends infer T ? { [k in keyof T]: T[k] } : never>;
|
|
14
15
|
toDriverScalar(value: TValue | Sql | null): string | null;
|
|
15
16
|
toSQLScalar(value: TValue | Sql | null): string;
|