@effect/sql-sqlite-do 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present The Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Effect SQL - SQLite
2
+
3
+ An @effect/sql implementation for Cloudflare Durable Objects sqlite storage.
4
+
5
+ See here for more information: https://github.com/Effect-TS/effect/tree/main/packages/sql
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/SqliteClient.js",
3
+ "module": "../dist/esm/SqliteClient.js",
4
+ "types": "../dist/dts/SqliteClient.d.ts",
5
+ "sideEffects": []
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/SqliteMigrator.js",
3
+ "module": "../dist/esm/SqliteMigrator.js",
4
+ "types": "../dist/dts/SqliteMigrator.d.ts",
5
+ "sideEffects": []
6
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.make = exports.layerConfig = exports.layer = exports.TypeId = exports.SqliteClient = void 0;
7
+ var Reactivity = _interopRequireWildcard(require("@effect/experimental/Reactivity"));
8
+ var Client = _interopRequireWildcard(require("@effect/sql/SqlClient"));
9
+ var _SqlError = require("@effect/sql/SqlError");
10
+ var Statement = _interopRequireWildcard(require("@effect/sql/Statement"));
11
+ var Chunk = _interopRequireWildcard(require("effect/Chunk"));
12
+ var Config = _interopRequireWildcard(require("effect/Config"));
13
+ var Context = _interopRequireWildcard(require("effect/Context"));
14
+ var Effect = _interopRequireWildcard(require("effect/Effect"));
15
+ var _Function = require("effect/Function");
16
+ var Layer = _interopRequireWildcard(require("effect/Layer"));
17
+ var Scope = _interopRequireWildcard(require("effect/Scope"));
18
+ var Stream = _interopRequireWildcard(require("effect/Stream"));
19
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
21
+ /**
22
+ * @category type ids
23
+ * @since 1.0.0
24
+ */
25
+ const TypeId = exports.TypeId = /*#__PURE__*/Symbol.for("@effect/sql-sqlite-do/SqliteClient");
26
+ /**
27
+ * @category tags
28
+ * @since 1.0.0
29
+ */
30
+ const SqliteClient = exports.SqliteClient = /*#__PURE__*/Context.GenericTag("@effect/sql-sqlite-do/SqliteClient");
31
+ /**
32
+ * @category constructor
33
+ * @since 1.0.0
34
+ */
35
+ const make = options => Effect.gen(function* () {
36
+ const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
37
+ const transformRows = options.transformResultNames ? Statement.defaultTransforms(options.transformResultNames).array : undefined;
38
+ const makeConnection = Effect.gen(function* () {
39
+ const db = options.db;
40
+ function* runIterator(sql, params = []) {
41
+ const cursor = db.exec(sql, ...params);
42
+ const columns = cursor.columnNames;
43
+ for (const result of cursor.raw()) {
44
+ const obj = {};
45
+ for (let i = 0; i < columns.length; i++) {
46
+ const value = result[i];
47
+ obj[columns[i]] = value instanceof ArrayBuffer ? new Uint8Array(value) : value;
48
+ }
49
+ yield obj;
50
+ }
51
+ }
52
+ const runStatement = (sql, params = []) => Effect.try({
53
+ try: () => Array.from(runIterator(sql, params)),
54
+ catch: cause => new _SqlError.SqlError({
55
+ cause,
56
+ message: `Failed to execute statement`
57
+ })
58
+ });
59
+ const runValues = (sql, params = []) => Effect.try({
60
+ try: () => Array.from(db.exec(sql, ...params).raw(), row => {
61
+ for (let i = 0; i < row.length; i++) {
62
+ const value = row[i];
63
+ if (value instanceof ArrayBuffer) {
64
+ row[i] = new Uint8Array(value);
65
+ }
66
+ }
67
+ return row;
68
+ }),
69
+ catch: cause => new _SqlError.SqlError({
70
+ cause,
71
+ message: `Failed to execute statement`
72
+ })
73
+ });
74
+ return (0, _Function.identity)({
75
+ execute(sql, params, transformRows) {
76
+ return transformRows ? Effect.map(runStatement(sql, params), transformRows) : runStatement(sql, params);
77
+ },
78
+ executeRaw(sql, params) {
79
+ return runStatement(sql, params);
80
+ },
81
+ executeValues(sql, params) {
82
+ return runValues(sql, params);
83
+ },
84
+ executeUnprepared(sql, params, transformRows) {
85
+ return transformRows ? Effect.map(runStatement(sql, params), transformRows) : runStatement(sql, params);
86
+ },
87
+ executeStream(sql, params, transformRows) {
88
+ return Stream.suspend(() => {
89
+ const iterator = runIterator(sql, params);
90
+ return Stream.fromIteratorSucceed(iterator, 16);
91
+ }).pipe(transformRows ? Stream.mapChunks(chunk => Chunk.unsafeFromArray(transformRows(Chunk.toReadonlyArray(chunk)))) : _Function.identity);
92
+ }
93
+ });
94
+ });
95
+ const semaphore = yield* Effect.makeSemaphore(1);
96
+ const connection = yield* makeConnection;
97
+ const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
98
+ const transactionAcquirer = Effect.uninterruptibleMask(restore => Effect.as(Effect.zipRight(restore(semaphore.take(1)), Effect.tap(Effect.scope, scope => Scope.addFinalizer(scope, semaphore.release(1)))), connection));
99
+ return Object.assign(yield* Client.make({
100
+ acquirer,
101
+ compiler,
102
+ transactionAcquirer,
103
+ spanAttributes: [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), ["db.system", "sqlite"]],
104
+ transformRows
105
+ }), {
106
+ [TypeId]: TypeId,
107
+ config: options
108
+ });
109
+ });
110
+ /**
111
+ * @category layers
112
+ * @since 1.0.0
113
+ */
114
+ exports.make = make;
115
+ const layerConfig = config => Layer.scopedContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(SqliteClient, client).pipe(Context.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
116
+ /**
117
+ * @category layers
118
+ * @since 1.0.0
119
+ */
120
+ exports.layerConfig = layerConfig;
121
+ const layer = config => Layer.scopedContext(Effect.map(make(config), client => Context.make(SqliteClient, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
122
+ exports.layer = layer;
123
+ //# sourceMappingURL=SqliteClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteClient.js","names":["Reactivity","_interopRequireWildcard","require","Client","_SqlError","Statement","Chunk","Config","Context","Effect","_Function","Layer","Scope","Stream","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","TypeId","exports","Symbol","for","SqliteClient","GenericTag","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","makeConnection","db","runIterator","sql","params","cursor","exec","columns","columnNames","result","raw","obj","length","value","ArrayBuffer","Uint8Array","runStatement","try","Array","from","catch","cause","SqlError","message","runValues","row","identity","execute","map","executeRaw","executeValues","executeUnprepared","executeStream","suspend","iterator","fromIteratorSucceed","pipe","mapChunks","chunk","unsafeFromArray","toReadonlyArray","semaphore","makeSemaphore","connection","acquirer","withPermits","succeed","transactionAcquirer","uninterruptibleMask","restore","as","zipRight","take","tap","scope","addFinalizer","release","assign","spanAttributes","entries","config","layerConfig","scopedContext","unwrap","flatMap","client","add","SqlClient","provide","layer"],"sources":["../../src/SqliteClient.ts"],"sourcesContent":[null],"mappings":";;;;;;AAIA,IAAAA,UAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,uBAAA,CAAAC,OAAA;AAEA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAJ,uBAAA,CAAAC,OAAA;AACA,IAAAI,KAAA,GAAAL,uBAAA,CAAAC,OAAA;AACA,IAAAK,MAAA,GAAAN,uBAAA,CAAAC,OAAA;AAEA,IAAAM,OAAA,GAAAP,uBAAA,CAAAC,OAAA;AACA,IAAAO,MAAA,GAAAR,uBAAA,CAAAC,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AACA,IAAAS,KAAA,GAAAV,uBAAA,CAAAC,OAAA;AACA,IAAAU,KAAA,GAAAX,uBAAA,CAAAC,OAAA;AACA,IAAAW,MAAA,GAAAZ,uBAAA,CAAAC,OAAA;AAAuC,SAAAY,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,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mH,SAAS,EAAEF,MAAM,CAAC,CACtC,CAAC,CACL,CAAC7B,IAAI,CAAC5E,KAAK,CAAC4G,OAAO,CAACvH,UAAU,CAACwH,KAAK,CAAC,CAAC;AAAArF,OAAA,CAAAqF,KAAA,GAAAA,KAAA","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ run: true,
8
+ layer: true
9
+ };
10
+ exports.run = exports.layer = void 0;
11
+ var Migrator = _interopRequireWildcard(require("@effect/sql/Migrator"));
12
+ Object.keys(Migrator).forEach(function (key) {
13
+ if (key === "default" || key === "__esModule") return;
14
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
15
+ if (key in exports && exports[key] === Migrator[key]) return;
16
+ Object.defineProperty(exports, key, {
17
+ enumerable: true,
18
+ get: function () {
19
+ return Migrator[key];
20
+ }
21
+ });
22
+ });
23
+ var Layer = _interopRequireWildcard(require("effect/Layer"));
24
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
25
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
26
+ /**
27
+ * @since 1.0.0
28
+ */
29
+
30
+ /**
31
+ * @since 1.0.0
32
+ */
33
+
34
+ /**
35
+ * @category constructor
36
+ * @since 1.0.0
37
+ */
38
+ const run = exports.run = /*#__PURE__*/Migrator.make({});
39
+ /**
40
+ * @category constructor
41
+ * @since 1.0.0
42
+ */
43
+ const layer = options => Layer.effectDiscard(run(options));
44
+ exports.layer = layer;
45
+ //# sourceMappingURL=SqliteMigrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteMigrator.js","names":["Migrator","_interopRequireWildcard","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","Layer","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set","run","make","layer","options","effectDiscard"],"sources":["../../src/SqliteMigrator.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;AAGA,IAAAA,QAAA,GAAAC,uBAAA,CAAAC,OAAA;AASAC,MAAA,CAAAC,IAAA,CAAAJ,QAAA,EAAAK,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAN,QAAA,CAAAM,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAd,QAAA,CAAAM,GAAA;IAAA;EAAA;AAAA;AALA,IAAAS,KAAA,GAAAd,uBAAA,CAAAC,OAAA;AAAqC,SAAAc,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAhB,wBAAAgB,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAN,GAAA,CAAAG,CAAA,OAAAO,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAvB,MAAA,CAAAS,cAAA,IAAAT,MAAA,CAAAwB,wBAAA,WAAAC,CAAA,IAAAX,CAAA,oBAAAW,CAAA,OAAApB,cAAA,CAAAC,IAAA,CAAAQ,CAAA,EAAAW,CAAA,SAAAC,CAAA,GAAAH,CAAA,GAAAvB,MAAA,CAAAwB,wBAAA,CAAAV,CAAA,EAAAW,CAAA,UAAAC,CAAA,KAAAA,CAAA,CAAAf,GAAA,IAAAe,CAAA,CAAAC,GAAA,IAAA3B,MAAA,CAAAS,cAAA,CAAAY,CAAA,EAAAI,CAAA,EAAAC,CAAA,IAAAL,CAAA,CAAAI,CAAA,IAAAX,CAAA,CAAAW,CAAA,YAAAJ,CAAA,CAAAF,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAU,GAAA,CAAAb,CAAA,EAAAO,CAAA,GAAAA,CAAA;AAPrC;;;;AASA;;;;AAKA;;;;AAIO,MAAMO,GAAG,GAAApB,OAAA,CAAAoB,GAAA,gBAMZ/B,QAAQ,CAACgC,IAAI,CAAC,EAAE,CAAC;AAErB;;;;AAIO,MAAMC,KAAK,GAChBC,OAAoC,IAC6CnB,KAAK,CAACoB,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC;AAAAvB,OAAA,CAAAsB,KAAA,GAAAA,KAAA","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SqliteMigrator = exports.SqliteClient = void 0;
7
+ var _SqliteClient = _interopRequireWildcard(require("./SqliteClient.js"));
8
+ exports.SqliteClient = _SqliteClient;
9
+ var _SqliteMigrator = _interopRequireWildcard(require("./SqliteMigrator.js"));
10
+ exports.SqliteMigrator = _SqliteMigrator;
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"","ignoreList":[]}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type { SqlStorage } from "@cloudflare/workers-types";
5
+ import * as Reactivity from "@effect/experimental/Reactivity";
6
+ import * as Client from "@effect/sql/SqlClient";
7
+ import * as Config from "effect/Config";
8
+ import type { ConfigError } from "effect/ConfigError";
9
+ import * as Context from "effect/Context";
10
+ import * as Effect from "effect/Effect";
11
+ import * as Layer from "effect/Layer";
12
+ import * as Scope from "effect/Scope";
13
+ /**
14
+ * @category type ids
15
+ * @since 1.0.0
16
+ */
17
+ export declare const TypeId: unique symbol;
18
+ /**
19
+ * @category type ids
20
+ * @since 1.0.0
21
+ */
22
+ export type TypeId = typeof TypeId;
23
+ /**
24
+ * @category models
25
+ * @since 1.0.0
26
+ */
27
+ export interface SqliteClient extends Client.SqlClient {
28
+ readonly [TypeId]: TypeId;
29
+ readonly config: SqliteClientConfig;
30
+ /** Not supported in sqlite */
31
+ readonly updateValues: never;
32
+ }
33
+ /**
34
+ * @category tags
35
+ * @since 1.0.0
36
+ */
37
+ export declare const SqliteClient: Context.Tag<SqliteClient, SqliteClient>;
38
+ /**
39
+ * @category models
40
+ * @since 1.0.0
41
+ */
42
+ export interface SqliteClientConfig {
43
+ readonly db: SqlStorage;
44
+ readonly spanAttributes?: Record<string, unknown> | undefined;
45
+ readonly transformResultNames?: ((str: string) => string) | undefined;
46
+ readonly transformQueryNames?: ((str: string) => string) | undefined;
47
+ }
48
+ /**
49
+ * @category constructor
50
+ * @since 1.0.0
51
+ */
52
+ export declare const make: (options: SqliteClientConfig) => Effect.Effect<SqliteClient, never, Scope.Scope | Reactivity.Reactivity>;
53
+ /**
54
+ * @category layers
55
+ * @since 1.0.0
56
+ */
57
+ export declare const layerConfig: (config: Config.Config.Wrap<SqliteClientConfig>) => Layer.Layer<SqliteClient | Client.SqlClient, ConfigError>;
58
+ /**
59
+ * @category layers
60
+ * @since 1.0.0
61
+ */
62
+ export declare const layer: (config: SqliteClientConfig) => Layer.Layer<SqliteClient | Client.SqlClient, ConfigError>;
63
+ //# sourceMappingURL=SqliteClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteClient.d.ts","sourceRoot":"","sources":["../../src/SqliteClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK,UAAU,MAAM,iCAAiC,CAAA;AAC7D,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAK/C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK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AAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,EAAE,WAAW,CAMlB,CAAA"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as Migrator from "@effect/sql/Migrator";
5
+ import type * as Client from "@effect/sql/SqlClient";
6
+ import type { SqlError } from "@effect/sql/SqlError";
7
+ import type * as Effect from "effect/Effect";
8
+ import * as Layer from "effect/Layer";
9
+ /**
10
+ * @since 1.0.0
11
+ */
12
+ export * from "@effect/sql/Migrator";
13
+ /**
14
+ * @category constructor
15
+ * @since 1.0.0
16
+ */
17
+ export declare const run: <R2 = never>({ loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>;
18
+ /**
19
+ * @category constructor
20
+ * @since 1.0.0
21
+ */
22
+ export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R>;
23
+ //# sourceMappingURL=SqliteMigrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteMigrator.d.ts","sourceRoot":"","sources":["../../src/SqliteMigrator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;GAEG;AACH,cAAc,sBAAsB,CAAA;AAEpC;;;GAGG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAC3B,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAC7D,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAClC,MAAM,CAAC,SAAS,GAAG,EAAE,CACF,CAAA;AAErB;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,WACZ,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAAE,MAAM,CAAC,SAAS,GAAG,CAAC,CAAsC,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ export * as SqliteClient from "./SqliteClient.js";
5
+ /**
6
+ * @since 1.0.0
7
+ */
8
+ export * as SqliteMigrator from "./SqliteMigrator.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD;;GAEG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,112 @@
1
+ import * as Reactivity from "@effect/experimental/Reactivity";
2
+ import * as Client from "@effect/sql/SqlClient";
3
+ import { SqlError } from "@effect/sql/SqlError";
4
+ import * as Statement from "@effect/sql/Statement";
5
+ import * as Chunk from "effect/Chunk";
6
+ import * as Config from "effect/Config";
7
+ import * as Context from "effect/Context";
8
+ import * as Effect from "effect/Effect";
9
+ import { identity } from "effect/Function";
10
+ import * as Layer from "effect/Layer";
11
+ import * as Scope from "effect/Scope";
12
+ import * as Stream from "effect/Stream";
13
+ /**
14
+ * @category type ids
15
+ * @since 1.0.0
16
+ */
17
+ export const TypeId = /*#__PURE__*/Symbol.for("@effect/sql-sqlite-do/SqliteClient");
18
+ /**
19
+ * @category tags
20
+ * @since 1.0.0
21
+ */
22
+ export const SqliteClient = /*#__PURE__*/Context.GenericTag("@effect/sql-sqlite-do/SqliteClient");
23
+ /**
24
+ * @category constructor
25
+ * @since 1.0.0
26
+ */
27
+ export const make = options => Effect.gen(function* () {
28
+ const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
29
+ const transformRows = options.transformResultNames ? Statement.defaultTransforms(options.transformResultNames).array : undefined;
30
+ const makeConnection = Effect.gen(function* () {
31
+ const db = options.db;
32
+ function* runIterator(sql, params = []) {
33
+ const cursor = db.exec(sql, ...params);
34
+ const columns = cursor.columnNames;
35
+ for (const result of cursor.raw()) {
36
+ const obj = {};
37
+ for (let i = 0; i < columns.length; i++) {
38
+ const value = result[i];
39
+ obj[columns[i]] = value instanceof ArrayBuffer ? new Uint8Array(value) : value;
40
+ }
41
+ yield obj;
42
+ }
43
+ }
44
+ const runStatement = (sql, params = []) => Effect.try({
45
+ try: () => Array.from(runIterator(sql, params)),
46
+ catch: cause => new SqlError({
47
+ cause,
48
+ message: `Failed to execute statement`
49
+ })
50
+ });
51
+ const runValues = (sql, params = []) => Effect.try({
52
+ try: () => Array.from(db.exec(sql, ...params).raw(), row => {
53
+ for (let i = 0; i < row.length; i++) {
54
+ const value = row[i];
55
+ if (value instanceof ArrayBuffer) {
56
+ row[i] = new Uint8Array(value);
57
+ }
58
+ }
59
+ return row;
60
+ }),
61
+ catch: cause => new SqlError({
62
+ cause,
63
+ message: `Failed to execute statement`
64
+ })
65
+ });
66
+ return identity({
67
+ execute(sql, params, transformRows) {
68
+ return transformRows ? Effect.map(runStatement(sql, params), transformRows) : runStatement(sql, params);
69
+ },
70
+ executeRaw(sql, params) {
71
+ return runStatement(sql, params);
72
+ },
73
+ executeValues(sql, params) {
74
+ return runValues(sql, params);
75
+ },
76
+ executeUnprepared(sql, params, transformRows) {
77
+ return transformRows ? Effect.map(runStatement(sql, params), transformRows) : runStatement(sql, params);
78
+ },
79
+ executeStream(sql, params, transformRows) {
80
+ return Stream.suspend(() => {
81
+ const iterator = runIterator(sql, params);
82
+ return Stream.fromIteratorSucceed(iterator, 16);
83
+ }).pipe(transformRows ? Stream.mapChunks(chunk => Chunk.unsafeFromArray(transformRows(Chunk.toReadonlyArray(chunk)))) : identity);
84
+ }
85
+ });
86
+ });
87
+ const semaphore = yield* Effect.makeSemaphore(1);
88
+ const connection = yield* makeConnection;
89
+ const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
90
+ const transactionAcquirer = Effect.uninterruptibleMask(restore => Effect.as(Effect.zipRight(restore(semaphore.take(1)), Effect.tap(Effect.scope, scope => Scope.addFinalizer(scope, semaphore.release(1)))), connection));
91
+ return Object.assign(yield* Client.make({
92
+ acquirer,
93
+ compiler,
94
+ transactionAcquirer,
95
+ spanAttributes: [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), ["db.system", "sqlite"]],
96
+ transformRows
97
+ }), {
98
+ [TypeId]: TypeId,
99
+ config: options
100
+ });
101
+ });
102
+ /**
103
+ * @category layers
104
+ * @since 1.0.0
105
+ */
106
+ export const layerConfig = config => Layer.scopedContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(SqliteClient, client).pipe(Context.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
107
+ /**
108
+ * @category layers
109
+ * @since 1.0.0
110
+ */
111
+ export const layer = config => Layer.scopedContext(Effect.map(make(config), client => Context.make(SqliteClient, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
112
+ //# sourceMappingURL=SqliteClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteClient.js","names":["Reactivity","Client","SqlError","Statement","Chunk","Config","Context","Effect","identity","Layer","Scope","Stream","TypeId","Symbol","for","SqliteClient","GenericTag","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","makeConnection","db","runIterator","sql","params","cursor","exec","columns","columnNames","result","raw","obj","i","length","value","ArrayBuffer","Uint8Array","runStatement","try","Array","from","catch","cause","message","runValues","row","execute","map","executeRaw","executeValues","executeUnprepared","executeStream","suspend","iterator","fromIteratorSucceed","pipe","mapChunks","chunk","unsafeFromArray","toReadonlyArray","semaphore","makeSemaphore","connection","acquirer","withPermits","succeed","transactionAcquirer","uninterruptibleMask","restore","as","zipRight","take","tap","scope","addFinalizer","release","Object","assign","spanAttributes","entries","config","layerConfig","scopedContext","unwrap","flatMap","client","add","SqlClient","provide","layer"],"sources":["../../src/SqliteClient.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,UAAU,MAAM,iCAAiC;AAC7D,OAAO,KAAKC,MAAM,MAAM,uBAAuB;AAE/C,SAASC,QAAQ,QAAQ,sBAAsB;AAC/C,OAAO,KAAKC,SAAS,MAAM,uBAAuB;AAClD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC;;;;AAIA,OAAO,MAAMC,MAAM,gBAAkBC,MAAM,CAACC,GAAG,CAAC,oCAAoC,CAAC;AAoBrF;;;;AAIA,OAAO,MAAMC,YAAY,gBAAGT,OAAO,CAACU,UAAU,CAAe,oCAAoC,CAAC;AAclG;;;;AAIA,OAAO,MAAMC,IAAI,GACfC,OAA2B,IAE3BX,MAAM,CAACY,GAAG,CAAC,aAAS;EAClB,MAAMC,QAAQ,GAAGjB,SAAS,CAACkB,kBAAkB,CAACH,OAAO,CAACI,mBAAmB,CAAC;EAC1E,MAAMC,aAAa,GAAGL,OAAO,CAACM,oBAAoB,GAC9CrB,SAAS,CAAC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AM,CAACG,OAAO,CAACrE,OAAO,CAACoE,cAAc,CAAC,GAAG,EAAE,CAAC,EACzE,CAAC,WAAW,EAAE,QAAQ,CAAC,CACxB;IACD/D;GACD,CAAC,EACF;IACE,CAACX,MAAM,GAAGA,MAAgB;IAC1B4E,MAAM,EAAEtE;GACT,CACF;AACH,CAAC,CAAC;AAEJ;;;;AAIA,OAAO,MAAMuE,WAAW,GACtBD,MAA8C,IAE9C/E,KAAK,CAACiF,aAAa,CACjBrF,MAAM,CAACsF,MAAM,CAACH,MAAM,CAAC,CAACzB,IAAI,CACxBxD,MAAM,CAACqF,OAAO,CAAC3E,IAAI,CAAC,EACpBV,MAAM,CAACgD,GAAG,CAAEsC,MAAM,IAChBvF,OAAO,CAACW,IAAI,CAACF,YAAY,EAAE8E,MAAM,CAAC,CAAC9B,IAAI,CACrCzD,OAAO,CAACwF,GAAG,CAAC7F,MAAM,CAAC8F,SAAS,EAAEF,MAAM,CAAC,CACtC,CACF,CACF,CACF,CAAC9B,IAAI,CAACtD,KAAK,CAACuF,OAAO,CAAChG,UAAU,CAACiG,KAAK,CAAC,CAAC;AAEzC;;;;AAIA,OAAO,MAAMA,KAAK,GAChBT,MAA0B,IAE1B/E,KAAK,CAACiF,aAAa,CACjBnF,MAAM,CAACgD,GAAG,CAACtC,IAAI,CAACuE,MAAM,CAAC,EAAGK,MAAM,IAC9BvF,OAAO,CAACW,IAAI,CAACF,YAAY,EAAE8E,MAAM,CAAC,CAAC9B,IAAI,CACrCzD,OAAO,CAACwF,GAAG,CAAC7F,MAAM,CAAC8F,SAAS,EAAEF,MAAM,CAAC,CACtC,CAAC,CACL,CAAC9B,IAAI,CAACtD,KAAK,CAACuF,OAAO,CAAChG,UAAU,CAACiG,KAAK,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as Migrator from "@effect/sql/Migrator";
5
+ import * as Layer from "effect/Layer";
6
+ /**
7
+ * @since 1.0.0
8
+ */
9
+ export * from "@effect/sql/Migrator";
10
+ /**
11
+ * @category constructor
12
+ * @since 1.0.0
13
+ */
14
+ export const run = /*#__PURE__*/Migrator.make({});
15
+ /**
16
+ * @category constructor
17
+ * @since 1.0.0
18
+ */
19
+ export const layer = options => Layer.effectDiscard(run(options));
20
+ //# sourceMappingURL=SqliteMigrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteMigrator.js","names":["Migrator","Layer","run","make","layer","options","effectDiscard"],"sources":["../../src/SqliteMigrator.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,QAAQ,MAAM,sBAAsB;AAIhD,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC;;;AAGA,cAAc,sBAAsB;AAEpC;;;;AAIA,OAAO,MAAMC,GAAG,gBAMZF,QAAQ,CAACG,IAAI,CAAC,EAAE,CAAC;AAErB;;;;AAIA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAC6CJ,KAAK,CAACK,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ export * as SqliteClient from "./SqliteClient.js";
5
+ /**
6
+ * @since 1.0.0
7
+ */
8
+ export * as SqliteMigrator from "./SqliteMigrator.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["SqliteClient","SqliteMigrator"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,YAAY,MAAM,mBAAmB;AAEjD;;;AAGA,OAAO,KAAKC,cAAc,MAAM,qBAAqB","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": []
4
+ }
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@effect/sql-sqlite-do",
3
+ "version": "0.1.0",
4
+ "description": "A SQLite toolkit for Effect",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/Effect-TS/effect.git",
9
+ "directory": "packages/sql-sqlite-do"
10
+ },
11
+ "sideEffects": [],
12
+ "dependencies": {
13
+ "@opentelemetry/semantic-conventions": "^1.25.1"
14
+ },
15
+ "peerDependencies": {
16
+ "@effect/experimental": "^0.34.2",
17
+ "effect": "^3.11.7",
18
+ "@effect/sql": "^0.23.2"
19
+ },
20
+ "publishConfig": {
21
+ "provenance": true
22
+ },
23
+ "main": "./dist/cjs/index.js",
24
+ "module": "./dist/esm/index.js",
25
+ "types": "./dist/dts/index.d.ts",
26
+ "exports": {
27
+ "./package.json": "./package.json",
28
+ ".": {
29
+ "types": "./dist/dts/index.d.ts",
30
+ "import": "./dist/esm/index.js",
31
+ "default": "./dist/cjs/index.js"
32
+ },
33
+ "./SqliteClient": {
34
+ "types": "./dist/dts/SqliteClient.d.ts",
35
+ "import": "./dist/esm/SqliteClient.js",
36
+ "default": "./dist/cjs/SqliteClient.js"
37
+ },
38
+ "./SqliteMigrator": {
39
+ "types": "./dist/dts/SqliteMigrator.d.ts",
40
+ "import": "./dist/esm/SqliteMigrator.js",
41
+ "default": "./dist/cjs/SqliteMigrator.js"
42
+ }
43
+ },
44
+ "typesVersions": {
45
+ "*": {
46
+ "SqliteClient": [
47
+ "./dist/dts/SqliteClient.d.ts"
48
+ ],
49
+ "SqliteMigrator": [
50
+ "./dist/dts/SqliteMigrator.d.ts"
51
+ ]
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,220 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import type { SqlStorage } from "@cloudflare/workers-types"
5
+ import * as Reactivity from "@effect/experimental/Reactivity"
6
+ import * as Client from "@effect/sql/SqlClient"
7
+ import type { Connection } from "@effect/sql/SqlConnection"
8
+ import { SqlError } from "@effect/sql/SqlError"
9
+ import * as Statement from "@effect/sql/Statement"
10
+ import * as Chunk from "effect/Chunk"
11
+ import * as Config from "effect/Config"
12
+ import type { ConfigError } from "effect/ConfigError"
13
+ import * as Context from "effect/Context"
14
+ import * as Effect from "effect/Effect"
15
+ import { identity } from "effect/Function"
16
+ import * as Layer from "effect/Layer"
17
+ import * as Scope from "effect/Scope"
18
+ import * as Stream from "effect/Stream"
19
+
20
+ /**
21
+ * @category type ids
22
+ * @since 1.0.0
23
+ */
24
+ export const TypeId: unique symbol = Symbol.for("@effect/sql-sqlite-do/SqliteClient")
25
+
26
+ /**
27
+ * @category type ids
28
+ * @since 1.0.0
29
+ */
30
+ export type TypeId = typeof TypeId
31
+
32
+ /**
33
+ * @category models
34
+ * @since 1.0.0
35
+ */
36
+ export interface SqliteClient extends Client.SqlClient {
37
+ readonly [TypeId]: TypeId
38
+ readonly config: SqliteClientConfig
39
+
40
+ /** Not supported in sqlite */
41
+ readonly updateValues: never
42
+ }
43
+
44
+ /**
45
+ * @category tags
46
+ * @since 1.0.0
47
+ */
48
+ export const SqliteClient = Context.GenericTag<SqliteClient>("@effect/sql-sqlite-do/SqliteClient")
49
+
50
+ /**
51
+ * @category models
52
+ * @since 1.0.0
53
+ */
54
+ export interface SqliteClientConfig {
55
+ readonly db: SqlStorage
56
+ readonly spanAttributes?: Record<string, unknown> | undefined
57
+
58
+ readonly transformResultNames?: ((str: string) => string) | undefined
59
+ readonly transformQueryNames?: ((str: string) => string) | undefined
60
+ }
61
+
62
+ /**
63
+ * @category constructor
64
+ * @since 1.0.0
65
+ */
66
+ export const make = (
67
+ options: SqliteClientConfig
68
+ ): Effect.Effect<SqliteClient, never, Scope.Scope | Reactivity.Reactivity> =>
69
+ Effect.gen(function*() {
70
+ const compiler = Statement.makeCompilerSqlite(options.transformQueryNames)
71
+ const transformRows = options.transformResultNames
72
+ ? Statement.defaultTransforms(options.transformResultNames).array
73
+ : undefined
74
+
75
+ const makeConnection = Effect.gen(function*() {
76
+ const db = options.db
77
+
78
+ function* runIterator(
79
+ sql: string,
80
+ params: ReadonlyArray<Statement.Primitive> = []
81
+ ) {
82
+ const cursor = db.exec(sql, ...params)
83
+ const columns = cursor.columnNames
84
+ for (const result of cursor.raw()) {
85
+ const obj: any = {}
86
+ for (let i = 0; i < columns.length; i++) {
87
+ const value = result[i]
88
+ obj[columns[i]] = value instanceof ArrayBuffer ? new Uint8Array(value) : value
89
+ }
90
+ yield obj
91
+ }
92
+ }
93
+
94
+ const runStatement = (
95
+ sql: string,
96
+ params: ReadonlyArray<Statement.Primitive> = []
97
+ ): Effect.Effect<ReadonlyArray<any>, SqlError, never> =>
98
+ Effect.try({
99
+ try: () => Array.from(runIterator(sql, params)),
100
+ catch: (cause) => new SqlError({ cause, message: `Failed to execute statement` })
101
+ })
102
+
103
+ const runValues = (
104
+ sql: string,
105
+ params: ReadonlyArray<Statement.Primitive> = []
106
+ ): Effect.Effect<ReadonlyArray<any>, SqlError, never> =>
107
+ Effect.try({
108
+ try: () =>
109
+ Array.from(db.exec(sql, ...params).raw(), (row) => {
110
+ for (let i = 0; i < row.length; i++) {
111
+ const value = row[i]
112
+ if (value instanceof ArrayBuffer) {
113
+ row[i] = new Uint8Array(value) as any
114
+ }
115
+ }
116
+ return row
117
+ }),
118
+ catch: (cause) => new SqlError({ cause, message: `Failed to execute statement` })
119
+ })
120
+
121
+ return identity<Connection>({
122
+ execute(sql, params, transformRows) {
123
+ return transformRows
124
+ ? Effect.map(runStatement(sql, params), transformRows)
125
+ : runStatement(sql, params)
126
+ },
127
+ executeRaw(sql, params) {
128
+ return runStatement(sql, params)
129
+ },
130
+ executeValues(sql, params) {
131
+ return runValues(sql, params)
132
+ },
133
+ executeUnprepared(sql, params, transformRows) {
134
+ return transformRows
135
+ ? Effect.map(runStatement(sql, params), transformRows)
136
+ : runStatement(sql, params)
137
+ },
138
+ executeStream(sql, params, transformRows) {
139
+ return Stream.suspend(() => {
140
+ const iterator = runIterator(sql, params)
141
+ return Stream.fromIteratorSucceed(iterator, 16)
142
+ }).pipe(
143
+ transformRows
144
+ ? Stream.mapChunks((chunk) =>
145
+ Chunk.unsafeFromArray(
146
+ transformRows(Chunk.toReadonlyArray(chunk))
147
+ )
148
+ )
149
+ : identity
150
+ )
151
+ }
152
+ })
153
+ })
154
+
155
+ const semaphore = yield* Effect.makeSemaphore(1)
156
+ const connection = yield* makeConnection
157
+
158
+ const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
159
+ const transactionAcquirer = Effect.uninterruptibleMask((restore) =>
160
+ Effect.as(
161
+ Effect.zipRight(
162
+ restore(semaphore.take(1)),
163
+ Effect.tap(
164
+ Effect.scope,
165
+ (scope) => Scope.addFinalizer(scope, semaphore.release(1))
166
+ )
167
+ ),
168
+ connection
169
+ )
170
+ )
171
+
172
+ return Object.assign(
173
+ (yield* Client.make({
174
+ acquirer,
175
+ compiler,
176
+ transactionAcquirer,
177
+ spanAttributes: [
178
+ ...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
179
+ ["db.system", "sqlite"]
180
+ ],
181
+ transformRows
182
+ })) as SqliteClient,
183
+ {
184
+ [TypeId]: TypeId as TypeId,
185
+ config: options
186
+ }
187
+ )
188
+ })
189
+
190
+ /**
191
+ * @category layers
192
+ * @since 1.0.0
193
+ */
194
+ export const layerConfig = (
195
+ config: Config.Config.Wrap<SqliteClientConfig>
196
+ ): Layer.Layer<SqliteClient | Client.SqlClient, ConfigError> =>
197
+ Layer.scopedContext(
198
+ Config.unwrap(config).pipe(
199
+ Effect.flatMap(make),
200
+ Effect.map((client) =>
201
+ Context.make(SqliteClient, client).pipe(
202
+ Context.add(Client.SqlClient, client)
203
+ )
204
+ )
205
+ )
206
+ ).pipe(Layer.provide(Reactivity.layer))
207
+
208
+ /**
209
+ * @category layers
210
+ * @since 1.0.0
211
+ */
212
+ export const layer = (
213
+ config: SqliteClientConfig
214
+ ): Layer.Layer<SqliteClient | Client.SqlClient, ConfigError> =>
215
+ Layer.scopedContext(
216
+ Effect.map(make(config), (client) =>
217
+ Context.make(SqliteClient, client).pipe(
218
+ Context.add(Client.SqlClient, client)
219
+ ))
220
+ ).pipe(Layer.provide(Reactivity.layer))
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as Migrator from "@effect/sql/Migrator"
5
+ import type * as Client from "@effect/sql/SqlClient"
6
+ import type { SqlError } from "@effect/sql/SqlError"
7
+ import type * as Effect from "effect/Effect"
8
+ import * as Layer from "effect/Layer"
9
+
10
+ /**
11
+ * @since 1.0.0
12
+ */
13
+ export * from "@effect/sql/Migrator"
14
+
15
+ /**
16
+ * @category constructor
17
+ * @since 1.0.0
18
+ */
19
+ export const run: <R2 = never>(
20
+ { loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>
21
+ ) => Effect.Effect<
22
+ ReadonlyArray<readonly [id: number, name: string]>,
23
+ Migrator.MigrationError | SqlError,
24
+ Client.SqlClient | R2
25
+ > = Migrator.make({})
26
+
27
+ /**
28
+ * @category constructor
29
+ * @since 1.0.0
30
+ */
31
+ export const layer = <R>(
32
+ options: Migrator.MigratorOptions<R>
33
+ ): Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R> => Layer.effectDiscard(run(options))
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ export * as SqliteClient from "./SqliteClient.js"
5
+
6
+ /**
7
+ * @since 1.0.0
8
+ */
9
+ export * as SqliteMigrator from "./SqliteMigrator.js"