@shivaedev/effect-prisma 0.4.3 → 0.5.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 (35) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +37 -0
  3. package/dist/database.d.ts +8 -27
  4. package/dist/database.d.ts.map +1 -1
  5. package/dist/database.js +29 -78
  6. package/dist/database.js.map +1 -1
  7. package/dist/internal/database-factory.d.ts +46 -0
  8. package/dist/internal/database-factory.d.ts.map +1 -0
  9. package/dist/internal/database-factory.js +56 -0
  10. package/dist/internal/database-factory.js.map +1 -0
  11. package/dist/internal/executor.d.ts +16 -5
  12. package/dist/internal/executor.d.ts.map +1 -1
  13. package/dist/internal/sqlite-datetime.d.ts +31 -0
  14. package/dist/internal/sqlite-datetime.d.ts.map +1 -0
  15. package/dist/internal/sqlite-datetime.js +66 -0
  16. package/dist/internal/sqlite-datetime.js.map +1 -0
  17. package/dist/internal/sqlite-pragmas.d.ts +16 -0
  18. package/dist/internal/sqlite-pragmas.d.ts.map +1 -0
  19. package/dist/internal/sqlite-pragmas.js +34 -0
  20. package/dist/internal/sqlite-pragmas.js.map +1 -0
  21. package/dist/internal/transaction.d.ts +7 -6
  22. package/dist/internal/transaction.d.ts.map +1 -1
  23. package/dist/internal/transaction.js.map +1 -1
  24. package/dist/sqlite.d.ts +28 -0
  25. package/dist/sqlite.d.ts.map +1 -0
  26. package/dist/sqlite.js +41 -0
  27. package/dist/sqlite.js.map +1 -0
  28. package/package.json +11 -2
  29. package/src/database.ts +54 -204
  30. package/src/internal/database-factory.ts +209 -0
  31. package/src/internal/executor.ts +17 -5
  32. package/src/internal/sqlite-datetime.ts +95 -0
  33. package/src/internal/sqlite-pragmas.ts +41 -0
  34. package/src/internal/transaction.ts +11 -8
  35. package/src/sqlite.ts +108 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.5.0 - 2026-08-12
6
+
7
+ ### Added
8
+
9
+ - Experimental SQLite support through `@shivaedev/effect-prisma/sqlite`.
10
+ `makeSqliteDatabase` owns a Prisma Next SQLite client, applies connect-time
11
+ pragmas (`journal_mode=WAL` by default), and serves the same queries,
12
+ implicitly scoped transactions, Streams, and always-rollback test harness as
13
+ the PostgreSQL entrypoint. In-memory databases are rejected because
14
+ transactions run on their own connection.
15
+ - SQLite `DateTime` values stored without a zone designator — the form
16
+ `datetime('now')` column defaults write — now decode as UTC instead of local
17
+ time, so generated defaults read back as the instant SQLite wrote.
18
+
5
19
  ## 0.4.3 - 2026-08-03
6
20
 
7
21
  ### Fixed
