@telorun/sql 0.22.1 → 0.23.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.
@@ -6,8 +6,8 @@ import type { SqlConnection, SqlDialect } from "./sql-connection.js";
6
6
  * scoping, template binding and row-count normalization over a kysely instance.
7
7
  *
8
8
  * Backends extend it, supply their {@link SqlDialect}, and override only what is
9
- * genuinely theirs — `teardown` for resources kysely does not own, `executeScript`
10
- * where the driver has a native multi-statement path.
9
+ * genuinely theirs — extending `init`'s effect chain for resources kysely does
10
+ * not own, `executeScript` where the driver has a native multi-statement path.
11
11
  */
12
12
  export declare abstract class SqlConnectionBase implements SqlConnection {
13
13
  #private;
@@ -16,8 +16,10 @@ export declare abstract class SqlConnectionBase implements SqlConnection {
16
16
  protected readonly db: Kysely<any>;
17
17
  constructor(db: Kysely<any>, dialect: SqlDialect, ctx: ResourceContext);
18
18
  get kysely(): Kysely<any>;
19
- init(): Promise<void>;
20
- teardown(): Promise<void>;
19
+ /** The pool, and what destroys it. A backend that allocates more extends this
20
+ * chain rather than overriding a separate teardown — so the two halves cannot
21
+ * drift out of order. */
22
+ init(ctx: ResourceContext): import("@telorun/sdk").EffectChain<undefined>;
21
23
  runInTransaction<T>(body: (bind: (entry: ZoneEntry) => void) => Promise<T>): Promise<T>;
22
24
  hasOpenTransaction(ctx?: InvokeContext): boolean;
23
25
  bindsZone(zone: ZoneEntry): boolean;
@@ -5,8 +5,8 @@ import { CompiledQuery } from "kysely";
5
5
  * scoping, template binding and row-count normalization over a kysely instance.
6
6
  *
7
7
  * Backends extend it, supply their {@link SqlDialect}, and override only what is
8
- * genuinely theirs — `teardown` for resources kysely does not own, `executeScript`
9
- * where the driver has a native multi-statement path.
8
+ * genuinely theirs — extending `init`'s effect chain for resources kysely does
9
+ * not own, `executeScript` where the driver has a native multi-statement path.
10
10
  */
11
11
  export class SqlConnectionBase {
12
12
  dialect;
@@ -26,14 +26,17 @@ export class SqlConnectionBase {
26
26
  get kysely() {
27
27
  return this.db;
28
28
  }
29
- async init() {
30
- await this.db.connection().execute(async () => {
31
- // just checking
29
+ /** The pool, and what destroys it. A backend that allocates more extends this
30
+ * chain rather than overriding a separate teardown — so the two halves cannot
31
+ * drift out of order. */
32
+ init(ctx) {
33
+ return ctx.effect("connection pool", async () => {
34
+ await this.db.connection().execute(async () => {
35
+ // just checking
36
+ });
37
+ return { result: undefined, inverse: () => this.db.destroy() };
32
38
  });
33
39
  }
34
- async teardown() {
35
- await this.db.destroy();
36
- }
37
40
  async runInTransaction(body) {
38
41
  this.ctx.log.debug("Transaction started");
39
42
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/sql",
3
- "version": "0.22.1",
3
+ "version": "0.23.0",
4
4
  "description": "Telo SQL module - SQL database resource kinds for Telo manifests.",
5
5
  "keywords": [
6
6
  "telo",
@@ -44,7 +44,7 @@
44
44
  "esbuild": "^0.25.12",
45
45
  "typescript": "^5.0.0",
46
46
  "vitest": "^2.1.8",
47
- "@telorun/sdk": "0.80.0"
47
+ "@telorun/sdk": "0.82.0"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@telorun/sdk": "*"
@@ -13,8 +13,8 @@ import type { SqlConnection, SqlDialect } from "./sql-connection.js";
13
13
  * scoping, template binding and row-count normalization over a kysely instance.
14
14
  *
15
15
  * Backends extend it, supply their {@link SqlDialect}, and override only what is
16
- * genuinely theirs — `teardown` for resources kysely does not own, `executeScript`
17
- * where the driver has a native multi-statement path.
16
+ * genuinely theirs — extending `init`'s effect chain for resources kysely does
17
+ * not own, `executeScript` where the driver has a native multi-statement path.
18
18
  */
19
19
  export abstract class SqlConnectionBase implements SqlConnection {
20
20
  protected readonly db: Kysely<any>;
@@ -38,16 +38,18 @@ export abstract class SqlConnectionBase implements SqlConnection {
38
38
  return this.db;
39
39
  }
40
40
 
41
- async init(): Promise<void> {
42
- await this.db.connection().execute(async () => {
43
- // just checking
41
+ /** The pool, and what destroys it. A backend that allocates more extends this
42
+ * chain rather than overriding a separate teardown — so the two halves cannot
43
+ * drift out of order. */
44
+ init(ctx: ResourceContext) {
45
+ return ctx.effect("connection pool", async () => {
46
+ await this.db.connection().execute(async () => {
47
+ // just checking
48
+ });
49
+ return { result: undefined, inverse: () => this.db.destroy() };
44
50
  });
45
51
  }
46
52
 
47
- async teardown(): Promise<void> {
48
- await this.db.destroy();
49
- }
50
-
51
53
  async runInTransaction<T>(
52
54
  body: (bind: (entry: ZoneEntry) => void) => Promise<T>,
53
55
  ): Promise<T> {