@effect/sql-libsql 0.3.1 → 0.4.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/dist/cjs/LibsqlClient.js +106 -52
- package/dist/cjs/LibsqlClient.js.map +1 -1
- package/dist/dts/LibsqlClient.d.ts +63 -38
- package/dist/dts/LibsqlClient.d.ts.map +1 -1
- package/dist/esm/LibsqlClient.js +106 -52
- package/dist/esm/LibsqlClient.js.map +1 -1
- package/package.json +3 -3
- package/src/LibsqlClient.ts +187 -100
package/dist/cjs/LibsqlClient.js
CHANGED
|
@@ -12,8 +12,8 @@ var Otel = _interopRequireWildcard(require("@opentelemetry/semantic-conventions"
|
|
|
12
12
|
var Config = _interopRequireWildcard(require("effect/Config"));
|
|
13
13
|
var Context = _interopRequireWildcard(require("effect/Context"));
|
|
14
14
|
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
15
|
-
var _Function = require("effect/Function");
|
|
16
15
|
var Layer = _interopRequireWildcard(require("effect/Layer"));
|
|
16
|
+
var Option = _interopRequireWildcard(require("effect/Option"));
|
|
17
17
|
var Scope = _interopRequireWildcard(require("effect/Scope"));
|
|
18
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
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; }
|
|
@@ -31,6 +31,7 @@ const TypeId = exports.TypeId = /*#__PURE__*/Symbol.for("@effect/sql-libsql/Libs
|
|
|
31
31
|
* @since 1.0.0
|
|
32
32
|
*/
|
|
33
33
|
const LibsqlClient = exports.LibsqlClient = /*#__PURE__*/Context.GenericTag("@effect/sql-libsql/LibsqlClient");
|
|
34
|
+
const LibsqlTransaction = /*#__PURE__*/Context.GenericTag("@effect/sql-libsql/LibsqlClient/LibsqlTransaction");
|
|
34
35
|
/**
|
|
35
36
|
* @category constructor
|
|
36
37
|
* @since 1.0.0
|
|
@@ -38,63 +39,116 @@ const LibsqlClient = exports.LibsqlClient = /*#__PURE__*/Context.GenericTag("@ef
|
|
|
38
39
|
const make = options => Effect.gen(function* () {
|
|
39
40
|
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
40
41
|
const transformRows = Statement.defaultTransforms(options.transformResultNames).array;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
42
|
+
const spanAttributes = [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), [Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]];
|
|
43
|
+
class LibsqlConnectionImpl {
|
|
44
|
+
sdk;
|
|
45
|
+
constructor(sdk) {
|
|
46
|
+
this.sdk = sdk;
|
|
47
|
+
}
|
|
48
|
+
run(sql, params = []) {
|
|
49
|
+
return Effect.map(Effect.tryPromise({
|
|
50
|
+
try: () => this.sdk.execute({
|
|
51
|
+
sql,
|
|
52
|
+
args: params
|
|
53
|
+
}),
|
|
54
|
+
catch: cause => new _SqlError.SqlError({
|
|
55
|
+
cause,
|
|
56
|
+
message: "Failed to execute statement"
|
|
57
|
+
})
|
|
58
|
+
}), results => results.rows);
|
|
59
|
+
}
|
|
60
|
+
runRaw(sql, params = []) {
|
|
61
|
+
return Effect.tryPromise({
|
|
62
|
+
try: () => this.sdk.execute({
|
|
63
|
+
sql,
|
|
64
|
+
args: params
|
|
65
|
+
}),
|
|
66
|
+
catch: cause => new _SqlError.SqlError({
|
|
67
|
+
cause,
|
|
68
|
+
message: "Failed to execute statement"
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
runTransform(sql, params = []) {
|
|
73
|
+
return options.transformResultNames ? Effect.map(this.run(sql, params), transformRows) : this.run(sql, params);
|
|
74
|
+
}
|
|
75
|
+
execute(sql, params) {
|
|
76
|
+
return this.runTransform(sql, params);
|
|
77
|
+
}
|
|
78
|
+
executeRaw(sql, params) {
|
|
79
|
+
return this.runRaw(sql, params);
|
|
80
|
+
}
|
|
81
|
+
executeValues(sql, params) {
|
|
82
|
+
return Effect.map(this.run(sql, params), rows => rows.map(row => Array.from(row)));
|
|
83
|
+
}
|
|
84
|
+
executeWithoutTransform(sql, params) {
|
|
85
|
+
return this.run(sql, params);
|
|
86
|
+
}
|
|
87
|
+
executeUnprepared(sql, params) {
|
|
88
|
+
return this.run(sql, params);
|
|
89
|
+
}
|
|
90
|
+
executeStream() {
|
|
91
|
+
return Effect.dieMessage("executeStream not implemented");
|
|
92
|
+
}
|
|
93
|
+
get beginTransaction() {
|
|
94
|
+
return Effect.map(Effect.tryPromise({
|
|
95
|
+
try: () => this.sdk.transaction("write"),
|
|
96
|
+
catch: cause => new _SqlError.SqlError({
|
|
97
|
+
cause,
|
|
98
|
+
message: "Failed to begin transaction"
|
|
99
|
+
})
|
|
100
|
+
}), tx => new LibsqlConnectionImpl(tx));
|
|
101
|
+
}
|
|
102
|
+
get commit() {
|
|
103
|
+
return Effect.tryPromise({
|
|
104
|
+
try: () => this.sdk.commit(),
|
|
105
|
+
catch: cause => new _SqlError.SqlError({
|
|
106
|
+
cause,
|
|
107
|
+
message: "Failed to commit transaction"
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
get rollback() {
|
|
112
|
+
return Effect.tryPromise({
|
|
113
|
+
try: () => this.sdk.rollback(),
|
|
114
|
+
catch: cause => new _SqlError.SqlError({
|
|
115
|
+
cause,
|
|
116
|
+
message: "Failed to rollback transaction"
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const connection = "liveClient" in options ? new LibsqlConnectionImpl(options.liveClient) : yield* Effect.map(Effect.acquireRelease(Effect.sync(() => Libsql.createClient(options)), sdk => Effect.sync(() => sdk.close())), sdk => new LibsqlConnectionImpl(sdk));
|
|
86
122
|
const semaphore = yield* Effect.makeSemaphore(1);
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
123
|
+
const withTransaction = Client.makeWithTransaction({
|
|
124
|
+
transactionTag: LibsqlTransaction,
|
|
125
|
+
spanAttributes,
|
|
126
|
+
acquireConnection: Effect.uninterruptibleMask(restore => Scope.make().pipe(Effect.bindTo("scope"), Effect.bind("conn", ({
|
|
127
|
+
scope
|
|
128
|
+
}) => restore(semaphore.take(1)).pipe(Effect.zipRight(Scope.addFinalizer(scope, semaphore.release(1))), Effect.zipRight(connection.beginTransaction))), Effect.map(({
|
|
129
|
+
conn,
|
|
130
|
+
scope
|
|
131
|
+
}) => [scope, conn]))),
|
|
132
|
+
begin: () => Effect.void,
|
|
133
|
+
// already begun in acquireConnection
|
|
134
|
+
savepoint: (conn, id) => conn.executeRaw(`SAVEPOINT effect_sql_${id};`, []),
|
|
135
|
+
commit: conn => conn.commit,
|
|
136
|
+
rollback: conn => conn.rollback,
|
|
137
|
+
rollbackSavepoint: (conn, id) => conn.executeRaw(`ROLLBACK TO SAVEPOINT effect_sql_${id};`, [])
|
|
138
|
+
});
|
|
139
|
+
const acquirer = Effect.flatMap(Effect.serviceOption(LibsqlTransaction), Option.match({
|
|
140
|
+
onNone: () => semaphore.withPermits(1)(Effect.succeed(connection)),
|
|
141
|
+
onSome: ([conn]) => Effect.succeed(conn)
|
|
142
|
+
}));
|
|
90
143
|
return Object.assign(Client.make({
|
|
91
144
|
acquirer,
|
|
92
145
|
compiler,
|
|
93
|
-
|
|
94
|
-
spanAttributes: [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), [Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]]
|
|
146
|
+
spanAttributes
|
|
95
147
|
}), {
|
|
96
148
|
[TypeId]: TypeId,
|
|
97
|
-
config: options
|
|
149
|
+
config: options,
|
|
150
|
+
withTransaction,
|
|
151
|
+
sdk: connection.sdk
|
|
98
152
|
});
|
|
99
153
|
});
|
|
100
154
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LibsqlClient.js","names":["Client","_interopRequireWildcard","require","_SqlError","Statement","Libsql","Otel","Config","Context","Effect","
|
|
1
|
+
{"version":3,"file":"LibsqlClient.js","names":["Client","_interopRequireWildcard","require","_SqlError","Statement","Libsql","Otel","Config","Context","Effect","Layer","Option","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","LibsqlTransaction","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","defaultTransforms","transformResultNames","array","spanAttributes","entries","SEMATTRS_DB_SYSTEM","DBSYSTEMVALUES_SQLITE","LibsqlConnectionImpl","sdk","constructor","run","sql","params","map","tryPromise","try","execute","args","catch","cause","SqlError","message","results","rows","runRaw","runTransform","executeRaw","executeValues","row","Array","from","executeWithoutTransform","executeUnprepared","executeStream","dieMessage","beginTransaction","transaction","tx","commit","rollback","connection","liveClient","acquireRelease","sync","createClient","close","semaphore","makeSemaphore","withTransaction","makeWithTransaction","transactionTag","acquireConnection","uninterruptibleMask","restore","pipe","bindTo","bind","scope","take","zipRight","addFinalizer","release","conn","begin","void","savepoint","id","rollbackSavepoint","acquirer","flatMap","serviceOption","match","onNone","withPermits","succeed","onSome","assign","config","layer","scopedContext","unwrap","client","add","SqlClient"],"sources":["../../src/LibsqlClient.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAH,uBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAJ,uBAAA,CAAAC,OAAA;AACA,IAAAI,IAAA,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,KAAA,GAAAT,uBAAA,CAAAC,OAAA;AACA,IAAAS,MAAA,GAAAV,uBAAA,CAAAC,OAAA;AACA,IAAAU,KAAA,GAAAX,uBAAA,CAAAC,OAAA;AAAqC,SAAAW,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,SAAAb,wBAAAa,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ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,CAAClC,UAA8B,CAAC,CAAC;IACtFmC,MAAM,EAAEA,CAAC,CAACb,IAAI,CAAC,KAAKpG,MAAM,CAACgH,OAAO,CAACZ,IAAI;GACxC,CAAC,CACH;EAED,OAAOpF,MAAM,CAACkG,MAAM,CAClB3H,MAAM,CAACwC,IAAI,CAAC;IACV2E,QAAQ;IACRxE,QAAQ;IACRO;GACD,CAAC,EACF;IACE,CAACjB,MAAM,GAAGA,MAAgB;IAC1B2F,MAAM,EAAEnF,OAAO;IACfsD,eAAe;IACfxC,GAAG,EAAEgC,UAAU,CAAChC;GACjB,CACF;AACH,CAAC,CAAC;AAEJ;;;;AAAArB,OAAA,CAAAM,IAAA,GAAAA,IAAA;AAIO,MAAMqF,KAAK,GAChBD,MAA8C,IAE9ClH,KAAK,CAACoH,aAAa,CACjBvH,MAAM,CAACwH,MAAM,CAACH,MAAM,CAAC,CAACvB,IAAI,CACxB5F,MAAM,CAAC2G,OAAO,CAAC5E,IAAI,CAAC,EACpB/B,MAAM,CAACmD,GAAG,CAAEoE,MAAM,IAChBxH,OAAO,CAACgC,IAAI,CAACH,YAAY,EAAE2F,MAAM,CAAC,CAAC3B,IAAI,CACrC7F,OAAO,CAACyH,GAAG,CAACjI,MAAM,CAACkI,SAAS,EAAEF,MAAM,CAAC,CACtC,CACF,CACF,CACF;AAAA9F,OAAA,CAAA2F,KAAA,GAAAA,KAAA","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
4
|
import * as Client from "@effect/sql/SqlClient";
|
|
5
|
+
import * as Libsql from "@libsql/client";
|
|
5
6
|
import * as Config from "effect/Config";
|
|
6
7
|
import type { ConfigError } from "effect/ConfigError";
|
|
7
8
|
import * as Context from "effect/Context";
|
|
@@ -35,47 +36,71 @@ export declare const LibsqlClient: Context.Tag<LibsqlClient, LibsqlClient>;
|
|
|
35
36
|
* @category models
|
|
36
37
|
* @since 1.0.0
|
|
37
38
|
*/
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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.
|
|
39
|
+
export type LibsqlClientConfig = LibsqlClientConfig.Full | LibsqlClientConfig.Live;
|
|
40
|
+
/**
|
|
41
|
+
* @category models
|
|
42
|
+
* @since 1.0.0
|
|
43
|
+
*/
|
|
44
|
+
export declare namespace LibsqlClientConfig {
|
|
45
|
+
/**
|
|
46
|
+
* @category models
|
|
47
|
+
* @since 1.0.0
|
|
58
48
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* - `"string"`: returns SQLite integers as strings.
|
|
49
|
+
interface Base {
|
|
50
|
+
readonly spanAttributes?: Record<string, unknown> | undefined;
|
|
51
|
+
readonly transformResultNames?: ((str: string) => string) | undefined;
|
|
52
|
+
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @category models
|
|
56
|
+
* @since 1.0.0
|
|
68
57
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
interface Full extends Base {
|
|
59
|
+
/** The database URL.
|
|
60
|
+
*
|
|
61
|
+
* The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation,
|
|
62
|
+
* please refer to the project README:
|
|
63
|
+
*
|
|
64
|
+
* https://github.com/libsql/libsql-client-ts#supported-urls
|
|
65
|
+
*/
|
|
66
|
+
readonly url: string;
|
|
67
|
+
/** Authentication token for the database. */
|
|
68
|
+
readonly authToken?: string | undefined;
|
|
69
|
+
/** Encryption key for the database. */
|
|
70
|
+
readonly encryptionKey?: string | undefined;
|
|
71
|
+
/** URL of a remote server to synchronize database with. */
|
|
72
|
+
readonly syncUrl?: string | undefined;
|
|
73
|
+
/** Sync interval in seconds. */
|
|
74
|
+
readonly syncInterval?: number | undefined;
|
|
75
|
+
/** Enables or disables TLS for `libsql:` URLs.
|
|
76
|
+
*
|
|
77
|
+
* By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.
|
|
78
|
+
*/
|
|
79
|
+
readonly tls?: boolean | undefined;
|
|
80
|
+
/** How to convert SQLite integers to JavaScript values:
|
|
81
|
+
*
|
|
82
|
+
* - `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats).
|
|
83
|
+
* `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read
|
|
84
|
+
* larger integers will throw a `RangeError`.
|
|
85
|
+
* - `"bigint"`: returns SQLite integers as JavaScript `bigint`-s (arbitrary precision integers). Bigints can
|
|
86
|
+
* precisely represent all SQLite integers.
|
|
87
|
+
* - `"string"`: returns SQLite integers as strings.
|
|
88
|
+
*/
|
|
89
|
+
readonly intMode?: "number" | "bigint" | "string" | undefined;
|
|
90
|
+
/** Concurrency limit.
|
|
91
|
+
*
|
|
92
|
+
* By default, the client performs up to 20 concurrent requests. You can set this option to a higher
|
|
93
|
+
* number to increase the concurrency limit or set it to 0 to disable concurrency limits completely.
|
|
94
|
+
*/
|
|
95
|
+
readonly concurrency?: number | undefined;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @category models
|
|
99
|
+
* @since 1.0.0
|
|
74
100
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
101
|
+
interface Live extends Base {
|
|
102
|
+
readonly liveClient: Libsql.Client;
|
|
103
|
+
}
|
|
79
104
|
}
|
|
80
105
|
/**
|
|
81
106
|
* @category constructor
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LibsqlClient.d.ts","sourceRoot":"","sources":["../../src/LibsqlClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"LibsqlClient.d.ts","sourceRoot":"","sources":["../../src/LibsqlClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAI/C,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAA;AAExC,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;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,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;AAM/F;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,kBAAkB,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CACF;AAQD;;;GAGG;AACH,eAAO,MAAM,IAAI,YACN,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CA6I7C,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"}
|
package/dist/esm/LibsqlClient.js
CHANGED
|
@@ -9,8 +9,8 @@ import * as Otel from "@opentelemetry/semantic-conventions";
|
|
|
9
9
|
import * as Config from "effect/Config";
|
|
10
10
|
import * as Context from "effect/Context";
|
|
11
11
|
import * as Effect from "effect/Effect";
|
|
12
|
-
import { identity } from "effect/Function";
|
|
13
12
|
import * as Layer from "effect/Layer";
|
|
13
|
+
import * as Option from "effect/Option";
|
|
14
14
|
import * as Scope from "effect/Scope";
|
|
15
15
|
/**
|
|
16
16
|
* @category type ids
|
|
@@ -22,6 +22,7 @@ export const TypeId = /*#__PURE__*/Symbol.for("@effect/sql-libsql/LibsqlClient")
|
|
|
22
22
|
* @since 1.0.0
|
|
23
23
|
*/
|
|
24
24
|
export const LibsqlClient = /*#__PURE__*/Context.GenericTag("@effect/sql-libsql/LibsqlClient");
|
|
25
|
+
const LibsqlTransaction = /*#__PURE__*/Context.GenericTag("@effect/sql-libsql/LibsqlClient/LibsqlTransaction");
|
|
25
26
|
/**
|
|
26
27
|
* @category constructor
|
|
27
28
|
* @since 1.0.0
|
|
@@ -29,63 +30,116 @@ export const LibsqlClient = /*#__PURE__*/Context.GenericTag("@effect/sql-libsql/
|
|
|
29
30
|
export const make = options => Effect.gen(function* () {
|
|
30
31
|
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
31
32
|
const transformRows = Statement.defaultTransforms(options.transformResultNames).array;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
33
|
+
const spanAttributes = [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), [Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]];
|
|
34
|
+
class LibsqlConnectionImpl {
|
|
35
|
+
sdk;
|
|
36
|
+
constructor(sdk) {
|
|
37
|
+
this.sdk = sdk;
|
|
38
|
+
}
|
|
39
|
+
run(sql, params = []) {
|
|
40
|
+
return Effect.map(Effect.tryPromise({
|
|
41
|
+
try: () => this.sdk.execute({
|
|
42
|
+
sql,
|
|
43
|
+
args: params
|
|
44
|
+
}),
|
|
45
|
+
catch: cause => new SqlError({
|
|
46
|
+
cause,
|
|
47
|
+
message: "Failed to execute statement"
|
|
48
|
+
})
|
|
49
|
+
}), results => results.rows);
|
|
50
|
+
}
|
|
51
|
+
runRaw(sql, params = []) {
|
|
52
|
+
return Effect.tryPromise({
|
|
53
|
+
try: () => this.sdk.execute({
|
|
54
|
+
sql,
|
|
55
|
+
args: params
|
|
56
|
+
}),
|
|
57
|
+
catch: cause => new SqlError({
|
|
58
|
+
cause,
|
|
59
|
+
message: "Failed to execute statement"
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
runTransform(sql, params = []) {
|
|
64
|
+
return options.transformResultNames ? Effect.map(this.run(sql, params), transformRows) : this.run(sql, params);
|
|
65
|
+
}
|
|
66
|
+
execute(sql, params) {
|
|
67
|
+
return this.runTransform(sql, params);
|
|
68
|
+
}
|
|
69
|
+
executeRaw(sql, params) {
|
|
70
|
+
return this.runRaw(sql, params);
|
|
71
|
+
}
|
|
72
|
+
executeValues(sql, params) {
|
|
73
|
+
return Effect.map(this.run(sql, params), rows => rows.map(row => Array.from(row)));
|
|
74
|
+
}
|
|
75
|
+
executeWithoutTransform(sql, params) {
|
|
76
|
+
return this.run(sql, params);
|
|
77
|
+
}
|
|
78
|
+
executeUnprepared(sql, params) {
|
|
79
|
+
return this.run(sql, params);
|
|
80
|
+
}
|
|
81
|
+
executeStream() {
|
|
82
|
+
return Effect.dieMessage("executeStream not implemented");
|
|
83
|
+
}
|
|
84
|
+
get beginTransaction() {
|
|
85
|
+
return Effect.map(Effect.tryPromise({
|
|
86
|
+
try: () => this.sdk.transaction("write"),
|
|
87
|
+
catch: cause => new SqlError({
|
|
88
|
+
cause,
|
|
89
|
+
message: "Failed to begin transaction"
|
|
90
|
+
})
|
|
91
|
+
}), tx => new LibsqlConnectionImpl(tx));
|
|
92
|
+
}
|
|
93
|
+
get commit() {
|
|
94
|
+
return Effect.tryPromise({
|
|
95
|
+
try: () => this.sdk.commit(),
|
|
96
|
+
catch: cause => new SqlError({
|
|
97
|
+
cause,
|
|
98
|
+
message: "Failed to commit transaction"
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
get rollback() {
|
|
103
|
+
return Effect.tryPromise({
|
|
104
|
+
try: () => this.sdk.rollback(),
|
|
105
|
+
catch: cause => new SqlError({
|
|
106
|
+
cause,
|
|
107
|
+
message: "Failed to rollback transaction"
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const connection = "liveClient" in options ? new LibsqlConnectionImpl(options.liveClient) : yield* Effect.map(Effect.acquireRelease(Effect.sync(() => Libsql.createClient(options)), sdk => Effect.sync(() => sdk.close())), sdk => new LibsqlConnectionImpl(sdk));
|
|
77
113
|
const semaphore = yield* Effect.makeSemaphore(1);
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
114
|
+
const withTransaction = Client.makeWithTransaction({
|
|
115
|
+
transactionTag: LibsqlTransaction,
|
|
116
|
+
spanAttributes,
|
|
117
|
+
acquireConnection: Effect.uninterruptibleMask(restore => Scope.make().pipe(Effect.bindTo("scope"), Effect.bind("conn", ({
|
|
118
|
+
scope
|
|
119
|
+
}) => restore(semaphore.take(1)).pipe(Effect.zipRight(Scope.addFinalizer(scope, semaphore.release(1))), Effect.zipRight(connection.beginTransaction))), Effect.map(({
|
|
120
|
+
conn,
|
|
121
|
+
scope
|
|
122
|
+
}) => [scope, conn]))),
|
|
123
|
+
begin: () => Effect.void,
|
|
124
|
+
// already begun in acquireConnection
|
|
125
|
+
savepoint: (conn, id) => conn.executeRaw(`SAVEPOINT effect_sql_${id};`, []),
|
|
126
|
+
commit: conn => conn.commit,
|
|
127
|
+
rollback: conn => conn.rollback,
|
|
128
|
+
rollbackSavepoint: (conn, id) => conn.executeRaw(`ROLLBACK TO SAVEPOINT effect_sql_${id};`, [])
|
|
129
|
+
});
|
|
130
|
+
const acquirer = Effect.flatMap(Effect.serviceOption(LibsqlTransaction), Option.match({
|
|
131
|
+
onNone: () => semaphore.withPermits(1)(Effect.succeed(connection)),
|
|
132
|
+
onSome: ([conn]) => Effect.succeed(conn)
|
|
133
|
+
}));
|
|
81
134
|
return Object.assign(Client.make({
|
|
82
135
|
acquirer,
|
|
83
136
|
compiler,
|
|
84
|
-
|
|
85
|
-
spanAttributes: [...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), [Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]]
|
|
137
|
+
spanAttributes
|
|
86
138
|
}), {
|
|
87
139
|
[TypeId]: TypeId,
|
|
88
|
-
config: options
|
|
140
|
+
config: options,
|
|
141
|
+
withTransaction,
|
|
142
|
+
sdk: connection.sdk
|
|
89
143
|
});
|
|
90
144
|
});
|
|
91
145
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LibsqlClient.js","names":["Client","SqlError","Statement","Libsql","Otel","Config","Context","Effect","
|
|
1
|
+
{"version":3,"file":"LibsqlClient.js","names":["Client","SqlError","Statement","Libsql","Otel","Config","Context","Effect","Layer","Option","Scope","TypeId","Symbol","for","LibsqlClient","GenericTag","LibsqlTransaction","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","defaultTransforms","transformResultNames","array","spanAttributes","Object","entries","SEMATTRS_DB_SYSTEM","DBSYSTEMVALUES_SQLITE","LibsqlConnectionImpl","sdk","constructor","run","sql","params","map","tryPromise","try","execute","args","catch","cause","message","results","rows","runRaw","runTransform","executeRaw","executeValues","row","Array","from","executeWithoutTransform","executeUnprepared","executeStream","dieMessage","beginTransaction","transaction","tx","commit","rollback","connection","liveClient","acquireRelease","sync","createClient","close","semaphore","makeSemaphore","withTransaction","makeWithTransaction","transactionTag","acquireConnection","uninterruptibleMask","restore","pipe","bindTo","bind","scope","take","zipRight","addFinalizer","release","conn","begin","void","savepoint","id","rollbackSavepoint","acquirer","flatMap","serviceOption","match","onNone","withPermits","succeed","onSome","assign","config","layer","scopedContext","unwrap","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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AC,CAAC3B,IAAI,CACrCxE,OAAO,CAACoG,GAAG,CAAC1G,MAAM,CAAC2G,SAAS,EAAEF,MAAM,CAAC,CACtC,CACF,CACF,CACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-libsql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "A libSQL toolkit for Effect",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"@opentelemetry/semantic-conventions": "^1.25.1"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@effect/platform": "^0.
|
|
18
|
-
"@effect/sql": "^0.
|
|
17
|
+
"@effect/platform": "^0.68.1",
|
|
18
|
+
"@effect/sql": "^0.16.1",
|
|
19
19
|
"effect": "^3.9.1"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
package/src/LibsqlClient.ts
CHANGED
|
@@ -11,8 +11,8 @@ import * as Config from "effect/Config"
|
|
|
11
11
|
import type { ConfigError } from "effect/ConfigError"
|
|
12
12
|
import * as Context from "effect/Context"
|
|
13
13
|
import * as Effect from "effect/Effect"
|
|
14
|
-
import { identity } from "effect/Function"
|
|
15
14
|
import * as Layer from "effect/Layer"
|
|
15
|
+
import * as Option from "effect/Option"
|
|
16
16
|
import * as Scope from "effect/Scope"
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -42,56 +42,89 @@ export interface LibsqlClient extends Client.SqlClient {
|
|
|
42
42
|
*/
|
|
43
43
|
export const LibsqlClient = Context.GenericTag<LibsqlClient>("@effect/sql-libsql/LibsqlClient")
|
|
44
44
|
|
|
45
|
+
const LibsqlTransaction = Context.GenericTag<readonly [LibsqlConnection, counter: number]>(
|
|
46
|
+
"@effect/sql-libsql/LibsqlClient/LibsqlTransaction"
|
|
47
|
+
)
|
|
48
|
+
|
|
45
49
|
/**
|
|
46
50
|
* @category models
|
|
47
51
|
* @since 1.0.0
|
|
48
52
|
*/
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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.
|
|
53
|
+
export type LibsqlClientConfig = LibsqlClientConfig.Full | LibsqlClientConfig.Live
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @category models
|
|
57
|
+
* @since 1.0.0
|
|
58
|
+
*/
|
|
59
|
+
export declare namespace LibsqlClientConfig {
|
|
60
|
+
/**
|
|
61
|
+
* @category models
|
|
62
|
+
* @since 1.0.0
|
|
85
63
|
*/
|
|
86
|
-
|
|
64
|
+
export interface Base {
|
|
65
|
+
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
66
|
+
readonly transformResultNames?: ((str: string) => string) | undefined
|
|
67
|
+
readonly transformQueryNames?: ((str: string) => string) | undefined
|
|
68
|
+
}
|
|
87
69
|
|
|
88
|
-
|
|
70
|
+
/**
|
|
71
|
+
* @category models
|
|
72
|
+
* @since 1.0.0
|
|
73
|
+
*/
|
|
74
|
+
export interface Full extends Base {
|
|
75
|
+
/** The database URL.
|
|
76
|
+
*
|
|
77
|
+
* The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation,
|
|
78
|
+
* please refer to the project README:
|
|
79
|
+
*
|
|
80
|
+
* https://github.com/libsql/libsql-client-ts#supported-urls
|
|
81
|
+
*/
|
|
82
|
+
readonly url: string
|
|
83
|
+
/** Authentication token for the database. */
|
|
84
|
+
readonly authToken?: string | undefined
|
|
85
|
+
/** Encryption key for the database. */
|
|
86
|
+
readonly encryptionKey?: string | undefined
|
|
87
|
+
/** URL of a remote server to synchronize database with. */
|
|
88
|
+
readonly syncUrl?: string | undefined
|
|
89
|
+
/** Sync interval in seconds. */
|
|
90
|
+
readonly syncInterval?: number | undefined
|
|
91
|
+
/** Enables or disables TLS for `libsql:` URLs.
|
|
92
|
+
*
|
|
93
|
+
* By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.
|
|
94
|
+
*/
|
|
95
|
+
readonly tls?: boolean | undefined
|
|
96
|
+
/** How to convert SQLite integers to JavaScript values:
|
|
97
|
+
*
|
|
98
|
+
* - `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats).
|
|
99
|
+
* `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read
|
|
100
|
+
* larger integers will throw a `RangeError`.
|
|
101
|
+
* - `"bigint"`: returns SQLite integers as JavaScript `bigint`-s (arbitrary precision integers). Bigints can
|
|
102
|
+
* precisely represent all SQLite integers.
|
|
103
|
+
* - `"string"`: returns SQLite integers as strings.
|
|
104
|
+
*/
|
|
105
|
+
readonly intMode?: "number" | "bigint" | "string" | undefined
|
|
106
|
+
/** Concurrency limit.
|
|
107
|
+
*
|
|
108
|
+
* By default, the client performs up to 20 concurrent requests. You can set this option to a higher
|
|
109
|
+
* number to increase the concurrency limit or set it to 0 to disable concurrency limits completely.
|
|
110
|
+
*/
|
|
111
|
+
readonly concurrency?: number | undefined
|
|
112
|
+
}
|
|
89
113
|
|
|
90
|
-
|
|
91
|
-
|
|
114
|
+
/**
|
|
115
|
+
* @category models
|
|
116
|
+
* @since 1.0.0
|
|
117
|
+
*/
|
|
118
|
+
export interface Live extends Base {
|
|
119
|
+
readonly liveClient: Libsql.Client
|
|
120
|
+
}
|
|
92
121
|
}
|
|
93
122
|
|
|
94
|
-
interface LibsqlConnection extends Connection {
|
|
123
|
+
interface LibsqlConnection extends Connection {
|
|
124
|
+
readonly beginTransaction: Effect.Effect<LibsqlConnection, SqlError>
|
|
125
|
+
readonly commit: Effect.Effect<void, SqlError>
|
|
126
|
+
readonly rollback: Effect.Effect<void, SqlError>
|
|
127
|
+
}
|
|
95
128
|
|
|
96
129
|
/**
|
|
97
130
|
* @category constructor
|
|
@@ -106,84 +139,138 @@ export const make = (
|
|
|
106
139
|
options.transformResultNames!
|
|
107
140
|
).array
|
|
108
141
|
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
142
|
+
const spanAttributes: Array<[string, unknown]> = [
|
|
143
|
+
...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
|
|
144
|
+
[Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]
|
|
145
|
+
]
|
|
146
|
+
|
|
147
|
+
class LibsqlConnectionImpl implements LibsqlConnection {
|
|
148
|
+
constructor(readonly sdk: Libsql.Client | Libsql.Transaction) {}
|
|
112
149
|
|
|
113
|
-
|
|
150
|
+
run(
|
|
114
151
|
sql: string,
|
|
115
152
|
params: ReadonlyArray<Statement.Primitive> = []
|
|
116
|
-
)
|
|
117
|
-
Effect.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
153
|
+
) {
|
|
154
|
+
return Effect.map(
|
|
155
|
+
Effect.tryPromise({
|
|
156
|
+
try: () => this.sdk.execute({ sql, args: params as Array<any> }),
|
|
157
|
+
catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" })
|
|
158
|
+
}),
|
|
159
|
+
(results) => results.rows
|
|
160
|
+
)
|
|
161
|
+
}
|
|
121
162
|
|
|
122
|
-
|
|
163
|
+
runRaw(
|
|
123
164
|
sql: string,
|
|
124
165
|
params: ReadonlyArray<Statement.Primitive> = []
|
|
125
|
-
)
|
|
126
|
-
Effect.tryPromise({
|
|
127
|
-
try: () =>
|
|
166
|
+
) {
|
|
167
|
+
return Effect.tryPromise({
|
|
168
|
+
try: () => this.sdk.execute({ sql, args: params as Array<any> }),
|
|
128
169
|
catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" })
|
|
129
170
|
})
|
|
171
|
+
}
|
|
130
172
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
})
|
|
173
|
+
runTransform(
|
|
174
|
+
sql: string,
|
|
175
|
+
params: ReadonlyArray<Statement.Primitive> = []
|
|
176
|
+
) {
|
|
177
|
+
return options.transformResultNames
|
|
178
|
+
? Effect.map(this.run(sql, params), transformRows)
|
|
179
|
+
: this.run(sql, params)
|
|
180
|
+
}
|
|
156
181
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
182
|
+
execute(sql: string, params: ReadonlyArray<Statement.Primitive>) {
|
|
183
|
+
return this.runTransform(sql, params)
|
|
184
|
+
}
|
|
185
|
+
executeRaw(sql: string, params: ReadonlyArray<Statement.Primitive>) {
|
|
186
|
+
return this.runRaw(sql, params)
|
|
187
|
+
}
|
|
188
|
+
executeValues(sql: string, params: ReadonlyArray<Statement.Primitive>) {
|
|
189
|
+
return Effect.map(this.run(sql, params), (rows) => rows.map((row) => Array.from(row) as Array<any>))
|
|
190
|
+
}
|
|
191
|
+
executeWithoutTransform(sql: string, params: ReadonlyArray<Statement.Primitive>) {
|
|
192
|
+
return this.run(sql, params)
|
|
193
|
+
}
|
|
194
|
+
executeUnprepared(sql: string, params?: ReadonlyArray<Statement.Primitive>) {
|
|
195
|
+
return this.run(sql, params)
|
|
196
|
+
}
|
|
197
|
+
executeStream() {
|
|
198
|
+
return Effect.dieMessage("executeStream not implemented")
|
|
199
|
+
}
|
|
200
|
+
get beginTransaction() {
|
|
201
|
+
return Effect.map(
|
|
202
|
+
Effect.tryPromise({
|
|
203
|
+
try: () => (this.sdk as Libsql.Client).transaction("write"),
|
|
204
|
+
catch: (cause) => new SqlError({ cause, message: "Failed to begin transaction" })
|
|
205
|
+
}),
|
|
206
|
+
(tx) => new LibsqlConnectionImpl(tx)
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
get commit() {
|
|
210
|
+
return Effect.tryPromise({
|
|
211
|
+
try: () => (this.sdk as Libsql.Transaction).commit(),
|
|
212
|
+
catch: (cause) => new SqlError({ cause, message: "Failed to commit transaction" })
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
get rollback() {
|
|
216
|
+
return Effect.tryPromise({
|
|
217
|
+
try: () => (this.sdk as Libsql.Transaction).rollback(),
|
|
218
|
+
catch: (cause) => new SqlError({ cause, message: "Failed to rollback transaction" })
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const connection = "liveClient" in options
|
|
224
|
+
? new LibsqlConnectionImpl(options.liveClient)
|
|
225
|
+
: yield* Effect.map(
|
|
226
|
+
Effect.acquireRelease(
|
|
227
|
+
Effect.sync(() => Libsql.createClient(options as Libsql.Config)),
|
|
228
|
+
(sdk) => Effect.sync(() => sdk.close())
|
|
169
229
|
),
|
|
170
|
-
|
|
230
|
+
(sdk) => new LibsqlConnectionImpl(sdk)
|
|
171
231
|
)
|
|
232
|
+
const semaphore = yield* Effect.makeSemaphore(1)
|
|
233
|
+
|
|
234
|
+
const withTransaction = Client.makeWithTransaction({
|
|
235
|
+
transactionTag: LibsqlTransaction,
|
|
236
|
+
spanAttributes,
|
|
237
|
+
acquireConnection: Effect.uninterruptibleMask((restore) =>
|
|
238
|
+
Scope.make().pipe(
|
|
239
|
+
Effect.bindTo("scope"),
|
|
240
|
+
Effect.bind("conn", ({ scope }) =>
|
|
241
|
+
restore(semaphore.take(1)).pipe(
|
|
242
|
+
Effect.zipRight(Scope.addFinalizer(scope, semaphore.release(1))),
|
|
243
|
+
Effect.zipRight(connection.beginTransaction)
|
|
244
|
+
)),
|
|
245
|
+
Effect.map(({ conn, scope }) => [scope, conn] as const)
|
|
246
|
+
)
|
|
247
|
+
),
|
|
248
|
+
begin: () => Effect.void, // already begun in acquireConnection
|
|
249
|
+
savepoint: (conn, id) => conn.executeRaw(`SAVEPOINT effect_sql_${id};`, []),
|
|
250
|
+
commit: (conn) => conn.commit,
|
|
251
|
+
rollback: (conn) => conn.rollback,
|
|
252
|
+
rollbackSavepoint: (conn, id) => conn.executeRaw(`ROLLBACK TO SAVEPOINT effect_sql_${id};`, [])
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
const acquirer = Effect.flatMap(
|
|
256
|
+
Effect.serviceOption(LibsqlTransaction),
|
|
257
|
+
Option.match({
|
|
258
|
+
onNone: () => semaphore.withPermits(1)(Effect.succeed(connection as LibsqlConnection)),
|
|
259
|
+
onSome: ([conn]) => Effect.succeed(conn)
|
|
260
|
+
})
|
|
172
261
|
)
|
|
173
262
|
|
|
174
263
|
return Object.assign(
|
|
175
264
|
Client.make({
|
|
176
265
|
acquirer,
|
|
177
266
|
compiler,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
|
|
181
|
-
[Otel.SEMATTRS_DB_SYSTEM, Otel.DBSYSTEMVALUES_SQLITE]
|
|
182
|
-
]
|
|
183
|
-
}) as LibsqlClient,
|
|
267
|
+
spanAttributes
|
|
268
|
+
}),
|
|
184
269
|
{
|
|
185
270
|
[TypeId]: TypeId as TypeId,
|
|
186
|
-
config: options
|
|
271
|
+
config: options,
|
|
272
|
+
withTransaction,
|
|
273
|
+
sdk: connection.sdk
|
|
187
274
|
}
|
|
188
275
|
)
|
|
189
276
|
})
|