package/README.md CHANGED
@@ -40,6 +40,43 @@ export const DatabaseLive = Database.layer({
40
40
 
41
41
  The Layer owns the PostgreSQL client and closes it with its Effect scope.
42
42
 
43
+ ## SQLite (experimental)
44
+
45
+ A SQLite contract emitted with `@prisma-next/sqlite` uses the same API through a
46
+ separate entrypoint. Its `DateTime` fields already declare `Date`, so the
47
+ normalization step above is PostgreSQL-only.
48
+
49
+ ```ts
50
+ import { makeSqliteDatabase } from "@shivaedev/effect-prisma/sqlite"
51
+ import { contractJson, type Contract } from "./generated/contract.js"
52
+
53
+ export const Database = makeSqliteDatabase<Contract>("@app/Database", {
54
+ contractJson,
55
+ })
56
+
57
+ export const DatabaseLive = Database.layer({
58
+ path: "app.db",
59
+ })
60
+ ```
61
+
62
+ The Layer applies `journal_mode=WAL` when it connects; pass `pragmas` to change
63
+ that list. Prisma Next's SQLite driver already sets `foreign_keys` and
64
+ `busy_timeout` on every connection it opens, and it opens a separate connection
65
+ per transaction, so in-memory databases are rejected.
66
+
67
+ That driver is synchronous. Queries block the event loop while they run, and
68
+ because SQLite allows a single writer, overlapping write transactions wait for
69
+ `busy_timeout` before failing with a transient `PrismaConnectionFailure`.
70
+ Serialize write transactions in the application.
71
+
72
+ SQLite stores `DateTime` as text, and `prisma-next db init` generates
73
+ `DEFAULT (datetime('now'))`, which writes a UTC instant without a zone
74
+ designator. The entrypoint decodes zone-less datetime text as UTC, so generated
75
+ column defaults round-trip to the instant SQLite wrote without hand-editing the
76
+ DDL. Values that already carry `Z` or a numeric offset decode unchanged.
77
+ `datetime('now')` itself stores whole seconds; write
78
+ `strftime('%Y-%m-%dT%H:%M:%fZ', 'now')` where a default needs milliseconds.
79
+
43
80
  ## Queries
44
81
 
45
82
  Yield the database service once and use generated models directly:
@@ -1,40 +1,21 @@
1
- import { type PostgresClient, type PostgresOptionsBase } from "@prisma-next/postgres/runtime";
2
- import { Context, Effect, Layer, Redacted } from "effect";
1
+ import { type PostgresOptionsBase } from "@prisma-next/postgres/runtime";
2
+ import { type Layer, Redacted } from "effect";
3
3
  import type { PrismaError } from "./error.js";
4
- import type { AnyPostgresContract, ExecutorIdentifier } from "./internal/executor.js";
5
- import type { Relation } from "./relation.js";
6
- type ClientFor<Contract extends AnyPostgresContract> = PostgresClient<Contract>;
7
- type OrmFor<Contract extends AnyPostgresContract> = ClientFor<Contract>["orm"];
8
- type DefaultNamespaceId<Contract extends AnyPostgresContract> = "__unbound__" extends keyof OrmFor<Contract> ? "__unbound__" : "public" extends keyof OrmFor<Contract> ? "public" : keyof OrmFor<Contract>;
9
- type DefaultModels<Contract extends AnyPostgresContract> = OrmFor<Contract>[DefaultNamespaceId<Contract>] extends infer Models extends object ? Models : never;
10
- interface DatabaseIdentifier<Contract extends AnyPostgresContract> {
11
- readonly _contract: Contract;
12
- readonly _databaseIdentifier: unique symbol;
13
- }
14
- type DatabaseModels<Contract extends AnyPostgresContract, Requirement> = {
15
- readonly [Model in keyof DefaultModels<Contract>]: Relation<DefaultModels<Contract>[Model], Requirement, Contract, Model & string>;
16
- };
17
- export type DatabaseService<Contract extends AnyPostgresContract, Requirement> = DatabaseModels<Contract, Requirement> & {
18
- transaction<A, E, R>(program: Effect.Effect<A, E, R>): Effect.Effect<A, E | PrismaError, R | Requirement>;
19
- };
4
+ import { type DatabaseIdentifier, type DatabaseServiceHolder, type DefaultModels } from "./internal/database-factory.js";
5
+ import type { AnySqlContract, ExecutorIdentifier } from "./internal/executor.js";
6
+ export type { AnyDatabase, DatabaseRequirement, DatabaseService, DatabaseServiceOf, } from "./internal/database-factory.js";
20
7
  export interface DatabaseLayerOptions extends PostgresOptionsBase {
21
8
  readonly url: string | Redacted.Redacted<string>;
22
9
  }
23
- type DatabaseFactoryOptions<Contract extends AnyPostgresContract> = {
10
+ type DatabaseFactoryOptions<Contract extends AnySqlContract> = {
24
11
  readonly contract: Contract;
25
12
  readonly contractJson?: never;
26
13
  } | {
27
14
  readonly contractJson: unknown;
28
15
  readonly contract?: never;
29
16
  };
30
- export interface DatabaseDefinition<Contract extends AnyPostgresContract, Requirement = ExecutorIdentifier<DefaultModels<Contract>>> extends Context.Service<DatabaseIdentifier<Contract>, DatabaseService<Contract, Requirement>> {
17
+ export interface DatabaseDefinition<Contract extends AnySqlContract, Requirement = ExecutorIdentifier<DefaultModels<Contract>>> extends DatabaseServiceHolder<Contract, Requirement> {
31
18
  readonly layer: (options: DatabaseLayerOptions) => Layer.Layer<DatabaseIdentifier<Contract> | Requirement, PrismaError>;
32
19
  }
33
- export type AnyDatabase = Effect.Effect<unknown, never, unknown> & {
34
- readonly layer: (...arguments_: ReadonlyArray<never>) => Layer.Any;
35
- };
36
- export type DatabaseRequirement<Database> = Database extends DatabaseDefinition<AnyPostgresContract, infer Requirement> ? Requirement : never;
37
- export type DatabaseServiceOf<Database extends AnyDatabase> = Effect.Success<Database>;
38
- export declare const makeDatabase: <const Contract extends AnyPostgresContract>(identifier: string, options: DatabaseFactoryOptions<Contract>) => DatabaseDefinition<Contract>;
39
- export {};
20
+ export declare const makeDatabase: <const Contract extends AnySqlContract>(identifier: string, options: DatabaseFactoryOptions<Contract>) => DatabaseDefinition<Contract>;
40
21
  //# sourceMappingURL=database.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAiB,EAChB,KAAK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AM,CAAC,CAAC;CACjD;AAED,KAAK,sBAAsB,CAAC,QAAQ,SAAS,cAAc,IACxD;IACA,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC;CAC7B,GACD;IACA,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC;CACzB,CAAC;AAEL,MAAM,WAAW,kBAAkB,CAClC,QAAQ,SAAS,cAAc,EAC/B,WAAW,GAAG,kBAAkB,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CACxD,SAAQ,qBAAqB,CAAC,QAAQ,EAAE,WAAW,CAAC;IACrD,QAAQ,CAAC,KAAK,EAAE,CACf,OAAO,EAAE,oBAAoB,KACzB,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAQ,CAAC,GAAG,WAAW,EAAE,WAAW,CAAC,CAAC;CAC1E;AAMD,eAAO,MAAM,YAAY,GAAI,KAAK,CAAC,QAAQ,SAAS,cAAc,EACjE,YAAY,MAAM,EAClB,SAAS,sBAAsB,CAAC,QAAQ,CAAC,KACvC,kBAAkB,CAAC,QAAQ,CAqC7B,CAAC"}
package/dist/database.js CHANGED
@@ -1,84 +1,35 @@
1
1
  import postgres, {} from "@prisma-next/postgres/runtime";
2
- import { Context, Effect, Layer, Redacted } from "effect";
3
- import { acquireConnectedClient, assertAvailableModelNames, } from "./internal/client-lifecycle.js";
2
+ import { Redacted } from "effect";
3
+ import { acquireConnectedClient } from "./internal/client-lifecycle.js";
4
+ import { makeSqlDatabase, namespaceModels, } from "./internal/database-factory.js";
4
5
  import { fromPrismaPromise } from "./internal/promise.js";
5
- import { makeModelRelation } from "./internal/relation-runtime.js";
6
- import { DatabaseTestingTypeId } from "./internal/testing.js";
7
- import { acquireTransaction, releaseTestTransaction, releaseTransaction, } from "./internal/transaction.js";
8
- const defaultModels = (client) => {
9
- const namespaces = Object.keys(client.contract.domain.namespaces);
10
- if (namespaces.length !== 1 || namespaces[0] === undefined) {
11
- throw new TypeError("Effect Prisma currently requires exactly one domain namespace");
12
- }
13
- assertAvailableModelNames(Object.keys(client.contract.domain.namespaces[namespaces[0]].models));
14
- return Reflect.get(client.orm, namespaces[0]);
15
- };
6
+ const defaultModels = (client) => namespaceModels(client.contract, client.orm);
16
7
  export const makeDatabase = (identifier, options) => {
17
- const Executor = Context.Service(`${identifier}/Executor`);
18
- const Service = Context.Service(identifier);
19
- const transaction = (program) => Effect.flatMap(Executor, (current) => {
20
- if (current.transactional) {
21
- return program;
22
- }
23
- return Effect.acquireUseRelease(acquireTransaction(current, (transactionOrm) => defaultModels({
24
- contract: current.client.contract,
25
- orm: transactionOrm,
26
- })), (resource) => program.pipe(Effect.provideService(Executor, resource.executor)), releaseTransaction).pipe(Effect.withSpan("prisma.transaction", { kind: "client" }));
27
- });
28
- const withTestTransaction = (program) => Effect.flatMap(Executor, (current) => {
29
- if (current.transactional) {
30
- return program;
31
- }
32
- return Effect.acquireUseRelease(acquireTransaction(current, (transactionOrm) => defaultModels({
33
- contract: current.client.contract,
34
- orm: transactionOrm,
35
- })), (resource) => program.pipe(Effect.provideService(Executor, resource.executor)), releaseTestTransaction).pipe(Effect.withSpan("prisma.testTransaction", { kind: "client" }));
36
- });
37
- const facade = new Proxy(Object.assign(Object.create(null), {
38
- transaction,
39
- }), {
40
- get(target, property, receiver) {
41
- if (Reflect.has(target, property)) {
42
- return Reflect.get(target, property, receiver);
43
- }
44
- if (typeof property !== "string") {
45
- return undefined;
46
- }
47
- return makeModelRelation(Executor, property);
48
- },
49
- });
50
- const layer = (layerOptions) => {
51
- const acquire = Effect.acquireRelease(Effect.suspend(() => {
52
- const clientOptions = {
53
- url: typeof layerOptions.url === "string"
54
- ? layerOptions.url
55
- : Redacted.value(layerOptions.url),
56
- extensions: layerOptions.extensions,
57
- middleware: layerOptions.middleware,
58
- poolOptions: layerOptions.poolOptions,
59
- verifyMarker: layerOptions.verifyMarker,
60
- };
61
- const client = options.contract === undefined
62
- ? postgres({
63
- ...clientOptions,
64
- contractJson: options.contractJson,
65
- })
66
- : postgres({
67
- ...clientOptions,
68
- contract: options.contract,
69
- });
70
- return fromPrismaPromise(() => acquireConnectedClient(client, () => ({
71
- client,
72
- models: defaultModels(client),
73
- querySemaphore: undefined,
74
- transactional: false,
75
- })));
76
- }), (executor) => Effect.promise(() => executor.client.close()).pipe(Effect.orDie));
77
- return Layer.effectContext(Effect.map(acquire, (executor) => Context.make(Executor, executor).pipe(Context.add(Service, facade))));
78
- };
79
- return Object.assign(Service, {
80
- layer,
81
- [DatabaseTestingTypeId]: { withTestTransaction },
8
+ return makeSqlDatabase(identifier, (layerOptions) => {
9
+ const clientOptions = {
10
+ url: typeof layerOptions.url === "string"
11
+ ? layerOptions.url
12
+ : Redacted.value(layerOptions.url),
13
+ extensions: layerOptions.extensions,
14
+ middleware: layerOptions.middleware,
15
+ poolOptions: layerOptions.poolOptions,
16
+ verifyMarker: layerOptions.verifyMarker,
17
+ };
18
+ const client = options.contract === undefined
19
+ ? postgres({
20
+ ...clientOptions,
21
+ contractJson: options.contractJson,
22
+ })
23
+ : postgres({
24
+ ...clientOptions,
25
+ contract: options.contract,
26
+ });
27
+ return fromPrismaPromise(() => acquireConnectedClient(client, () => ({
28
+ client,
29
+ models: defaultModels(client),
30
+ querySemaphore: undefined,
31
+ transactional: false,
32
+ })));
82
33
  });
83
34
  };
84
35
  //# sourceMappingURL=database.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,EAAE,EAGhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE1D,OAAO,EACN,sBAAsB,EACtB,yBAAyB,GACzB,MAAM,gCAAgC,CAAC;AAMxC,OAAO,EAAE,i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AQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;AAE5E,MAAM,CAAC,MAAM,YAAY,GAAG,CAC3B,UAAkB,EAClB,OAAyC,EACV,EAAE;IAGjC,OAAO,eAAe,CACrB,UAAU,EACV,CAAC,YAAY,EAAE,EAAE;QAChB,MAAM,aAAa,GAAG;YACrB,GAAG,EACF,OAAO,YAAY,CAAC,GAAG,KAAK,QAAQ;gBACnC,CAAC,CAAC,YAAY,CAAC,GAAG;gBAClB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC;YACpC,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,UAAU,EAAE,YAAY,CAAC,UAAU;YACnC,WAAW,EAAE,YAAY,CAAC,WAAW;YACrC,YAAY,EAAE,YAAY,CAAC,YAAY;SACvC,CAAC;QACF,MAAM,MAAM,GACX,OAAO,CAAC,QAAQ,KAAK,SAAS;YAC7B,CAAC,CAAC,QAAQ,CAAW;gBACnB,GAAG,aAAa;gBAChB,YAAY,EAAE,OAAO,CAAC,YAAY;aAClC,CAAC;YACH,CAAC,CAAC,QAAQ,CAAW;gBACnB,GAAG,aAAa;gBAChB,QAAQ,EAAE,OAAO,CAAC,QAAQ;aAC1B,CAAC,CAAC;QAEN,OAAO,iBAAiB,CAAC,GAAG,EAAE,CAC7B,sBAAsB,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YACrC,MAAM;YACN,MAAM,EAAE,aAAa,CAAmB,MAAM,CAAC;YAC/C,cAAc,EAAE,SAAS;YACzB,aAAa,EAAE,KAAK;SACpB,CAAC,CAAC,CACH,CAAC;IACH,CAAC,CAC+B,CAAC;AACnC,CAAC,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { orm } from "@prisma-next/sql-orm-client";
2
+ import { Context, Effect, Layer } from "effect";
3
+ import type { PrismaError } from "../error.js";
4
+ import type { Relation } from "../relation.js";
5
+ import type { AnySqlContract, DatabaseExecutor, ExecutorIdentifier } from "./executor.js";
6
+ import { type TransactionOrm } from "./transaction.js";
7
+ type OrmFor<Contract extends AnySqlContract> = ReturnType<typeof orm<Contract>>;
8
+ type DefaultNamespaceId<Contract extends AnySqlContract> = "__unbound__" extends keyof OrmFor<Contract> ? "__unbound__" : "public" extends keyof OrmFor<Contract> ? "public" : keyof OrmFor<Contract>;
9
+ export type DefaultModels<Contract extends AnySqlContract> = OrmFor<Contract>[DefaultNamespaceId<Contract>] extends infer Models extends object ? Models : never;
10
+ export interface DatabaseIdentifier<Contract extends AnySqlContract> {
11
+ readonly _contract: Contract;
12
+ readonly _databaseIdentifier: unique symbol;
13
+ }
14
+ type DatabaseModels<Contract extends AnySqlContract, Requirement> = {
15
+ readonly [Model in keyof DefaultModels<Contract>]: Relation<DefaultModels<Contract>[Model], Requirement, Contract, Model & string>;
16
+ };
17
+ export type DatabaseService<Contract extends AnySqlContract, Requirement> = DatabaseModels<Contract, Requirement> & {
18
+ transaction<A, E, R>(program: Effect.Effect<A, E, R>): Effect.Effect<A, E | PrismaError, R | Requirement>;
19
+ };
20
+ /**
21
+ * The driver-independent part of a database definition: the Context service
22
+ * carrying the typed facade. Driver entrypoints add their own `layer` options.
23
+ */
24
+ export interface DatabaseServiceHolder<Contract extends AnySqlContract, Requirement = ExecutorIdentifier<DefaultModels<Contract>>> extends Context.Service<DatabaseIdentifier<Contract>, DatabaseService<Contract, Requirement>> {
25
+ }
26
+ export type AnyDatabase = Effect.Effect<unknown, never, unknown> & {
27
+ readonly layer: (...arguments_: ReadonlyArray<never>) => Layer.Any;
28
+ };
29
+ export type DatabaseRequirement<Database> = Database extends DatabaseServiceHolder<AnySqlContract, infer Requirement> ? Requirement : never;
30
+ export type DatabaseServiceOf<Database extends AnyDatabase> = Effect.Success<Database>;
31
+ export interface SqlDatabase<Contract extends AnySqlContract, Options> extends DatabaseServiceHolder<Contract> {
32
+ readonly layer: (options: Options) => Layer.Layer<DatabaseIdentifier<Contract> | ExecutorIdentifier<DefaultModels<Contract>>, PrismaError>;
33
+ }
34
+ /**
35
+ * Resolve the models of the single domain namespace from a namespaced ORM
36
+ * client. Prisma Next namespaces PostgreSQL models under their schema and
37
+ * SQLite models under the unbound namespace.
38
+ */
39
+ export declare const namespaceModels: <Contract extends AnySqlContract, Models extends object>(contract: Contract, namespacedOrm: TransactionOrm<Contract>) => Models;
40
+ /**
41
+ * Assemble the database service, its Executor service, and its Layer around a
42
+ * driver-specific executor acquisition.
43
+ */
44
+ export declare const makeSqlDatabase: <const Contract extends AnySqlContract, Options>(identifier: string, acquireExecutor: (options: Options) => Effect.Effect<DatabaseExecutor<DefaultModels<Contract>, Contract>, PrismaError>) => SqlDatabase<Contract, Options>;
45
+ export {};
46
+ //# sourceMappingURL=database-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-factory.d.ts","sourceRoot":"","sources":["../../src/internal/database-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAIN,KAAK,cAAc,EACnB,MAAM,kBAAkB,CAAC;AAE1B,KAAK,MAAM,CAAC,QAAQ,SAAS,cAAc,IAAI,UAAU,CAAC,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;AAChF,KAAK,kBAAkB,CAAC,QAAQ,SAAS,cAAc,IACtD,aAAa,SAAS,MAAM,MAAM,CAAC,QAAQ,CAAC,GACzC,aAAa,GACb,QAAQ,SAAS,MAAM,MAAM,CAAC,QAAQ,CAAC,GACtC,QAAQ,GACR,MAAM,MAAM,CAA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effect";
2
+ import { assertAvailableModelNames } from "./client-lifecycle.js";
3
+ import { makeModelRelation } from "./relation-runtime.js";
4
+ import { DatabaseTestingTypeId } from "./testing.js";
5
+ import { acquireTransaction, releaseTestTransaction, releaseTransaction, } from "./transaction.js";
6
+ /**
7
+ * Resolve the models of the single domain namespace from a namespaced ORM
8
+ * client. Prisma Next namespaces PostgreSQL models under their schema and
9
+ * SQLite models under the unbound namespace.
10
+ */
11
+ export const namespaceModels = (contract, namespacedOrm) => {
12
+ const namespaces = Object.keys(contract.domain.namespaces);
13
+ if (namespaces.length !== 1 || namespaces[0] === undefined) {
14
+ throw new TypeError("Effect Prisma currently requires exactly one domain namespace");
15
+ }
16
+ assertAvailableModelNames(Object.keys(contract.domain.namespaces[namespaces[0]].models));
17
+ return Reflect.get(namespacedOrm, namespaces[0]);
18
+ };
19
+ /**
20
+ * Assemble the database service, its Executor service, and its Layer around a
21
+ * driver-specific executor acquisition.
22
+ */
23
+ export const makeSqlDatabase = (identifier, acquireExecutor) => {
24
+ const Executor = Context.Service(`${identifier}/Executor`);
25
+ const Service = Context.Service(identifier);
26
+ const scopedTransaction = (release, span) => (program) => Effect.flatMap(Executor, (current) => {
27
+ if (current.transactional) {
28
+ return program;
29
+ }
30
+ return Effect.acquireUseRelease(acquireTransaction(current, (transactionOrm) => namespaceModels(current.client.contract, transactionOrm)), (resource) => program.pipe(Effect.provideService(Executor, resource.executor)), release).pipe(Effect.withSpan(span, { kind: "client" }));
31
+ });
32
+ const transaction = scopedTransaction(releaseTransaction, "prisma.transaction");
33
+ const withTestTransaction = scopedTransaction(releaseTestTransaction, "prisma.testTransaction");
34
+ const facade = new Proxy(Object.assign(Object.create(null), {
35
+ transaction,
36
+ }), {
37
+ get(target, property, receiver) {
38
+ if (Reflect.has(target, property)) {
39
+ return Reflect.get(target, property, receiver);
40
+ }
41
+ if (typeof property !== "string") {
42
+ return undefined;
43
+ }
44
+ return makeModelRelation(Executor, property);
45
+ },
46
+ });
47
+ const layer = (layerOptions) => {
48
+ const acquire = Effect.acquireRelease(Effect.suspend(() => acquireExecutor(layerOptions)), (executor) => Effect.promise(() => executor.client.close()).pipe(Effect.orDie));
49
+ return Layer.effectContext(Effect.map(acquire, (executor) => Context.make(Executor, executor).pipe(Context.add(Service, facade))));
50
+ };
51
+ return Object.assign(Service, {
52
+ layer,
53
+ [DatabaseTestingTypeId]: { withTestTransaction },
54
+ });
55
+ };
56
+ //# sourceMappingURL=database-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-factory.js","sourceRoot":"","sources":["../../src/internal/database-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAGhD,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAMlE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GAElB,MAAM,kBAAkB,CAAC;AAwE1B;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAI9B,QAAkB,EAClB,aAAuC,EAC9B,EAAE;IACX,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC3D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;QAC5D,MAAM,IAAI,SAAS,CAClB,+DAA+D,CAC/D,CAAC;IACH,CAAC;IACD,yBAAyB,CACxB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAC7D,CAAC;IACF,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,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
- import type { PostgresClient } from "@prisma-next/postgres/runtime";
3
2
  import type { SqlStorage } from "@prisma-next/sql-contract/types";
3
+ import type { ExecutionContext, Runtime } from "@prisma-next/sql-runtime";
4
4
  import type { Context, Semaphore } from "effect";
5
- export type AnyPostgresContract = PrismaContract<SqlStorage>;
6
- export interface DatabaseExecutor<Models extends object, Contract extends AnyPostgresContract = AnyPostgresContract> {
7
- readonly client: PostgresClient<Contract>;
5
+ export type AnySqlContract = PrismaContract<SqlStorage>;
6
+ export type AnyPostgresContract = AnySqlContract;
7
+ /**
8
+ * The subset of a Prisma Next client the package depends on. Both the
9
+ * PostgreSQL and the SQLite client satisfy it.
10
+ */
11
+ export interface SqlDatabaseClient<Contract extends AnySqlContract> {
12
+ readonly contract: Contract;
13
+ readonly context: ExecutionContext<Contract>;
14
+ runtime(): Runtime;
15
+ close(): Promise<void>;
16
+ }
17
+ export interface DatabaseExecutor<Models extends object, Contract extends AnySqlContract = AnySqlContract> {
18
+ readonly client: SqlDatabaseClient<Contract>;
8
19
  readonly models: Models;
9
20
  readonly querySemaphore: Semaphore.Semaphore | undefined;
10
21
  readonly transactional: boolean;
11
22
  }
12
- export type ExecutorService<Models extends object, Contract extends AnyPostgresContract = AnyPostgresContract> = Context.Service<ExecutorIdentifier<Models>, DatabaseExecutor<Models, Contract>>;
23
+ export type ExecutorService<Models extends object, Contract extends AnySqlContract = AnySqlContract> = Context.Service<ExecutorIdentifier<Models>, DatabaseExecutor<Models, Contract>>;
13
24
  export interface ExecutorIdentifier<Models extends object> {
14
25
  readonly _models: Models;
15
26
  readonly _executorIdentifier: unique symbol;
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/internal/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,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CAAC,CAAC;AACxD,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAEjD;;;GAGG;AACH,MAAM,WAAW,iBAAiB,CAAC,QAAQ,SAAS,cAAc;IACjE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC7C,OAAO,IAAI,OAAO,CAAC;IACnB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB,CAChC,MAAM,SAAS,MAAM,EACrB,QAAQ,SAAS,cAAc,GAAG,cAAc;IAEhD,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC;IACzD,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,MAAM,eAAe,CAC1B,MAAM,SAAS,MAAM,EACrB,QAAQ,SAAS,cAAc,GAAG,cAAc,IAC7C,OAAO,CAAC,OAAO,CAClB,kBAAkB,CAAC,MAAM,CAAC,EAC1B,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAClC,CAAC;AAEF,MAAM,WAAW,kBAAkB,CAAC,MAAM,SAAS,MAAM;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,mBAAmB,EAAE,OAAO,MAAM,CAAC;CAC5C"}
@@ -0,0 +1,31 @@
1
+ import type { ExecutionContext } from "@prisma-next/sql-runtime";
2
+ import type { AnySqlContract } from "./executor.js";
3
+ /**
4
+ * Stamp `Z` onto a SQLite datetime string that carries no zone designator.
5
+ *
6
+ * SQLite stores `DateTime` as text and computes `datetime('now')` — the default
7
+ * `prisma-next db init` generates — in UTC, but writes it as
8
+ * `YYYY-MM-DD HH:MM:SS` with no zone. `new Date` reads that form as local time,
9
+ * so decoding it unchanged shifts the instant by the process' UTC offset.
10
+ * Values that already carry `Z` or a numeric offset, date-only values (which
11
+ * `new Date` already reads as UTC), and anything that is not a datetime string
12
+ * are returned unchanged.
13
+ */
14
+ export declare const normalizeSqliteDatetime: (value: string) => string;
15
+ /**
16
+ * Replace the client's codec registry with one that decodes zone-less
17
+ * `sqlite/datetime@1` values as UTC.
18
+ *
19
+ * The registry is the single resolution point for both row decoding and the
20
+ * JSON decoding of included relations, so wrapping it covers every read path
21
+ * without touching encoding. Prisma Next rejects a second descriptor for an
22
+ * already-registered codec id, so an extension pack cannot replace the codec
23
+ * itself. Must run before the first query, because the runtime reads the
24
+ * registry off the context when it is created.
25
+ *
26
+ * Codecs are identified by the resolved reference rather than by `codec.id`:
27
+ * Prisma Next materializes a codec through an unbound descriptor factory, so
28
+ * the instance's `id` accessor throws.
29
+ */
30
+ export declare const decodeSqliteDatetimesAsUtc: (context: ExecutionContext<AnySqlContract>) => void;
31
+ //# sourceMappingURL=sqlite-datetime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-datetime.d.ts","sourceRoot":"","sources":["../../src/internal/sqlite-datetime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAYpD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MACd,CAAC;AAiB3C;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,0BAA0B,GACtC,SAAS,gBAAgB,CAAC,cAAc,CAAC,KACvC,IAmCF,CAAC"}
@@ -0,0 +1,66 @@
1
+ const sqliteDatetimeCodecId = "sqlite/datetime@1";
2
+ const zonelessDatetime = /^(\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?)$/;
3
+ /**
4
+ * Stamp `Z` onto a SQLite datetime string that carries no zone designator.
5
+ *
6
+ * SQLite stores `DateTime` as text and computes `datetime('now')` — the default
7
+ * `prisma-next db init` generates — in UTC, but writes it as
8
+ * `YYYY-MM-DD HH:MM:SS` with no zone. `new Date` reads that form as local time,
9
+ * so decoding it unchanged shifts the instant by the process' UTC offset.
10
+ * Values that already carry `Z` or a numeric offset, date-only values (which
11
+ * `new Date` already reads as UTC), and anything that is not a datetime string
12
+ * are returned unchanged.
13
+ */
14
+ export const normalizeSqliteDatetime = (value) => value.replace(zonelessDatetime, "$1T$2Z");
15
+ const decodeAsUtc = (codec) => ({
16
+ id: sqliteDatetimeCodecId,
17
+ encode: (value, context) => codec.encode(value, context),
18
+ decode: (wire, context) => codec.decode(typeof wire === "string" ? normalizeSqliteDatetime(wire) : wire, context),
19
+ encodeJson: (value) => codec.encodeJson(value),
20
+ decodeJson: (json) => codec.decodeJson(typeof json === "string" ? normalizeSqliteDatetime(json) : json),
21
+ });
22
+ /**
23
+ * Replace the client's codec registry with one that decodes zone-less
24
+ * `sqlite/datetime@1` values as UTC.
25
+ *
26
+ * The registry is the single resolution point for both row decoding and the
27
+ * JSON decoding of included relations, so wrapping it covers every read path
28
+ * without touching encoding. Prisma Next rejects a second descriptor for an
29
+ * already-registered codec id, so an extension pack cannot replace the codec
30
+ * itself. Must run before the first query, because the runtime reads the
31
+ * registry off the context when it is created.
32
+ *
33
+ * Codecs are identified by the resolved reference rather than by `codec.id`:
34
+ * Prisma Next materializes a codec through an unbound descriptor factory, so
35
+ * the instance's `id` accessor throws.
36
+ */
37
+ export const decodeSqliteDatetimesAsUtc = (context) => {
38
+ const registry = context.contractCodecs;
39
+ const descriptors = context.codecDescriptors;
40
+ const utcCodecs = new WeakMap();
41
+ const wrap = (codec) => {
42
+ const existing = utcCodecs.get(codec);
43
+ if (existing !== undefined) {
44
+ return existing;
45
+ }
46
+ const utc = decodeAsUtc(codec);
47
+ utcCodecs.set(codec, utc);
48
+ return utc;
49
+ };
50
+ const utcRegistry = {
51
+ forColumn: (namespaceId, table, column) => {
52
+ const codec = registry.forColumn(namespaceId, table, column);
53
+ if (codec === undefined) {
54
+ return undefined;
55
+ }
56
+ const reference = descriptors.codecRefForColumn(namespaceId, table, column);
57
+ return reference?.codecId === sqliteDatetimeCodecId ? wrap(codec) : codec;
58
+ },
59
+ forCodecRef: (reference) => {
60
+ const codec = registry.forCodecRef(reference);
61
+ return reference.codecId === sqliteDatetimeCodecId ? wrap(codec) : codec;
62
+ },
63
+ };
64
+ context.contractCodecs = utcRegistry;
65
+ };
66
+ //# sourceMappingURL=sqlite-datetime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-datetime.js","sourceRoot":"","sources":["../../src/internal/sqlite-datetime.ts"],"names":[],"mappings":"AAQA,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAElD,MAAM,gBAAgB,GACrB,6DAA6D,CAAC;AAE/D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAa,EAAU,EAAE,CAChE,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAE3C,MAAM,WAAW,GAAG,CAAC,KAAoB,EAAiB,EAAE,CAAC,CAAC;IAC7D,EAAE,EAAE,qBAAqB;IACzB,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;IACxD,MAAM,EAAE,CAAC,IAAe,EAAE,OAAO,EAAE,EAAE,CACpC,KAAK,CAAC,MAAM,CACX,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAC/D,OAAO,CACP;IACF,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC;IAC9C,UAAU,EAAE,CAAC,IA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C3E,CAAC;QACD,WAAW,EAAE,CAAC,SAAS,EAAE,EAAE;YAC1B,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;YAC9C,OAAO,SAAS,CAAC,OAAO,KAAK,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAC1E,CAAC;KACD,CAAC;IAED,OAA6C,CAAC,cAAc,GAAG,WAAW,CAAC;AAC7E,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ export declare const MEMORY_PATH = ":memory:";
2
+ /**
3
+ * Prisma Next's SQLite driver opens a fresh `node:sqlite` connection for every
4
+ * `RuntimeConnection`, so an in-memory database would give each transaction its
5
+ * own empty database.
6
+ */
7
+ export declare const assertFileBackedPath: (path: string) => void;
8
+ /**
9
+ * Apply connect-time pragmas.
10
+ *
11
+ * The driver already sets `foreign_keys` and `busy_timeout` on every connection
12
+ * it opens, but it has no hook for anything else, so durable pragmas such as
13
+ * `journal_mode` are applied once against the database file itself.
14
+ */
15
+ export declare const applySqlitePragmas: (path: string, pragmas: ReadonlyArray<string>) => void;
16
+ //# sourceMappingURL=sqlite-pragmas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-pragmas.d.ts","sourceRoot":"","sources":["../../src/internal/sqlite-pragmas.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,aAAa,CAAC;AAEtC;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,IAMnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC9B,MAAM,MAAM,EACZ,SAAS,aAAa,CAAC,MAAM,CAAC,KAC5B,IAaF,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ export const MEMORY_PATH = ":memory:";
3
+ /**
4
+ * Prisma Next's SQLite driver opens a fresh `node:sqlite` connection for every
5
+ * `RuntimeConnection`, so an in-memory database would give each transaction its
6
+ * own empty database.
7
+ */
8
+ export const assertFileBackedPath = (path) => {
9
+ if (path === MEMORY_PATH || path.trim().length === 0) {
10
+ throw new TypeError("Effect Prisma requires a file-backed SQLite database; transactions run on their own connection and cannot see an in-memory database");
11
+ }
12
+ };
13
+ /**
14
+ * Apply connect-time pragmas.
15
+ *
16
+ * The driver already sets `foreign_keys` and `busy_timeout` on every connection
17
+ * it opens, but it has no hook for anything else, so durable pragmas such as
18
+ * `journal_mode` are applied once against the database file itself.
19
+ */
20
+ export const applySqlitePragmas = (path, pragmas) => {
21
+ if (pragmas.length === 0) {
22
+ return;
23
+ }
24
+ const database = new DatabaseSync(path);
25
+ try {
26
+ for (const pragma of pragmas) {
27
+ database.exec(`PRAGMA ${pragma}`);
28
+ }
29
+ }
30
+ finally {
31
+ database.close();
32
+ }
33
+ };
34
+ //# sourceMappingURL=sqlite-pragmas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-pragmas.js","sourceRoot":"","sources":["../../src/internal/sqlite-pragmas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC;AAEtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAQ,EAAE;IAC1D,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,SAAS,CAClB,qIAAqI,CACrI,CAAC;IACH,CAAC;AACF,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CACjC,IAAY,EACZ,OAA8B,EACvB,EAAE;IACT,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO;IACR,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,CAAC;QACJ,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC9B,QAAQ,CAAC,IAAI,CAAC,UAAU,MAAM,EAAE,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;YAAS,CAAC;QACV,QAAQ,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;AACF,CAAC,CAAC"}
@@ -1,14 +1,15 @@
1
- import type { PostgresClient } from "@prisma-next/postgres/runtime";
1
+ import { orm } from "@prisma-next/sql-orm-client";
2
2
  import type { RuntimeConnection, RuntimeTransaction } from "@prisma-next/sql-runtime";
3
3
  import { Effect, Exit } from "effect";
4
4
  import type { PrismaError } from "../error.js";
5
- import type { AnyPostgresContract, DatabaseExecutor } from "./executor.js";
6
- export interface TransactionResource<Models extends object, Contract extends AnyPostgresContract> {
5
+ import type { AnySqlContract, DatabaseExecutor } from "./executor.js";
6
+ export type TransactionOrm<Contract extends AnySqlContract> = ReturnType<typeof orm<Contract>>;
7
+ export interface TransactionResource<Models extends object, Contract extends AnySqlContract> {
7
8
  readonly connection: RuntimeConnection;
8
9
  readonly transaction: RuntimeTransaction;
9
10
  readonly executor: DatabaseExecutor<Models, Contract>;
10
11
  }
11
- export declare const acquireTransaction: <Models extends object, Contract extends AnyPostgresContract>(current: DatabaseExecutor<Models, Contract>, models: (orm: PostgresClient<Contract>["orm"]) => Models) => Effect.Effect<TransactionResource<Models, Contract>, PrismaError>;
12
- export declare const releaseTransaction: <Models extends object, Contract extends AnyPostgresContract, A, E>(resource: TransactionResource<Models, Contract>, exit: Exit.Exit<A, E>) => Effect.Effect<void, PrismaError>;
13
- export declare const releaseTestTransaction: <Models extends object, Contract extends AnyPostgresContract, A, E>(resource: TransactionResource<Models, Contract>, exit: Exit.Exit<A, E>) => Effect.Effect<void, PrismaError>;
12
+ export declare const acquireTransaction: <Models extends object, Contract extends AnySqlContract>(current: DatabaseExecutor<Models, Contract>, models: (orm: TransactionOrm<Contract>) => Models) => Effect.Effect<TransactionResource<Models, Contract>, PrismaError>;
13
+ export declare const releaseTransaction: <Models extends object, Contract extends AnySqlContract, A, E>(resource: TransactionResource<Models, Contract>, exit: Exit.Exit<A, E>) => Effect.Effect<void, PrismaError>;
14
+ export declare const releaseTestTransaction: <Models extends object, Contract extends AnySqlContract, A, E>(resource: TransactionResource<Models, Contract>, exit: Exit.Exit<A, E>) => Effect.Effect<void, PrismaError>;
14
15
  //# sourceMappingURL=transaction.d.ts.map