durcno 1.0.0-alpha.0 → 1.0.0-alpha.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.
package/README.md CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  ---
19
19
 
20
- ## Features
20
+ ## Features
21
21
 
22
22
  - **🔗 Relation Mapping** — Intuitive `many`, `one`, and `fk` relations with full type inference.
23
23
  - **🦾 Robust Migrations** — Auto-generated, reversible, and squashable migrations for production applications.
@@ -25,7 +25,7 @@
25
25
  - **🔌 Multiple Drivers** — Support for `pg`, `postgres`, `bun`, and `pglite` drivers.
26
26
  - **🌍 PostGIS Support** — First-class geographic column types for spatial queries.
27
27
 
28
- ## 📦 Setup
28
+ ## Setup
29
29
 
30
30
  ```bash
31
31
  npm install durcno
@@ -35,7 +35,7 @@ npm install durcno
35
35
  npx durcno init
36
36
  ```
37
37
 
38
- ## 🚀 Getting Started
38
+ ## Getting Started
39
39
 
40
40
  Get started with Durcno by following our comprehensive documentation.
41
41
 
@@ -45,11 +45,11 @@ Get started with Durcno by following our comprehensive documentation.
45
45
  > Durcno is currently in the alpha stage.
46
46
  > Avoid using it in any critical or large project until it reaches beta. Expect bugs and breaking changes. However, your feedback is invaluable to help us shape the future of Durcno!
47
47
 
48
- ## 🤝 Contributing
48
+ ## Contributing
49
49
 
50
50
  Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) before submitting PRs.
51
51
 
52
- ## 📄 License
52
+ ## License
53
53
 
54
54
  Apache License 2.0 - see [LICENSE](LICENSE) for details.
55
55
 
