@effect/sql-d1 4.0.0-beta.66 → 4.0.0-beta.68
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/dist/D1Client.d.ts +49 -12
- package/dist/D1Client.d.ts.map +1 -1
- package/dist/D1Client.js +17 -7
- package/dist/D1Client.js.map +1 -1
- package/dist/index.d.ts +23 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/D1Client.ts +49 -12
- package/src/index.ts +23 -2
package/dist/D1Client.d.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Cloudflare D1 client implementation for Effect SQL, backed by a Workers `D1Database` binding.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts a Cloudflare D1 database binding into both the
|
|
5
|
+
* D1-specific `D1Client` service and the generic Effect `SqlClient` service.
|
|
6
|
+
* Use it in Workers, Pages Functions, and tests that provide a D1 binding to
|
|
7
|
+
* run SQLite-compatible queries through Effect services and layers, including
|
|
8
|
+
* repositories, migrations, request handlers, and local development against
|
|
9
|
+
* Wrangler or Miniflare-backed D1 databases.
|
|
10
|
+
*
|
|
11
|
+
* The client prepares statements with D1, caches them by SQL string, and uses
|
|
12
|
+
* the SQLite statement compiler for query and result name transforms. D1
|
|
13
|
+
* commits individual statements automatically, and native `D1Database.batch`
|
|
14
|
+
* is the D1 API for sequential, transactional multi-statement work; this
|
|
15
|
+
* adapter does not expose Effect SQL transactions because it cannot map
|
|
16
|
+
* `withTransaction` onto a connection-scoped D1 transaction. D1 databases are
|
|
17
|
+
* serverless SQLite storage with platform limits and single-database serialized
|
|
18
|
+
* execution, so keep queries small and indexed, batch large maintenance work
|
|
19
|
+
* at the D1 API level, and use D1 sessions outside this client when an
|
|
20
|
+
* application needs bookmark-based sequential consistency or read replicas.
|
|
21
|
+
* Streaming queries and `updateValues` are not supported.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
3
24
|
*/
|
|
4
25
|
import type { D1Database } from "@cloudflare/workers-types";
|
|
5
26
|
import * as Config from "effect/Config";
|
|
@@ -11,18 +32,24 @@ import type * as Scope from "effect/Scope";
|
|
|
11
32
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
12
33
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
13
34
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
35
|
+
* Unique runtime identifier used to tag `D1Client` values.
|
|
36
|
+
*
|
|
37
|
+
* @category type IDs
|
|
38
|
+
* @since 4.0.0
|
|
16
39
|
*/
|
|
17
40
|
export declare const TypeId: TypeId;
|
|
18
41
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
42
|
+
* Type-level literal for the `D1Client` runtime identifier.
|
|
43
|
+
*
|
|
44
|
+
* @category type IDs
|
|
45
|
+
* @since 4.0.0
|
|
21
46
|
*/
|
|
22
47
|
export type TypeId = "~@effect/sql-d1/D1Client";
|
|
23
48
|
/**
|
|
49
|
+
* Cloudflare D1 SQL client service, extending `SqlClient` with its D1 configuration and no `updateValues` support.
|
|
50
|
+
*
|
|
24
51
|
* @category models
|
|
25
|
-
* @since
|
|
52
|
+
* @since 4.0.0
|
|
26
53
|
*/
|
|
27
54
|
export interface D1Client extends Client.SqlClient {
|
|
28
55
|
readonly [TypeId]: TypeId;
|
|
@@ -31,13 +58,17 @@ export interface D1Client extends Client.SqlClient {
|
|
|
31
58
|
readonly updateValues: never;
|
|
32
59
|
}
|
|
33
60
|
/**
|
|
61
|
+
* Context tag used to access the `D1Client` service.
|
|
62
|
+
*
|
|
34
63
|
* @category tags
|
|
35
|
-
* @since
|
|
64
|
+
* @since 4.0.0
|
|
36
65
|
*/
|
|
37
66
|
export declare const D1Client: Context.Service<D1Client, D1Client>;
|
|
38
67
|
/**
|
|
68
|
+
* Configuration for a Cloudflare D1 client, including the `D1Database`, prepared statement cache settings, span attributes, and query/result name transforms.
|
|
69
|
+
*
|
|
39
70
|
* @category models
|
|
40
|
-
* @since
|
|
71
|
+
* @since 4.0.0
|
|
41
72
|
*/
|
|
42
73
|
export interface D1ClientConfig {
|
|
43
74
|
readonly db: D1Database;
|
|
@@ -48,18 +79,24 @@ export interface D1ClientConfig {
|
|
|
48
79
|
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
49
80
|
}
|
|
50
81
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
82
|
+
* Creates a scoped Cloudflare D1 SQL client. Prepared statements are cached, while transactions and streaming queries are not supported by this driver.
|
|
83
|
+
*
|
|
84
|
+
* @category constructors
|
|
85
|
+
* @since 4.0.0
|
|
53
86
|
*/
|
|
54
87
|
export declare const make: (options: D1ClientConfig) => Effect.Effect<D1Client, never, Scope.Scope | Reactivity.Reactivity>;
|
|
55
88
|
/**
|
|
89
|
+
* Creates a layer from a `Config`-wrapped D1 client configuration, providing both `D1Client` and `SqlClient`.
|
|
90
|
+
*
|
|
56
91
|
* @category layers
|
|
57
|
-
* @since
|
|
92
|
+
* @since 4.0.0
|
|
58
93
|
*/
|
|
59
94
|
export declare const layerConfig: (config: Config.Wrap<D1ClientConfig>) => Layer.Layer<D1Client | Client.SqlClient, Config.ConfigError>;
|
|
60
95
|
/**
|
|
96
|
+
* Creates a layer from a concrete D1 client configuration, providing both `D1Client` and `SqlClient`.
|
|
97
|
+
*
|
|
61
98
|
* @category layers
|
|
62
|
-
* @since
|
|
99
|
+
* @since 4.0.0
|
|
63
100
|
*/
|
|
64
101
|
export declare const layer: (config: D1ClientConfig) => Layer.Layer<D1Client | Client.SqlClient, Config.ConfigError>;
|
|
65
102
|
//# sourceMappingURL=D1Client.d.ts.map
|
package/dist/D1Client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"D1Client.d.ts","sourceRoot":"","sources":["../src/D1Client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"D1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AE7D,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;IACrE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;CACrE;AAED;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GACf,SAAS,cAAc,KACtB,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CAgHjE,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,KAClC,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAUrB,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,QAAQ,cAAc,KACrB,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAMrB,CAAA"}
|
package/dist/D1Client.js
CHANGED
|
@@ -17,18 +17,24 @@ const classifyError = (cause, message, operation) => new UnknownError({
|
|
|
17
17
|
operation
|
|
18
18
|
});
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* Unique runtime identifier used to tag `D1Client` values.
|
|
21
|
+
*
|
|
22
|
+
* @category type IDs
|
|
23
|
+
* @since 4.0.0
|
|
22
24
|
*/
|
|
23
25
|
export const TypeId = "~@effect/sql-d1/D1Client";
|
|
24
26
|
/**
|
|
27
|
+
* Context tag used to access the `D1Client` service.
|
|
28
|
+
*
|
|
25
29
|
* @category tags
|
|
26
|
-
* @since
|
|
30
|
+
* @since 4.0.0
|
|
27
31
|
*/
|
|
28
32
|
export const D1Client = /*#__PURE__*/Context.Service("@effect/sql-d1/D1Client");
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
34
|
+
* Creates a scoped Cloudflare D1 SQL client. Prepared statements are cached, while transactions and streaming queries are not supported by this driver.
|
|
35
|
+
*
|
|
36
|
+
* @category constructors
|
|
37
|
+
* @since 4.0.0
|
|
32
38
|
*/
|
|
33
39
|
export const make = options => Effect.gen(function* () {
|
|
34
40
|
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
@@ -101,13 +107,17 @@ export const make = options => Effect.gen(function* () {
|
|
|
101
107
|
});
|
|
102
108
|
});
|
|
103
109
|
/**
|
|
110
|
+
* Creates a layer from a `Config`-wrapped D1 client configuration, providing both `D1Client` and `SqlClient`.
|
|
111
|
+
*
|
|
104
112
|
* @category layers
|
|
105
|
-
* @since
|
|
113
|
+
* @since 4.0.0
|
|
106
114
|
*/
|
|
107
115
|
export const layerConfig = config => Layer.effectContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(D1Client, client).pipe(Context.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
|
|
108
116
|
/**
|
|
117
|
+
* Creates a layer from a concrete D1 client configuration, providing both `D1Client` and `SqlClient`.
|
|
118
|
+
*
|
|
109
119
|
* @category layers
|
|
110
|
-
* @since
|
|
120
|
+
* @since 4.0.0
|
|
111
121
|
*/
|
|
112
122
|
export const layer = config => Layer.effectContext(Effect.map(make(config), client => Context.make(D1Client, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
|
|
113
123
|
//# sourceMappingURL=D1Client.js.map
|
package/dist/D1Client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"D1Client.js","names":["Cache","Config","Context","Duration","Effect","identity","Layer","Stream","Reactivity","Client","SqlError","UnknownError","Statement","ATTR_DB_SYSTEM_NAME","classifyError","cause","message","operation","TypeId","D1Client","Service","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","makeConnection","db","prepareCache","capacity","prepareCacheSize","timeToLive","prepareCacheTTL","minutes","lookup","sql","try","prepare","catch","reason","runStatement","statement","params","tryPromise","response","bind","all","error","results","runRaw","runCached","flatMap","get","s","runUncached","runValues","raw","execute","map","executeRaw","executeValues","executeUnprepared","executeStream","_sql","_params","die","connection","acquirer","succeed","transactionAcquirer","Object","assign","spanAttributes","entries","config","layerConfig","effectContext","unwrap","pipe","client","add","SqlClient","provide","layer"],"sources":["../src/D1Client.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"file":"D1Client.js","names":["Cache","Config","Context","Duration","Effect","identity","Layer","Stream","Reactivity","Client","SqlError","UnknownError","Statement","ATTR_DB_SYSTEM_NAME","classifyError","cause","message","operation","TypeId","D1Client","Service","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","makeConnection","db","prepareCache","capacity","prepareCacheSize","timeToLive","prepareCacheTTL","minutes","lookup","sql","try","prepare","catch","reason","runStatement","statement","params","tryPromise","response","bind","all","error","results","runRaw","runCached","flatMap","get","s","runUncached","runValues","raw","execute","map","executeRaw","executeValues","executeUnprepared","executeStream","_sql","_params","die","connection","acquirer","succeed","transactionAcquirer","Object","assign","spanAttributes","entries","config","layerConfig","effectContext","unwrap","pipe","client","add","SqlClient","provide","layer"],"sources":["../src/D1Client.ts"],"sourcesContent":[null],"mappings":"AAyBA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,M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ACjClF,OAAO,CAACoF,GAAG,CAAC7E,MAAM,CAAC8E,SAAS,EAAEF,MAAM,CAAC,CACtC,CAAC,CACL,CAACD,IAAI,CAAC9E,KAAK,CAACkF,OAAO,CAAChF,UAAU,CAACiF,KAAK,CAAC,CAAC","ignoreList":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Cloudflare D1 client implementation for Effect SQL, backed by a Workers `D1Database` binding.
|
|
6
|
+
*
|
|
7
|
+
* This module adapts a Cloudflare D1 database binding into both the
|
|
8
|
+
* D1-specific `D1Client` service and the generic Effect `SqlClient` service.
|
|
9
|
+
* Use it in Workers, Pages Functions, and tests that provide a D1 binding to
|
|
10
|
+
* run SQLite-compatible queries through Effect services and layers, including
|
|
11
|
+
* repositories, migrations, request handlers, and local development against
|
|
12
|
+
* Wrangler or Miniflare-backed D1 databases.
|
|
13
|
+
*
|
|
14
|
+
* The client prepares statements with D1, caches them by SQL string, and uses
|
|
15
|
+
* the SQLite statement compiler for query and result name transforms. D1
|
|
16
|
+
* commits individual statements automatically, and native `D1Database.batch`
|
|
17
|
+
* is the D1 API for sequential, transactional multi-statement work; this
|
|
18
|
+
* adapter does not expose Effect SQL transactions because it cannot map
|
|
19
|
+
* `withTransaction` onto a connection-scoped D1 transaction. D1 databases are
|
|
20
|
+
* serverless SQLite storage with platform limits and single-database serialized
|
|
21
|
+
* execution, so keep queries small and indexed, batch large maintenance work
|
|
22
|
+
* at the D1 API level, and use D1 sessions outside this client when an
|
|
23
|
+
* application needs bookmark-based sequential consistency or read replicas.
|
|
24
|
+
* Streaming queries and `updateValues` are not supported.
|
|
25
|
+
*
|
|
26
|
+
* @since 4.0.0
|
|
6
27
|
*/
|
|
7
28
|
export * as D1Client from "./D1Client.ts";
|
|
8
29
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Cloudflare D1 client implementation for Effect SQL, backed by a Workers `D1Database` binding.
|
|
7
|
+
*
|
|
8
|
+
* This module adapts a Cloudflare D1 database binding into both the
|
|
9
|
+
* D1-specific `D1Client` service and the generic Effect `SqlClient` service.
|
|
10
|
+
* Use it in Workers, Pages Functions, and tests that provide a D1 binding to
|
|
11
|
+
* run SQLite-compatible queries through Effect services and layers, including
|
|
12
|
+
* repositories, migrations, request handlers, and local development against
|
|
13
|
+
* Wrangler or Miniflare-backed D1 databases.
|
|
14
|
+
*
|
|
15
|
+
* The client prepares statements with D1, caches them by SQL string, and uses
|
|
16
|
+
* the SQLite statement compiler for query and result name transforms. D1
|
|
17
|
+
* commits individual statements automatically, and native `D1Database.batch`
|
|
18
|
+
* is the D1 API for sequential, transactional multi-statement work; this
|
|
19
|
+
* adapter does not expose Effect SQL transactions because it cannot map
|
|
20
|
+
* `withTransaction` onto a connection-scoped D1 transaction. D1 databases are
|
|
21
|
+
* serverless SQLite storage with platform limits and single-database serialized
|
|
22
|
+
* execution, so keep queries small and indexed, batch large maintenance work
|
|
23
|
+
* at the D1 API level, and use D1 sessions outside this client when an
|
|
24
|
+
* application needs bookmark-based sequential consistency or read replicas.
|
|
25
|
+
* Streaming queries and `updateValues` are not supported.
|
|
26
|
+
*
|
|
27
|
+
* @since 4.0.0
|
|
7
28
|
*/
|
|
8
29
|
export * as D1Client from "./D1Client.js";
|
|
9
30
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["D1Client"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA
|
|
1
|
+
{"version":3,"file":"index.js","names":["D1Client"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,OAAO,KAAKA,QAAQ,MAAM,eAAe","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-d1",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.68",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A Cloudflare D1 integration for Effect",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
"provenance": true
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"miniflare": "^4.
|
|
51
|
-
"effect": "^4.0.0-beta.
|
|
50
|
+
"miniflare": "^4.20260507.1",
|
|
51
|
+
"effect": "^4.0.0-beta.68"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"effect": "^4.0.0-beta.
|
|
54
|
+
"effect": "^4.0.0-beta.68"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@cloudflare/workers-types": "^4.
|
|
57
|
+
"@cloudflare/workers-types": "^4.20260511.1"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"codegen": "effect-utils codegen",
|
package/src/D1Client.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Cloudflare D1 client implementation for Effect SQL, backed by a Workers `D1Database` binding.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts a Cloudflare D1 database binding into both the
|
|
5
|
+
* D1-specific `D1Client` service and the generic Effect `SqlClient` service.
|
|
6
|
+
* Use it in Workers, Pages Functions, and tests that provide a D1 binding to
|
|
7
|
+
* run SQLite-compatible queries through Effect services and layers, including
|
|
8
|
+
* repositories, migrations, request handlers, and local development against
|
|
9
|
+
* Wrangler or Miniflare-backed D1 databases.
|
|
10
|
+
*
|
|
11
|
+
* The client prepares statements with D1, caches them by SQL string, and uses
|
|
12
|
+
* the SQLite statement compiler for query and result name transforms. D1
|
|
13
|
+
* commits individual statements automatically, and native `D1Database.batch`
|
|
14
|
+
* is the D1 API for sequential, transactional multi-statement work; this
|
|
15
|
+
* adapter does not expose Effect SQL transactions because it cannot map
|
|
16
|
+
* `withTransaction` onto a connection-scoped D1 transaction. D1 databases are
|
|
17
|
+
* serverless SQLite storage with platform limits and single-database serialized
|
|
18
|
+
* execution, so keep queries small and indexed, batch large maintenance work
|
|
19
|
+
* at the D1 API level, and use D1 sessions outside this client when an
|
|
20
|
+
* application needs bookmark-based sequential consistency or read replicas.
|
|
21
|
+
* Streaming queries and `updateValues` are not supported.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
3
24
|
*/
|
|
4
25
|
import type { D1Database, D1PreparedStatement } from "@cloudflare/workers-types"
|
|
5
26
|
import * as Cache from "effect/Cache"
|
|
@@ -23,20 +44,26 @@ const classifyError = (cause: unknown, message: string, operation: string) =>
|
|
|
23
44
|
new UnknownError({ cause, message, operation })
|
|
24
45
|
|
|
25
46
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
47
|
+
* Unique runtime identifier used to tag `D1Client` values.
|
|
48
|
+
*
|
|
49
|
+
* @category type IDs
|
|
50
|
+
* @since 4.0.0
|
|
28
51
|
*/
|
|
29
52
|
export const TypeId: TypeId = "~@effect/sql-d1/D1Client"
|
|
30
53
|
|
|
31
54
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
55
|
+
* Type-level literal for the `D1Client` runtime identifier.
|
|
56
|
+
*
|
|
57
|
+
* @category type IDs
|
|
58
|
+
* @since 4.0.0
|
|
34
59
|
*/
|
|
35
60
|
export type TypeId = "~@effect/sql-d1/D1Client"
|
|
36
61
|
|
|
37
62
|
/**
|
|
63
|
+
* Cloudflare D1 SQL client service, extending `SqlClient` with its D1 configuration and no `updateValues` support.
|
|
64
|
+
*
|
|
38
65
|
* @category models
|
|
39
|
-
* @since
|
|
66
|
+
* @since 4.0.0
|
|
40
67
|
*/
|
|
41
68
|
export interface D1Client extends Client.SqlClient {
|
|
42
69
|
readonly [TypeId]: TypeId
|
|
@@ -47,14 +74,18 @@ export interface D1Client extends Client.SqlClient {
|
|
|
47
74
|
}
|
|
48
75
|
|
|
49
76
|
/**
|
|
77
|
+
* Context tag used to access the `D1Client` service.
|
|
78
|
+
*
|
|
50
79
|
* @category tags
|
|
51
|
-
* @since
|
|
80
|
+
* @since 4.0.0
|
|
52
81
|
*/
|
|
53
82
|
export const D1Client = Context.Service<D1Client>("@effect/sql-d1/D1Client")
|
|
54
83
|
|
|
55
84
|
/**
|
|
85
|
+
* Configuration for a Cloudflare D1 client, including the `D1Database`, prepared statement cache settings, span attributes, and query/result name transforms.
|
|
86
|
+
*
|
|
56
87
|
* @category models
|
|
57
|
-
* @since
|
|
88
|
+
* @since 4.0.0
|
|
58
89
|
*/
|
|
59
90
|
export interface D1ClientConfig {
|
|
60
91
|
readonly db: D1Database
|
|
@@ -67,8 +98,10 @@ export interface D1ClientConfig {
|
|
|
67
98
|
}
|
|
68
99
|
|
|
69
100
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
101
|
+
* Creates a scoped Cloudflare D1 SQL client. Prepared statements are cached, while transactions and streaming queries are not supported by this driver.
|
|
102
|
+
*
|
|
103
|
+
* @category constructors
|
|
104
|
+
* @since 4.0.0
|
|
72
105
|
*/
|
|
73
106
|
export const make = (
|
|
74
107
|
options: D1ClientConfig
|
|
@@ -187,8 +220,10 @@ export const make = (
|
|
|
187
220
|
})
|
|
188
221
|
|
|
189
222
|
/**
|
|
223
|
+
* Creates a layer from a `Config`-wrapped D1 client configuration, providing both `D1Client` and `SqlClient`.
|
|
224
|
+
*
|
|
190
225
|
* @category layers
|
|
191
|
-
* @since
|
|
226
|
+
* @since 4.0.0
|
|
192
227
|
*/
|
|
193
228
|
export const layerConfig = (
|
|
194
229
|
config: Config.Wrap<D1ClientConfig>
|
|
@@ -205,8 +240,10 @@ export const layerConfig = (
|
|
|
205
240
|
).pipe(Layer.provide(Reactivity.layer))
|
|
206
241
|
|
|
207
242
|
/**
|
|
243
|
+
* Creates a layer from a concrete D1 client configuration, providing both `D1Client` and `SqlClient`.
|
|
244
|
+
*
|
|
208
245
|
* @category layers
|
|
209
|
-
* @since
|
|
246
|
+
* @since 4.0.0
|
|
210
247
|
*/
|
|
211
248
|
export const layer = (
|
|
212
249
|
config: D1ClientConfig
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Cloudflare D1 client implementation for Effect SQL, backed by a Workers `D1Database` binding.
|
|
9
|
+
*
|
|
10
|
+
* This module adapts a Cloudflare D1 database binding into both the
|
|
11
|
+
* D1-specific `D1Client` service and the generic Effect `SqlClient` service.
|
|
12
|
+
* Use it in Workers, Pages Functions, and tests that provide a D1 binding to
|
|
13
|
+
* run SQLite-compatible queries through Effect services and layers, including
|
|
14
|
+
* repositories, migrations, request handlers, and local development against
|
|
15
|
+
* Wrangler or Miniflare-backed D1 databases.
|
|
16
|
+
*
|
|
17
|
+
* The client prepares statements with D1, caches them by SQL string, and uses
|
|
18
|
+
* the SQLite statement compiler for query and result name transforms. D1
|
|
19
|
+
* commits individual statements automatically, and native `D1Database.batch`
|
|
20
|
+
* is the D1 API for sequential, transactional multi-statement work; this
|
|
21
|
+
* adapter does not expose Effect SQL transactions because it cannot map
|
|
22
|
+
* `withTransaction` onto a connection-scoped D1 transaction. D1 databases are
|
|
23
|
+
* serverless SQLite storage with platform limits and single-database serialized
|
|
24
|
+
* execution, so keep queries small and indexed, batch large maintenance work
|
|
25
|
+
* at the D1 API level, and use D1 sessions outside this client when an
|
|
26
|
+
* application needs bookmark-based sequential consistency or read replicas.
|
|
27
|
+
* Streaming queries and `updateValues` are not supported.
|
|
28
|
+
*
|
|
29
|
+
* @since 4.0.0
|
|
9
30
|
*/
|
|
10
31
|
export * as D1Client from "./D1Client.ts"
|