@effect/sql-libsql 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/LibsqlClient/package.json +6 -0
- package/LibsqlMigrator/package.json +6 -0
- package/README.md +5 -0
- package/dist/cjs/LibsqlClient.js +107 -0
- package/dist/cjs/LibsqlClient.js.map +1 -0
- package/dist/cjs/LibsqlMigrator.js +61 -0
- package/dist/cjs/LibsqlMigrator.js.map +1 -0
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/dts/LibsqlClient.d.ts +90 -0
- package/dist/dts/LibsqlClient.d.ts.map +1 -0
- package/dist/dts/LibsqlMigrator.d.ts +27 -0
- package/dist/dts/LibsqlMigrator.d.ts.map +1 -0
- package/dist/dts/index.d.ts +9 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/esm/LibsqlClient.js +96 -0
- package/dist/esm/LibsqlClient.js.map +1 -0
- package/dist/esm/LibsqlMigrator.js +24 -0
- package/dist/esm/LibsqlMigrator.js.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +4 -0
- package/package.json +55 -0
- package/src/LibsqlClient.ts +207 -0
- package/src/LibsqlMigrator.ts +38 -0
- package/src/index.ts +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-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,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.make = exports.layer = exports.TypeId = exports.LibsqlClient = void 0;
|
|
7
|
+
var Client = _interopRequireWildcard(require("@effect/sql/SqlClient"));
|
|
8
|
+
var _SqlError = require("@effect/sql/SqlError");
|
|
9
|
+
var Statement = _interopRequireWildcard(require("@effect/sql/Statement"));
|
|
10
|
+
var Libsql = _interopRequireWildcard(require("@libsql/client"));
|
|
11
|
+
var Otel = _interopRequireWildcard(require("@opentelemetry/semantic-conventions"));
|
|
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
|
+
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); }
|
|
19
|
+
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; }
|
|
20
|
+
/**
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @category type ids
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
const TypeId = exports.TypeId = /*#__PURE__*/Symbol.for("@effect/sql-libsql/LibsqlClient");
|
|
29
|
+
/**
|
|
30
|
+
* @category tags
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
*/
|
|
33
|
+
const LibsqlClient = exports.LibsqlClient = /*#__PURE__*/Context.GenericTag("@effect/sql-libsql/LibsqlClient");
|
|
34
|
+
/**
|
|
35
|
+
* @category constructor
|
|
36
|
+
* @since 1.0.0
|
|
37
|
+
*/
|
|
38
|
+
const make = options => Effect.gen(function* () {
|
|
39
|
+
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
40
|
+
const transformRows = Statement.defaultTransforms(options.transformResultNames).array;
|
|
41
|
+
const makeConnection = Effect.gen(function* () {
|
|
42
|
+
const db = Libsql.createClient(options);
|
|
43
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => db.close()));
|
|
44
|
+
const run = (sql, params = []) => Effect.tryPromise({
|
|
45
|
+
try: () => db.execute({
|
|
46
|
+
sql,
|
|
47
|
+
args: params
|
|
48
|
+
}).then(results => results.rows),
|
|
49
|
+
catch: cause => new _SqlError.SqlError({
|
|
50
|
+
cause,
|
|
51
|
+
message: "Failed to execute statement"
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
const runRaw = (sql, params = []) => Effect.tryPromise({
|
|
55
|
+
try: () => db.execute({
|
|
56
|
+
sql,
|
|
57
|
+
args: params
|
|
58
|
+
}),
|
|
59
|
+
catch: cause => new _SqlError.SqlError({
|
|
60
|
+
cause,
|
|
61
|
+
message: "Failed to execute statement"
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
const runTransform = options.transformResultNames ? (sql, params) => Effect.map(run(sql, params), transformRows) : run;
|
|
65
|
+
return (0, _Function.identity)({
|
|
66
|
+
execute(sql, params) {
|
|
67
|
+
return runTransform(sql, params);
|
|
68
|
+
},
|
|
69
|
+
executeRaw(sql, params) {
|
|
70
|
+
return runRaw(sql, params);
|
|
71
|
+
},
|
|
72
|
+
executeValues(sql, params) {
|
|
73
|
+
return Effect.map(run(sql, params), rows => rows.map(row => Array.from(row)));
|
|
74
|
+
},
|
|
75
|
+
executeWithoutTransform(sql, params) {
|
|
76
|
+
return run(sql, params);
|
|
77
|
+
},
|
|
78
|
+
executeUnprepared(sql, params) {
|
|
79
|
+
return run(sql, params);
|
|
80
|
+
},
|
|
81
|
+
executeStream(_sql, _params) {
|
|
82
|
+
return Effect.dieMessage("executeStream not implemented");
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
const semaphore = yield* Effect.makeSemaphore(1);
|
|
87
|
+
const connection = yield* makeConnection;
|
|
88
|
+
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
89
|
+
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));
|
|
90
|
+
return Object.assign(Client.make({
|
|
91
|
+
acquirer,
|
|
92
|
+
compiler,
|
|
93
|
+
transactionAcquirer,
|
|
94
|
+
spanAttributes: [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), [Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]]
|
|
95
|
+
}), {
|
|
96
|
+
[TypeId]: TypeId,
|
|
97
|
+
config: options
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* @category layers
|
|
102
|
+
* @since 1.0.0
|
|
103
|
+
*/
|
|
104
|
+
exports.make = make;
|
|
105
|
+
const layer = config => Layer.scopedContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(LibsqlClient, client).pipe(Context.add(Client.SqlClient, client)))));
|
|
106
|
+
exports.layer = layer;
|
|
107
|
+
//# sourceMappingURL=LibsqlClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LibsqlClient.js","names":["Client","_interopRequireWildcard","require","_SqlError","Statement","Libsql","Otel","Config","Context","Effect","_Function","Layer","Scope","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","TypeId","exports","Symbol","for","LibsqlClient","GenericTag","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","defaultTransforms","transformResultNames","array","makeConnection","db","createClient","addFinalizer","sync","close","run","sql","params","tryPromise","try","execute","args","then","results","rows","catch","cause","SqlError","message","runRaw","runTransform","map","identity","executeRaw","executeValues","row","Array","from","executeWithoutTransform","executeUnprepared","executeStream","_sql","_params","dieMessage","semaphore","makeSemaphore","connection","acquirer","withPermits","succeed","transactionAcquirer","uninterruptibleMask","restore","as","zipRight","take","tap","scope","release","assign","spanAttributes","entries","SEMATTRS_DB_SYSTEM","DBSYSTEMVALUES_SQLITE","config","layer","scopedContext","unwrap","pipe","flatMap","client","add","SqlClient"],"sources":["../../src/LibsqlClient.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAA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B,EAClB;IACE,CAACtE,MAAM,GAAGA,MAAgB;IAC1BuE,MAAM,EAAEhE;GACT,CACF;AACH,CAAC,CAAC;AAEJ;;;;AAAAN,OAAA,CAAAK,IAAA,GAAAA,IAAA;AAIO,MAAMkE,KAAK,GAChBD,MAA8C,IAE9C7F,KAAK,CAAC+F,aAAa,CACjBnG,MAAM,CAACoG,MAAM,CAACH,MAAM,CAAC,CAACI,IAAI,CACxBnG,MAAM,CAACoG,OAAO,CAACtE,IAAI,CAAC,EACpB9B,MAAM,CAAC8D,GAAG,CAAEuC,MAAM,IAChBtG,OAAO,CAAC+B,IAAI,CAACF,YAAY,EAAEyE,MAAM,CAAC,CAACF,IAAI,CACrCpG,OAAO,CAACuG,GAAG,CAAC/G,MAAM,CAACgH,SAAS,EAAEF,MAAM,CAAC,CACtC,CACF,CACF,CACF;AAAA5E,OAAA,CAAAuE,KAAA,GAAAA,KAAA","ignoreList":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
var _FileSystem = require("@effect/sql/Migrator/FileSystem");
|
|
25
|
+
Object.keys(_FileSystem).forEach(function (key) {
|
|
26
|
+
if (key === "default" || key === "__esModule") return;
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
28
|
+
if (key in exports && exports[key] === _FileSystem[key]) return;
|
|
29
|
+
Object.defineProperty(exports, key, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () {
|
|
32
|
+
return _FileSystem[key];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
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); }
|
|
37
|
+
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; }
|
|
38
|
+
/**
|
|
39
|
+
* @since 1.0.0
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @since 1.0.0
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @category constructor
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
*/
|
|
54
|
+
const run = exports.run = /*#__PURE__*/Migrator.make({});
|
|
55
|
+
/**
|
|
56
|
+
* @category constructor
|
|
57
|
+
* @since 1.0.0
|
|
58
|
+
*/
|
|
59
|
+
const layer = options => Layer.effectDiscard(run(options));
|
|
60
|
+
exports.layer = layer;
|
|
61
|
+
//# sourceMappingURL=LibsqlMigrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LibsqlMigrator.js","names":["Migrator","_interopRequireWildcard","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","Layer","_FileSystem","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set","run","make","layer","options","effectDiscard"],"sources":["../../src/LibsqlMigrator.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;AAUA,IAAAc,WAAA,GAAAd,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAY,WAAA,EAAAX,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,MAAAU,WAAA,CAAAV,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;I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AArB,OAAA,CAAAqB,GAAA,gBAMZhC,QAAQ,CAACiC,IAAI,CAAC,EAAE,CAAC;AAErB;;;;AAIO,MAAMC,KAAK,GAChBC,OAAoC,IAC6CpB,KAAK,CAACqB,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC;AAAAxB,OAAA,CAAAuB,KAAA,GAAAA,KAAA","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LibsqlMigrator = exports.LibsqlClient = void 0;
|
|
7
|
+
var _LibsqlClient = _interopRequireWildcard(require("./LibsqlClient.js"));
|
|
8
|
+
exports.LibsqlClient = _LibsqlClient;
|
|
9
|
+
var _LibsqlMigrator = _interopRequireWildcard(require("./LibsqlMigrator.js"));
|
|
10
|
+
exports.LibsqlMigrator = _LibsqlMigrator;
|
|
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,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Client from "@effect/sql/SqlClient";
|
|
5
|
+
import * as Config from "effect/Config";
|
|
6
|
+
import type { ConfigError } from "effect/ConfigError";
|
|
7
|
+
import * as Context from "effect/Context";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
import * as Scope from "effect/Scope";
|
|
11
|
+
/**
|
|
12
|
+
* @category type ids
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
export declare const TypeId: unique symbol;
|
|
16
|
+
/**
|
|
17
|
+
* @category type ids
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
export type TypeId = typeof TypeId;
|
|
21
|
+
/**
|
|
22
|
+
* @category models
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
*/
|
|
25
|
+
export interface LibsqlClient extends Client.SqlClient {
|
|
26
|
+
readonly [TypeId]: TypeId;
|
|
27
|
+
readonly config: LibsqlClientConfig;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @category tags
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
*/
|
|
33
|
+
export declare const LibsqlClient: Context.Tag<LibsqlClient, LibsqlClient>;
|
|
34
|
+
/**
|
|
35
|
+
* @category models
|
|
36
|
+
* @since 1.0.0
|
|
37
|
+
*/
|
|
38
|
+
export interface LibsqlClientConfig {
|
|
39
|
+
/** The database URL.
|
|
40
|
+
*
|
|
41
|
+
* The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation,
|
|
42
|
+
* please refer to the project README:
|
|
43
|
+
*
|
|
44
|
+
* https://github.com/libsql/libsql-client-ts#supported-urls
|
|
45
|
+
*/
|
|
46
|
+
readonly url: string;
|
|
47
|
+
/** Authentication token for the database. */
|
|
48
|
+
readonly authToken?: string | undefined;
|
|
49
|
+
/** Encryption key for the database. */
|
|
50
|
+
readonly encryptionKey?: string | undefined;
|
|
51
|
+
/** URL of a remote server to synchronize database with. */
|
|
52
|
+
readonly syncUrl?: string | undefined;
|
|
53
|
+
/** Sync interval in seconds. */
|
|
54
|
+
readonly syncInterval?: number | undefined;
|
|
55
|
+
/** Enables or disables TLS for `libsql:` URLs.
|
|
56
|
+
*
|
|
57
|
+
* By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.
|
|
58
|
+
*/
|
|
59
|
+
readonly tls?: boolean | undefined;
|
|
60
|
+
/** How to convert SQLite integers to JavaScript values:
|
|
61
|
+
*
|
|
62
|
+
* - `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats).
|
|
63
|
+
* `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read
|
|
64
|
+
* larger integers will throw a `RangeError`.
|
|
65
|
+
* - `"bigint"`: returns SQLite integers as JavaScript `bigint`-s (arbitrary precision integers). Bigints can
|
|
66
|
+
* precisely represent all SQLite integers.
|
|
67
|
+
* - `"string"`: returns SQLite integers as strings.
|
|
68
|
+
*/
|
|
69
|
+
readonly intMode?: "number" | "bigint" | "string" | undefined;
|
|
70
|
+
/** Concurrency limit.
|
|
71
|
+
*
|
|
72
|
+
* By default, the client performs up to 20 concurrent requests. You can set this option to a higher
|
|
73
|
+
* number to increase the concurrency limit or set it to 0 to disable concurrency limits completely.
|
|
74
|
+
*/
|
|
75
|
+
readonly concurrency?: number | undefined;
|
|
76
|
+
readonly spanAttributes?: Record<string, unknown> | undefined;
|
|
77
|
+
readonly transformResultNames?: ((str: string) => string) | undefined;
|
|
78
|
+
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @category constructor
|
|
82
|
+
* @since 1.0.0
|
|
83
|
+
*/
|
|
84
|
+
export declare const make: (options: LibsqlClientConfig) => Effect.Effect<LibsqlClient, never, Scope.Scope>;
|
|
85
|
+
/**
|
|
86
|
+
* @category layers
|
|
87
|
+
* @since 1.0.0
|
|
88
|
+
*/
|
|
89
|
+
export declare const layer: (config: Config.Config.Wrap<LibsqlClientConfig>) => Layer.Layer<LibsqlClient | Client.SqlClient, ConfigError>;
|
|
90
|
+
//# sourceMappingURL=LibsqlClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LibsqlClient.d.ts","sourceRoot":"","sources":["../../src/LibsqlClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAM/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,MAAM,cAAc,CAAA;AAErC;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,OAAO,MAAsD,CAAA;AAElF;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAA;AAElC;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,SAAS;IACpD,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;CACpC;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,yCAAsE,CAAA;AAE/F;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACvC,uCAAuC;IACvC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3C,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC,gCAAgC;IAChC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1C;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAClC;;;;;;;;OAQG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;IAC7D;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAEzC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IAE7D,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;AAID;;;GAGG;AACH,eAAO,MAAM,IAAI,YACN,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAuF7C,CAAA;AAEJ;;;GAGG;AACH,eAAO,MAAM,KAAK,WACR,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAC7C,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,EAAE,WAAW,CAUxD,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
* @since 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
export * from "@effect/sql/Migrator/FileSystem";
|
|
17
|
+
/**
|
|
18
|
+
* @category constructor
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*/
|
|
21
|
+
export declare const run: <R2 = never>(options: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>;
|
|
22
|
+
/**
|
|
23
|
+
* @category constructor
|
|
24
|
+
* @since 1.0.0
|
|
25
|
+
*/
|
|
26
|
+
export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R>;
|
|
27
|
+
//# sourceMappingURL=LibsqlMigrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LibsqlMigrator.d.ts","sourceRoot":"","sources":["../../src/LibsqlMigrator.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;;GAEG;AACH,cAAc,iCAAiC,CAAA;AAE/C;;;GAGG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAC3B,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAClC,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 @@
|
|
|
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,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Client from "@effect/sql/SqlClient";
|
|
5
|
+
import { SqlError } from "@effect/sql/SqlError";
|
|
6
|
+
import * as Statement from "@effect/sql/Statement";
|
|
7
|
+
import * as Libsql from "@libsql/client";
|
|
8
|
+
import * as Otel from "@opentelemetry/semantic-conventions";
|
|
9
|
+
import * as Config from "effect/Config";
|
|
10
|
+
import * as Context from "effect/Context";
|
|
11
|
+
import * as Effect from "effect/Effect";
|
|
12
|
+
import { identity } from "effect/Function";
|
|
13
|
+
import * as Layer from "effect/Layer";
|
|
14
|
+
import * as Scope from "effect/Scope";
|
|
15
|
+
/**
|
|
16
|
+
* @category type ids
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
export const TypeId = /*#__PURE__*/Symbol.for("@effect/sql-libsql/LibsqlClient");
|
|
20
|
+
/**
|
|
21
|
+
* @category tags
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
export const LibsqlClient = /*#__PURE__*/Context.GenericTag("@effect/sql-libsql/LibsqlClient");
|
|
25
|
+
/**
|
|
26
|
+
* @category constructor
|
|
27
|
+
* @since 1.0.0
|
|
28
|
+
*/
|
|
29
|
+
export const make = options => Effect.gen(function* () {
|
|
30
|
+
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
31
|
+
const transformRows = Statement.defaultTransforms(options.transformResultNames).array;
|
|
32
|
+
const makeConnection = Effect.gen(function* () {
|
|
33
|
+
const db = Libsql.createClient(options);
|
|
34
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => db.close()));
|
|
35
|
+
const run = (sql, params = []) => Effect.tryPromise({
|
|
36
|
+
try: () => db.execute({
|
|
37
|
+
sql,
|
|
38
|
+
args: params
|
|
39
|
+
}).then(results => results.rows),
|
|
40
|
+
catch: cause => new SqlError({
|
|
41
|
+
cause,
|
|
42
|
+
message: "Failed to execute statement"
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
const runRaw = (sql, params = []) => Effect.tryPromise({
|
|
46
|
+
try: () => db.execute({
|
|
47
|
+
sql,
|
|
48
|
+
args: params
|
|
49
|
+
}),
|
|
50
|
+
catch: cause => new SqlError({
|
|
51
|
+
cause,
|
|
52
|
+
message: "Failed to execute statement"
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
const runTransform = options.transformResultNames ? (sql, params) => Effect.map(run(sql, params), transformRows) : run;
|
|
56
|
+
return identity({
|
|
57
|
+
execute(sql, params) {
|
|
58
|
+
return runTransform(sql, params);
|
|
59
|
+
},
|
|
60
|
+
executeRaw(sql, params) {
|
|
61
|
+
return runRaw(sql, params);
|
|
62
|
+
},
|
|
63
|
+
executeValues(sql, params) {
|
|
64
|
+
return Effect.map(run(sql, params), rows => rows.map(row => Array.from(row)));
|
|
65
|
+
},
|
|
66
|
+
executeWithoutTransform(sql, params) {
|
|
67
|
+
return run(sql, params);
|
|
68
|
+
},
|
|
69
|
+
executeUnprepared(sql, params) {
|
|
70
|
+
return run(sql, params);
|
|
71
|
+
},
|
|
72
|
+
executeStream(_sql, _params) {
|
|
73
|
+
return Effect.dieMessage("executeStream not implemented");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
const semaphore = yield* Effect.makeSemaphore(1);
|
|
78
|
+
const connection = yield* makeConnection;
|
|
79
|
+
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
80
|
+
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));
|
|
81
|
+
return Object.assign(Client.make({
|
|
82
|
+
acquirer,
|
|
83
|
+
compiler,
|
|
84
|
+
transactionAcquirer,
|
|
85
|
+
spanAttributes: [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), [Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]]
|
|
86
|
+
}), {
|
|
87
|
+
[TypeId]: TypeId,
|
|
88
|
+
config: options
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* @category layers
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
*/
|
|
95
|
+
export const layer = config => Layer.scopedContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(LibsqlClient, client).pipe(Context.add(Client.SqlClient, client)))));
|
|
96
|
+
//# sourceMappingURL=LibsqlClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LibsqlClient.js","names":["Client","SqlError","Statement","Libsql","Otel","Config","Context","Effect","identity","Layer","Scope","TypeId","Symbol","for","LibsqlClient","GenericTag","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","defaultTransforms","transformResultNames","array","makeConnection","db","createClient","addFinalizer","sync","close","run","sql","params","tryPromise","try","execute","args","then","results","rows","catch","cause","message","runRaw","runTransform","map","executeRaw","executeValues","row","Array","from","executeWithoutTransform","executeUnprepared","executeStream","_sql","_params","dieMessage","semaphore","makeSemaphore","connection","acquirer","withPermits","succeed","transactionAcquirer","uninterruptibleMask","restore","as","zipRight","take","tap","scope","release","Object","assign","spanAttributes","entries","SEMATTRS_DB_SYSTEM","DBSYSTEMVALUES_SQLITE","config","layer","scopedContext","unwrap","pipe","flatMap","client","add","SqlClient"],"sources":["../../src/LibsqlClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,uBAAuB;AAE/C,SAASC,QAAQ,QAAQ,sBAAsB;AAC/C,OAAO,KAAKC,SAAS,MAAM,uBAAuB;AAClD,OAAO,KAAKC,MAAM,MAAM,gBAAgB;AACxC,OAAO,KAAKC,IAAI,MAAM,qCAAqC;AAC3D,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;AAErC;;;;AAIA,OAAO,MAAMC,MAAM,gBAAkBC,MAAM,CAACC,GAAG,CAAC,iCAAiC,CAAC;AAiBlF;;;;AAIA,OAAO,MAAMC,YAAY,gBAAGR,OAAO,CAACS,UAAU,CAAe,iCAAiC,CAAC;AAqD/F;;;;AAIA,OAAO,MAAMC,IAAI,GACfC,OAA2B,IAE3BV,MAAM,CAACW,GAAG,CAAC,aAAS;EAClB,MAAMC,QAAQ,GAAGjB,SAAS,CAACkB,kBAAkB,CAACH,OAAO,CAACI,mBAAmB,CAAC;EAC1E,MAAMC,aAAa,GAAGpB,SAAS,CAACqB,iBAAiB,CAC/CN,OAAO,CAACO,oBAAqB,CAC9B,CAACC,KAAK;EAEP,MAAMC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,EAAEb,SAAS,CAACc,OAAO,CAAC,CAAC,CAAC,CAAC,CAC3D,CACF,EACDZ,UAAU,CACX,CACF;EAED,OAAOa,MAAM,CAACC,MAAM,CAClB3E,MAAM,CAACgB,IAAI,CAAC;IACV8C,QAAQ;IACR3C,QAAQ;IACR8C,mBAAmB;IACnBW,cAAc,EAAE,CACd,IAAI3D,OAAO,CAAC2D,cAAc,GAAGF,MAAM,CAACG,OAAO,CAAC5D,OAAO,CAAC2D,cAAc,CAAC,GAAG,EAAE,CAAC,EACzE,CAACxE,IAAI,CAAC0E,kBAAkB,EAAE1E,IAAI,CAAC2E,qBAAqB,CAAC;GAExD,CAAiB,EAClB;IACE,CAACpE,MAAM,GAAGA,MAAgB;IAC1BqE,MAAM,EAAE/D;GACT,CACF;AACH,CAAC,CAAC;AAEJ;;;;AAIA,OAAO,MAAMgE,KAAK,GAChBD,MAA8C,IAE9CvE,KAAK,CAACyE,aAAa,CACjB7E,MAAM,CAAC8E,MAAM,CAACH,MAAM,CAAC,CAACI,IAAI,CACxB7E,MAAM,CAAC8E,OAAO,CAACrE,IAAI,CAAC,EACpBT,MAAM,CAACwC,GAAG,CAAEuC,MAAM,IAChBhF,OAAO,CAACU,IAAI,CAACF,YAAY,EAAEwE,MAAM,CAAC,CAACF,IAAI,CACrC9E,OAAO,CAACiF,GAAG,CAACvF,MAAM,CAACwF,SAAS,EAAEF,MAAM,CAAC,CACtC,CACF,CACF,CACF","ignoreList":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
export * from "@effect/sql/Migrator/FileSystem";
|
|
14
|
+
/**
|
|
15
|
+
* @category constructor
|
|
16
|
+
* @since 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
export const run = /*#__PURE__*/Migrator.make({});
|
|
19
|
+
/**
|
|
20
|
+
* @category constructor
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
*/
|
|
23
|
+
export const layer = options => Layer.effectDiscard(run(options));
|
|
24
|
+
//# sourceMappingURL=LibsqlMigrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LibsqlMigrator.js","names":["Migrator","Layer","run","make","layer","options","effectDiscard"],"sources":["../../src/LibsqlMigrator.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,QAAQ,MAAM,sBAAsB;AAIhD,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC;;;AAGA,cAAc,sBAAsB;AAEpC;;;AAGA,cAAc,iCAAiC;AAE/C;;;;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 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["LibsqlClient","LibsqlMigrator"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,YAAY,MAAM,mBAAmB;AAEjD;;;AAGA,OAAO,KAAKC,cAAc,MAAM,qBAAqB","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@effect/sql-libsql",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A libSQL toolkit for Effect",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/Effect-TS/effect.git",
|
|
9
|
+
"directory": "packages/sql-libsql"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": [],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@libsql/client": "^0.12.0",
|
|
14
|
+
"@opentelemetry/semantic-conventions": "^1.25.1"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@effect/sql": "^0.13.3",
|
|
18
|
+
"effect": "^3.8.4",
|
|
19
|
+
"@effect/platform": "^0.66.2"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"provenance": true
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/cjs/index.js",
|
|
25
|
+
"module": "./dist/esm/index.js",
|
|
26
|
+
"types": "./dist/dts/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
"./package.json": "./package.json",
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/dts/index.d.ts",
|
|
31
|
+
"import": "./dist/esm/index.js",
|
|
32
|
+
"default": "./dist/cjs/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./LibsqlClient": {
|
|
35
|
+
"types": "./dist/dts/LibsqlClient.d.ts",
|
|
36
|
+
"import": "./dist/esm/LibsqlClient.js",
|
|
37
|
+
"default": "./dist/cjs/LibsqlClient.js"
|
|
38
|
+
},
|
|
39
|
+
"./LibsqlMigrator": {
|
|
40
|
+
"types": "./dist/dts/LibsqlMigrator.d.ts",
|
|
41
|
+
"import": "./dist/esm/LibsqlMigrator.js",
|
|
42
|
+
"default": "./dist/cjs/LibsqlMigrator.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"typesVersions": {
|
|
46
|
+
"*": {
|
|
47
|
+
"LibsqlClient": [
|
|
48
|
+
"./dist/dts/LibsqlClient.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"LibsqlMigrator": [
|
|
51
|
+
"./dist/dts/LibsqlMigrator.d.ts"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Client from "@effect/sql/SqlClient"
|
|
5
|
+
import type { Connection } from "@effect/sql/SqlConnection"
|
|
6
|
+
import { SqlError } from "@effect/sql/SqlError"
|
|
7
|
+
import * as Statement from "@effect/sql/Statement"
|
|
8
|
+
import * as Libsql from "@libsql/client"
|
|
9
|
+
import * as Otel from "@opentelemetry/semantic-conventions"
|
|
10
|
+
import * as Config from "effect/Config"
|
|
11
|
+
import type { ConfigError } from "effect/ConfigError"
|
|
12
|
+
import * as Context from "effect/Context"
|
|
13
|
+
import * as Effect from "effect/Effect"
|
|
14
|
+
import { identity } from "effect/Function"
|
|
15
|
+
import * as Layer from "effect/Layer"
|
|
16
|
+
import * as Scope from "effect/Scope"
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @category type ids
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
export const TypeId: unique symbol = Symbol.for("@effect/sql-libsql/LibsqlClient")
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @category type ids
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
export type TypeId = typeof TypeId
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @category models
|
|
32
|
+
* @since 1.0.0
|
|
33
|
+
*/
|
|
34
|
+
export interface LibsqlClient extends Client.SqlClient {
|
|
35
|
+
readonly [TypeId]: TypeId
|
|
36
|
+
readonly config: LibsqlClientConfig
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @category tags
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
*/
|
|
43
|
+
export const LibsqlClient = Context.GenericTag<LibsqlClient>("@effect/sql-libsql/LibsqlClient")
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @category models
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
49
|
+
export interface LibsqlClientConfig {
|
|
50
|
+
/** The database URL.
|
|
51
|
+
*
|
|
52
|
+
* The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation,
|
|
53
|
+
* please refer to the project README:
|
|
54
|
+
*
|
|
55
|
+
* https://github.com/libsql/libsql-client-ts#supported-urls
|
|
56
|
+
*/
|
|
57
|
+
readonly url: string
|
|
58
|
+
/** Authentication token for the database. */
|
|
59
|
+
readonly authToken?: string | undefined
|
|
60
|
+
/** Encryption key for the database. */
|
|
61
|
+
readonly encryptionKey?: string | undefined
|
|
62
|
+
/** URL of a remote server to synchronize database with. */
|
|
63
|
+
readonly syncUrl?: string | undefined
|
|
64
|
+
/** Sync interval in seconds. */
|
|
65
|
+
readonly syncInterval?: number | undefined
|
|
66
|
+
/** Enables or disables TLS for `libsql:` URLs.
|
|
67
|
+
*
|
|
68
|
+
* By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.
|
|
69
|
+
*/
|
|
70
|
+
readonly tls?: boolean | undefined
|
|
71
|
+
/** How to convert SQLite integers to JavaScript values:
|
|
72
|
+
*
|
|
73
|
+
* - `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats).
|
|
74
|
+
* `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read
|
|
75
|
+
* larger integers will throw a `RangeError`.
|
|
76
|
+
* - `"bigint"`: returns SQLite integers as JavaScript `bigint`-s (arbitrary precision integers). Bigints can
|
|
77
|
+
* precisely represent all SQLite integers.
|
|
78
|
+
* - `"string"`: returns SQLite integers as strings.
|
|
79
|
+
*/
|
|
80
|
+
readonly intMode?: "number" | "bigint" | "string" | undefined
|
|
81
|
+
/** Concurrency limit.
|
|
82
|
+
*
|
|
83
|
+
* By default, the client performs up to 20 concurrent requests. You can set this option to a higher
|
|
84
|
+
* number to increase the concurrency limit or set it to 0 to disable concurrency limits completely.
|
|
85
|
+
*/
|
|
86
|
+
readonly concurrency?: number | undefined
|
|
87
|
+
|
|
88
|
+
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
89
|
+
|
|
90
|
+
readonly transformResultNames?: ((str: string) => string) | undefined
|
|
91
|
+
readonly transformQueryNames?: ((str: string) => string) | undefined
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface LibsqlConnection extends Connection {}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @category constructor
|
|
98
|
+
* @since 1.0.0
|
|
99
|
+
*/
|
|
100
|
+
export const make = (
|
|
101
|
+
options: LibsqlClientConfig
|
|
102
|
+
): Effect.Effect<LibsqlClient, never, Scope.Scope> =>
|
|
103
|
+
Effect.gen(function*() {
|
|
104
|
+
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames)
|
|
105
|
+
const transformRows = Statement.defaultTransforms(
|
|
106
|
+
options.transformResultNames!
|
|
107
|
+
).array
|
|
108
|
+
|
|
109
|
+
const makeConnection = Effect.gen(function*() {
|
|
110
|
+
const db = Libsql.createClient(options as Libsql.Config)
|
|
111
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => db.close()))
|
|
112
|
+
|
|
113
|
+
const run = (
|
|
114
|
+
sql: string,
|
|
115
|
+
params: ReadonlyArray<Statement.Primitive> = []
|
|
116
|
+
) =>
|
|
117
|
+
Effect.tryPromise({
|
|
118
|
+
try: () => db.execute({ sql, args: params as Array<any> }).then((results) => results.rows),
|
|
119
|
+
catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" })
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const runRaw = (
|
|
123
|
+
sql: string,
|
|
124
|
+
params: ReadonlyArray<Statement.Primitive> = []
|
|
125
|
+
) =>
|
|
126
|
+
Effect.tryPromise({
|
|
127
|
+
try: () => db.execute({ sql, args: params as Array<any> }),
|
|
128
|
+
catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" })
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const runTransform = options.transformResultNames
|
|
132
|
+
? (sql: string, params?: ReadonlyArray<Statement.Primitive>) => Effect.map(run(sql, params), transformRows)
|
|
133
|
+
: run
|
|
134
|
+
|
|
135
|
+
return identity<LibsqlConnection>({
|
|
136
|
+
execute(sql, params) {
|
|
137
|
+
return runTransform(sql, params)
|
|
138
|
+
},
|
|
139
|
+
executeRaw(sql, params) {
|
|
140
|
+
return runRaw(sql, params)
|
|
141
|
+
},
|
|
142
|
+
executeValues(sql, params) {
|
|
143
|
+
return Effect.map(run(sql, params), (rows) => rows.map((row) => Array.from(row) as Array<any>))
|
|
144
|
+
},
|
|
145
|
+
executeWithoutTransform(sql, params) {
|
|
146
|
+
return run(sql, params)
|
|
147
|
+
},
|
|
148
|
+
executeUnprepared(sql, params) {
|
|
149
|
+
return run(sql, params)
|
|
150
|
+
},
|
|
151
|
+
executeStream(_sql, _params) {
|
|
152
|
+
return Effect.dieMessage("executeStream not implemented")
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const semaphore = yield* Effect.makeSemaphore(1)
|
|
158
|
+
const connection = yield* makeConnection
|
|
159
|
+
|
|
160
|
+
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
|
|
161
|
+
const transactionAcquirer = Effect.uninterruptibleMask((restore) =>
|
|
162
|
+
Effect.as(
|
|
163
|
+
Effect.zipRight(
|
|
164
|
+
restore(semaphore.take(1)),
|
|
165
|
+
Effect.tap(
|
|
166
|
+
Effect.scope,
|
|
167
|
+
(scope) => Scope.addFinalizer(scope, semaphore.release(1))
|
|
168
|
+
)
|
|
169
|
+
),
|
|
170
|
+
connection
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
return Object.assign(
|
|
175
|
+
Client.make({
|
|
176
|
+
acquirer,
|
|
177
|
+
compiler,
|
|
178
|
+
transactionAcquirer,
|
|
179
|
+
spanAttributes: [
|
|
180
|
+
...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
|
|
181
|
+
[Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]
|
|
182
|
+
]
|
|
183
|
+
}) as LibsqlClient,
|
|
184
|
+
{
|
|
185
|
+
[TypeId]: TypeId as TypeId,
|
|
186
|
+
config: options
|
|
187
|
+
}
|
|
188
|
+
)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @category layers
|
|
193
|
+
* @since 1.0.0
|
|
194
|
+
*/
|
|
195
|
+
export const layer = (
|
|
196
|
+
config: Config.Config.Wrap<LibsqlClientConfig>
|
|
197
|
+
): Layer.Layer<LibsqlClient | Client.SqlClient, ConfigError> =>
|
|
198
|
+
Layer.scopedContext(
|
|
199
|
+
Config.unwrap(config).pipe(
|
|
200
|
+
Effect.flatMap(make),
|
|
201
|
+
Effect.map((client) =>
|
|
202
|
+
Context.make(LibsqlClient, client).pipe(
|
|
203
|
+
Context.add(Client.SqlClient, client)
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
)
|
|
207
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
* @since 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
export * from "@effect/sql/Migrator/FileSystem"
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @category constructor
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
export const run: <R2 = never>(
|
|
25
|
+
options: Migrator.MigratorOptions<R2>
|
|
26
|
+
) => Effect.Effect<
|
|
27
|
+
ReadonlyArray<readonly [id: number, name: string]>,
|
|
28
|
+
Migrator.MigrationError | SqlError,
|
|
29
|
+
Client.SqlClient | R2
|
|
30
|
+
> = Migrator.make({})
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @category constructor
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
export const layer = <R>(
|
|
37
|
+
options: Migrator.MigratorOptions<R>
|
|
38
|
+
): Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R> => Layer.effectDiscard(run(options))
|