package/dist/bin.cjs CHANGED
@@ -8962,13 +8962,20 @@ async function runDownMigration(migrationDirName, isFirstMigration, migrationsDi
8962
8962
  const statements = migrationModule.statements;
8963
8963
  const options = migrationModule.options ?? {};
8964
8964
  const useTransaction = options.transaction ?? true;
8965
+ const execution = options.execution ?? "joined";
8965
8966
  if (useTransaction) {
8966
8967
  await client.query("BEGIN;");
8967
8968
  }
8968
8969
  try {
8969
8970
  if (statements.length > 0) {
8970
- const sql = `${statements.map((st) => st.toSQL()).join(";\n")};`;
8971
- await client.query(sql);
8971
+ if (execution === "sequential") {
8972
+ for (const st of statements) {
8973
+ await client.query(st.toSQL());
8974
+ }
8975
+ } else {
8976
+ const sql = `${statements.map((st) => st.toSQL()).join("\n")}`;
8977
+ await client.query(sql);
8978
+ }
8972
8979
  }
8973
8980
  if (useTransaction) {
8974
8981
  await client.query("COMMIT;");
@@ -12733,11 +12740,11 @@ var CONNECTOR_PACKAGES = {
12733
12740
  bun: []
12734
12741
  // Built-in
12735
12742
  };
12736
- var CONNECTOR_CLASS_NAMES = {
12737
- pg: "PgConnector",
12738
- postgres: "PostgresConnector",
12739
- bun: "BunConnector",
12740
- pglite: "PgLiteConnector"
12743
+ var CONNECTOR_FUNCTION_NAMES = {
12744
+ pg: "pg",
12745
+ postgres: "postgres",
12746
+ bun: "bun",
12747
+ pglite: "pglite"
12741
12748
  };
12742
12749
  var LOADER_PACKAGES = {
12743
12750
  node: ["dotenv"],
@@ -12757,15 +12764,15 @@ var pm = (() => {
12757
12764
  })();
12758
12765
  function generateConfigFile(config2) {
12759
12766
  const { connector, connectionUrl, schemaPath, migrationsDir } = config2;
12760
- const className = CONNECTOR_CLASS_NAMES[connector];
12767
+ const funcName = CONNECTOR_FUNCTION_NAMES[connector];
12761
12768
  const urlValue = connectionUrl === "" ? "process.env.DATABASE_URL!" : `"${connectionUrl}"`;
12762
12769
  const envLoader = connectionUrl === "" ? runtime === "bun" ? "" : runtime === "deno" ? `import "@std/dotenv/load";
12763
12770
  ` : `import "dotenv/config";
12764
12771
  ` : "";
12765
12772
  return `${envLoader}import { defineConfig } from "durcno";
12766
- import { ${className} } from "durcno/connectors/${connector}";
12773
+ import { ${funcName} } from "durcno/connectors/${connector}";
12767
12774
 
12768
- export default defineConfig(${className}, {
12775
+ export default defineConfig(${funcName}(), {
12769
12776
  schema: "${schemaPath}",
12770
12777
  out: "${migrationsDir}",
12771
12778
  dbCredentials: {
@@ -12789,10 +12796,10 @@ export const Users = table("public", "users", {
12789
12796
  `;
12790
12797
  }
12791
12798
  function generateIndexFile(schemaPath) {
12792
- const schemaImport = schemaPath.replace(/\.ts$/, "").replace(/^db\//, "./");
12799
+ const schemaImport = schemaPath.replace(/^db\//, "./");
12793
12800
  return `import { database } from "durcno";
12794
12801
  import * as schema from "${schemaImport}";
12795
- import setup from "../durcno.config";
12802
+ import setup from "../durcno.config.ts";
12796
12803
 
12797
12804
  export const db = database(schema, setup);
12798
12805
  `;
@@ -13052,13 +13059,20 @@ async function runUpMigration(migrationDirName, migrationsDir, client, setup) {
13052
13059
  const statements = migrationModule.statements;
13053
13060
  const options = migrationModule.options ?? {};
13054
13061
  const useTransaction = options.transaction ?? true;
13062
+ const execution = options.execution ?? "joined";
13055
13063
  if (useTransaction) {
13056
13064
  await client.query("BEGIN;");
13057
13065
  }
13058
13066
  try {
13059
13067
  if (statements.length > 0) {
13060
- const sql = `${statements.map((st) => st.toSQL()).join(";\n")};`;
13061
- await client.query(sql);
13068
+ if (execution === "sequential") {
13069
+ for (const st of statements) {
13070
+ await client.query(st.toSQL());
13071
+ }
13072
+ } else {
13073
+ const sql = `${statements.map((st) => st.toSQL()).join("\n")}`;
13074
+ await client.query(sql);
13075
+ }
13062
13076
  }
13063
13077
  if (useTransaction) {
13064
13078
  await client.query("COMMIT;");
@@ -14,5 +14,7 @@ declare class BunConnector extends Connector {
14
14
  getClient(): BunClient;
15
15
  getPool(): BunPool;
16
16
  }
17
+ /** Creates a Bun SQL connector instance. */
18
+ declare function bun(): BunConnector;
17
19
  //#endregion
18
- export { BunConnector };
20
+ export { BunConnector, bun };
@@ -18,6 +18,10 @@ var BunConnector = class extends Connector {
18
18
  return new BunPool(this.url, this.config.pool);
19
19
  }
20
20
  };
21
+ /** Creates a Bun SQL connector instance. */
22
+ function bun() {
23
+ return new BunConnector();
24
+ }
21
25
  /**
22
26
  * Single-connection client wrapper for Bun's SQL API.
23
27
  *
@@ -94,4 +98,4 @@ var BunPoolClient = class extends $Client {
94
98
  }
95
99
  };
96
100
  //#endregion
97
- export { BunConnector };
101
+ export { BunConnector, bun };
@@ -16,7 +16,8 @@ declare abstract class Connector {
16
16
  config: Config;
17
17
  /** The PostgreSQL connection URL derived from the configuration. */
18
18
  url: string;
19
- constructor(config: Config);
19
+ /** Injects the configuration and derives the connection URL. Called by `defineConfig`. */
20
+ _init(config: Config): void;
20
21
  /**
21
22
  * Creates a single-connection client.
22
23
  *
@@ -15,7 +15,8 @@ var Connector = class {
15
15
  config;
16
16
  /** The PostgreSQL connection URL derived from the configuration. */
17
17
  url;
18
- constructor(config) {
18
+ /** Injects the configuration and derives the connection URL. Called by `defineConfig`. */
19
+ _init(config) {
19
20
  this.config = config;
20
21
  this.url = getUrlFromDbCredentials(config.dbCredentials);
21
22
  }
@@ -14,5 +14,7 @@ declare class PgConnector extends Connector {
14
14
  getClient(): PgClient;
15
15
  getPool(): PgPool;
16
16
  }
17
+ /** Creates a pg (node-postgres) connector instance. */
18
+ declare function pg(): PgConnector;
17
19
  //#endregion
18
- export { PgConnector };
20
+ export { PgConnector, pg };
@@ -18,6 +18,10 @@ var PgConnector = class extends Connector {
18
18
  return new PgPool(this.url, this.config.pool);
19
19
  }
20
20
  };
21
+ /** Creates a pg (node-postgres) connector instance. */
22
+ function pg() {
23
+ return new PgConnector();
24
+ }
21
25
  /**
22
26
  * Single-connection client wrapper for the `pg` library.
23
27
  *
@@ -100,4 +104,4 @@ var PgPoolClient = class extends $Client {
100
104
  }
101
105
  };
102
106
  //#endregion
103
- export { PgConnector };
107
+ export { PgConnector, pg };
@@ -1,4 +1,5 @@
1
1
  import { Connector } from "./common.mjs";
2
+ import { PGliteOptions } from "@electric-sql/pglite";
2
3
 
3
4
  //#region src/connectors/pglite.d.ts
4
5
  /**
@@ -12,8 +13,12 @@ import { Connector } from "./common.mjs";
12
13
  * @see https://www.npmjs.com/package/@electric-sql/pglite
13
14
  */
14
15
  declare class PgLiteConnector extends Connector {
16
+ #private;
17
+ constructor(options?: PGliteOptions);
15
18
  getClient(): PgLiteClient;
16
19
  getPool(): PgLitePool;
17
20
  }
21
+ /** Creates a PgLite connector instance, optionally accepting PGlite options (e.g., extensions). */
22
+ declare function pglite(options?: PGliteOptions): PgLiteConnector;
18
23
  //#endregion
19
- export { PgLiteConnector };
24
+ export { PgLiteConnector, pglite };
@@ -12,13 +12,22 @@ import { PGlite } from "@electric-sql/pglite";
12
12
  * @see https://www.npmjs.com/package/@electric-sql/pglite
13
13
  */
14
14
  var PgLiteConnector = class extends Connector {
15
+ #options;
16
+ constructor(options) {
17
+ super();
18
+ this.#options = options;
19
+ }
15
20
  getClient() {
16
- return new PgLiteClient(this.url);
21
+ return new PgLiteClient(this.url, this.#options);
17
22
  }
18
23
  getPool() {
19
- return new PgLitePool(this.url, this.config.pool);
24
+ return new PgLitePool(this.url, this.config.pool, this.#options);
20
25
  }
21
26
  };
27
+ /** Creates a PgLite connector instance, optionally accepting PGlite options (e.g., extensions). */
28
+ function pglite(options) {
29
+ return new PgLiteConnector(options);
30
+ }
22
31
  /**
23
32
  * Single-instance client wrapper for PGlite.
24
33
  *
@@ -29,9 +38,9 @@ var PgLiteConnector = class extends Connector {
29
38
  */
30
39
  var PgLiteClient = class extends $Client {
31
40
  #client;
32
- constructor(connectionString) {
41
+ constructor(connectionString, options) {
33
42
  super();
34
- this.#client = new PGlite(connectionString);
43
+ this.#client = new PGlite(connectionString, options);
35
44
  this.query = this.#client.query.bind(this.#client);
36
45
  }
37
46
  async connect() {}
@@ -53,9 +62,9 @@ var PgLiteClient = class extends $Client {
53
62
  */
54
63
  var PgLitePool = class extends $Pool {
55
64
  #pool;
56
- constructor(connectionString, pool) {
65
+ constructor(connectionString, pool, options) {
57
66
  super();
58
- this.#pool = new PGlite(connectionString);
67
+ this.#pool = new PGlite(connectionString, options);
59
68
  this.query = this.#pool.query.bind(this.#pool);
60
69
  }
61
70
  async connect() {}
@@ -91,4 +100,4 @@ var PgLitePoolClient = class extends $Client {
91
100
  async close() {}
92
101
  };
93
102
  //#endregion
94
- export { PgLiteConnector };
103
+ export { PgLiteConnector, pglite };
@@ -14,5 +14,7 @@ declare class PostgresConnector extends Connector {
14
14
  getClient(): PostgresClient;
15
15
  getPool(): PostgresPool;
16
16
  }
17
+ /** Creates a postgres.js connector instance. */
18
+ declare function postgres(): PostgresConnector;
17
19
  //#endregion
18
- export { PostgresConnector };
20
+ export { PostgresConnector, postgres };
@@ -1,5 +1,5 @@
1
1
  import { $Client, $Pool, Connector } from "./common.mjs";
2
- import postgres from "postgres";
2
+ import postgresLib from "postgres";
3
3
  //#region src/connectors/postgres.ts
4
4
  /**
5
5
  * Connector implementation for the `postgres` (postgres.js) library.
@@ -18,6 +18,10 @@ var PostgresConnector = class extends Connector {
18
18
  return new PostgresPool(this.url, this.config.pool);
19
19
  }
20
20
  };
21
+ /** Creates a postgres.js connector instance. */
22
+ function postgres() {
23
+ return new PostgresConnector();
24
+ }
21
25
  /**
22
26
  * Single-connection client wrapper for postgres.js.
23
27
  *
@@ -30,7 +34,7 @@ var PostgresClient = class extends $Client {
30
34
  #sql;
31
35
  constructor(connectionString) {
32
36
  super();
33
- this.#sql = postgres(connectionString, { max: 1 });
37
+ this.#sql = postgresLib(connectionString, { max: 1 });
34
38
  this.query = this.#sql.unsafe.bind(this.#sql);
35
39
  }
36
40
  async connect() {}
@@ -53,7 +57,7 @@ var PostgresPool = class extends $Pool {
53
57
  #sql;
54
58
  constructor(connectionString, pool) {
55
59
  super();
56
- this.#sql = postgres(connectionString, { max: pool?.max ?? 10 });
60
+ this.#sql = postgresLib(connectionString, { max: pool?.max ?? 10 });
57
61
  this.query = this.#sql.unsafe.bind(this.#sql);
58
62
  }
59
63
  async connect() {}
@@ -90,4 +94,4 @@ var PostgresPoolClient = class extends $Client {
90
94
  }
91
95
  };
92
96
  //#endregion
93
- export { PostgresConnector };
97
+ export { PostgresConnector, postgres };
package/dist/src/db.d.mts CHANGED
@@ -28,7 +28,6 @@ declare class Base<TTName extends string, TTables extends Record<TTName, TableWi
28
28
  tables: TTables;
29
29
  allRelations: TAllRelations;
30
30
  config: Config;
31
- dbUrl: string;
32
31
  pre: TPrepare;
33
32
  };
34
33
  constructor(tables: TTables, allRelations: TAllRelations, executor: QueryExecutor | null, connector: Connector, prepare: TPrepare);
package/dist/src/db.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { is } from "./entity.mjs";
2
- import { getUrlFromDbCredentials } from "./cli/helpers.mjs";
3
2
  import { AggregateQuery } from "./query-builders/aggregates.mjs";
4
3
  import { CountQuery } from "./query-builders/count.mjs";
5
4
  import { DeleteQuery } from "./query-builders/delete.mjs";
@@ -33,7 +32,6 @@ var Base = class {
33
32
  tables,
34
33
  allRelations,
35
34
  config: connector.config,
36
- dbUrl: getUrlFromDbCredentials(connector.config.dbCredentials),
37
35
  pre: prepare
38
36
  };
39
37
  }
@@ -61,18 +61,18 @@ type DurcnoSetup<T extends Connector = Connector> = {
61
61
  * Define a Durcno configuration.
62
62
  *
63
63
  * This is the recommended way to create your `durcno.config.ts` file.
64
- * Pass the connector class for your database driver and the configuration options.
64
+ * Pass a connector instance for your database driver and the configuration options.
65
65
  *
66
- * @param Connector - The connector class to use (e.g., `PgConnector`, `PostgresConnector`, `BunConnector`, `PgLiteConnector`).
66
+ * @param connector - The connector instance to use (e.g., `pg()`, `postgres()`, `bun()`, `pglite()`).
67
67
  * @param config - The database configuration including connection credentials and pool settings.
68
68
  * @returns A setup object containing the connector instance and the config options.
69
69
  *
70
70
  * @example
71
71
  * ```typescript
72
72
  * import { defineConfig } from "durcno";
73
- * import { PgConnector } from "durcno/connectors/pg";
73
+ * import { pg } from "durcno/connectors/pg";
74
74
  *
75
- * export default defineConfig(PgConnector, {
75
+ * export default defineConfig(pg(), {
76
76
  * schema: "db/schema.ts",
77
77
  * out: "migrations",
78
78
  * dbCredentials: {
@@ -81,7 +81,7 @@ type DurcnoSetup<T extends Connector = Connector> = {
81
81
  * });
82
82
  * ```
83
83
  */
84
- declare function defineConfig<T extends Connector>(ConnectorClass: new (config: Config) => T, config: Config): DurcnoSetup<T>;
84
+ declare function defineConfig<T extends Connector>(connector: T, config: Config): DurcnoSetup<T>;
85
85
  type Config = {
86
86
  /**
87
87
  * The relative path to the database schema file.
@@ -48,18 +48,18 @@ const $ = {
48
48
  * Define a Durcno configuration.
49
49
  *
50
50
  * This is the recommended way to create your `durcno.config.ts` file.
51
- * Pass the connector class for your database driver and the configuration options.
51
+ * Pass a connector instance for your database driver and the configuration options.
52
52
  *
53
- * @param Connector - The connector class to use (e.g., `PgConnector`, `PostgresConnector`, `BunConnector`, `PgLiteConnector`).
53
+ * @param connector - The connector instance to use (e.g., `pg()`, `postgres()`, `bun()`, `pglite()`).
54
54
  * @param config - The database configuration including connection credentials and pool settings.
55
55
  * @returns A setup object containing the connector instance and the config options.
56
56
  *
57
57
  * @example
58
58
  * ```typescript
59
59
  * import { defineConfig } from "durcno";
60
- * import { PgConnector } from "durcno/connectors/pg";
60
+ * import { pg } from "durcno/connectors/pg";
61
61
  *
62
- * export default defineConfig(PgConnector, {
62
+ * export default defineConfig(pg(), {
63
63
  * schema: "db/schema.ts",
64
64
  * out: "migrations",
65
65
  * dbCredentials: {
@@ -68,9 +68,10 @@ const $ = {
68
68
  * });
69
69
  * ```
70
70
  */
71
- function defineConfig(ConnectorClass, config) {
71
+ function defineConfig(connector, config) {
72
+ connector._init(config);
72
73
  return {
73
- connector: new ConnectorClass(config),
74
+ connector,
74
75
  config
75
76
  };
76
77
  }
@@ -10,6 +10,8 @@ import { ddl } from "./ddl.mjs";
10
10
  interface MigrationOptions {
11
11
  /** Whether to wrap statements in BEGIN...COMMIT (default: true) */
12
12
  transaction?: boolean;
13
+ /** How to execute statements: 'joined' runs all as a single query, 'sequential' runs one at a time (default: 'joined') */
14
+ execution?: "joined" | "sequential";
13
15
  }
14
16
  //#endregion
15
17
  export { CustomStatement, DDLStatement, MIGRATION_NAME_REGEX, MigrationOptions, type Snapshot, type SnapshotColumn, type SnapshotColumnRef, type SnapshotEnum, type SnapshotSequence, type SnapshotTable, type SnapshotTableCheck, type SnapshotTableIndex, type SnapshotTablePrimaryKey, type SnapshotTableUnique, createEmptySnapshot, ddl, snapshot };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "durcno",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.1",
4
4
  "description": "A PostgreSQL Query Builder and Migration Manager for TypeScript, from the future.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://durcno.dev",
7
7
  "keywords": [
8
8
  "durcno",
9
9
  "query",
10
+ "query-builder",
10
11
  "sql",
11
12
  "ts",
12
13
  "typescript",
@@ -27,7 +28,7 @@
27
28
  },
28
29
  "type": "module",
29
30
  "engines": {
30
- "node": ">=25.8.0"
31
+ "node": ">=24.14.0"
31
32
  },
32
33
  "files": [
33
34
  "dist"