@effect/sql-sqlite-bun 4.0.0-beta.8 → 4.0.0-beta.80
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/SqliteClient.d.ts +34 -14
- package/dist/SqliteClient.d.ts.map +1 -1
- package/dist/SqliteClient.js +46 -25
- package/dist/SqliteClient.js.map +1 -1
- package/dist/SqliteMigrator.d.ts +17 -6
- package/dist/SqliteMigrator.d.ts.map +1 -1
- package/dist/SqliteMigrator.js +9 -5
- package/dist/SqliteMigrator.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +5 -5
- package/src/SqliteClient.ts +61 -30
- package/src/SqliteMigrator.ts +17 -6
- package/src/index.ts +3 -3
package/dist/SqliteClient.d.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import * as Config from "effect/Config";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
3
4
|
import * as Layer from "effect/Layer";
|
|
4
5
|
import * as Scope from "effect/Scope";
|
|
5
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
6
6
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
7
7
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
8
8
|
import { SqlError } from "effect/unstable/sql/SqlError";
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Runtime type identifier used to mark Bun `SqliteClient` values.
|
|
11
|
+
*
|
|
12
|
+
* @category type IDs
|
|
13
|
+
* @since 4.0.0
|
|
12
14
|
*/
|
|
13
15
|
export declare const TypeId: TypeId;
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
+
* Type-level identifier used to mark Bun `SqliteClient` values.
|
|
18
|
+
*
|
|
19
|
+
* @category type IDs
|
|
20
|
+
* @since 4.0.0
|
|
17
21
|
*/
|
|
18
22
|
export type TypeId = "~@effect/sql-sqlite-bun/SqliteClient";
|
|
19
23
|
/**
|
|
24
|
+
* Bun SQLite client service, extending `SqlClient` with database export and extension loading helpers. `updateValues` is not supported.
|
|
25
|
+
*
|
|
20
26
|
* @category models
|
|
21
|
-
* @since
|
|
27
|
+
* @since 4.0.0
|
|
22
28
|
*/
|
|
23
29
|
export interface SqliteClient extends Client.SqlClient {
|
|
24
30
|
readonly [TypeId]: TypeId;
|
|
@@ -29,13 +35,21 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
29
35
|
readonly updateValues: never;
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
38
|
+
* Service tag for the Bun SQLite client service.
|
|
39
|
+
*
|
|
40
|
+
* **When to use**
|
|
41
|
+
*
|
|
42
|
+
* Use to access or provide a Bun SQLite client through the Effect context.
|
|
43
|
+
*
|
|
44
|
+
* @category services
|
|
45
|
+
* @since 4.0.0
|
|
34
46
|
*/
|
|
35
|
-
export declare const SqliteClient:
|
|
47
|
+
export declare const SqliteClient: Context.Service<SqliteClient, SqliteClient>;
|
|
36
48
|
/**
|
|
49
|
+
* Configuration for a Bun SQLite client, including filename, open mode flags, WAL behavior, span attributes, and query/result name transforms.
|
|
50
|
+
*
|
|
37
51
|
* @category models
|
|
38
|
-
* @since
|
|
52
|
+
* @since 4.0.0
|
|
39
53
|
*/
|
|
40
54
|
export interface SqliteClientConfig {
|
|
41
55
|
readonly filename: string;
|
|
@@ -48,18 +62,24 @@ export interface SqliteClientConfig {
|
|
|
48
62
|
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
49
63
|
}
|
|
50
64
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
65
|
+
* Creates a scoped Bun SQLite client for a database file, enabling WAL by default and serializing access. Streaming queries are not implemented.
|
|
66
|
+
*
|
|
67
|
+
* @category constructors
|
|
68
|
+
* @since 4.0.0
|
|
53
69
|
*/
|
|
54
70
|
export declare const make: (options: SqliteClientConfig) => Effect.Effect<SqliteClient, never, Scope.Scope | Reactivity.Reactivity>;
|
|
55
71
|
/**
|
|
72
|
+
* Creates a layer from a `Config`-wrapped Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
73
|
+
*
|
|
56
74
|
* @category layers
|
|
57
|
-
* @since
|
|
75
|
+
* @since 4.0.0
|
|
58
76
|
*/
|
|
59
77
|
export declare const layerConfig: (config: Config.Wrap<SqliteClientConfig>) => Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError>;
|
|
60
78
|
/**
|
|
79
|
+
* Creates a layer from a concrete Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
80
|
+
*
|
|
61
81
|
* @category layers
|
|
62
|
-
* @since
|
|
82
|
+
* @since 4.0.0
|
|
63
83
|
*/
|
|
64
84
|
export declare const layer: (config: SqliteClientConfig) => Layer.Layer<SqliteClient | Client.SqlClient>;
|
|
65
85
|
//# sourceMappingURL=SqliteClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteClient.d.ts","sourceRoot":"","sources":["../src/SqliteClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SqliteClient.d.ts","sourceRoot":"","sources":["../src/SqliteClient.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,UAAU,MAAM,uCAAuC,CAAA;AACnE,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAEvD,OAAO,EAAuB,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAQ5E;;;;;GAKG;AACH,eAAO,MAAM,MAAM,EAAE,MAA+C,CAAA;AAEpE;;;;;GAKG;A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,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CAsHrE,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,KACtC,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAUzB,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,QAAQ,kBAAkB,KACzB,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,CAML,CAAA"}
|
package/dist/SqliteClient.js
CHANGED
|
@@ -1,34 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Connects Effect SQL to SQLite when running on Bun, using `bun:sqlite`.
|
|
3
|
+
*
|
|
4
|
+
* This module opens a SQLite database and exposes it as both `SqliteClient` and
|
|
5
|
+
* the generic Effect SQL client. It serializes access to the database, enables
|
|
6
|
+
* WAL mode unless disabled, and supports database export and extension loading.
|
|
7
|
+
* Streaming queries and `updateValues` are not supported by this driver.
|
|
8
|
+
*
|
|
9
|
+
* @since 4.0.0
|
|
3
10
|
*/
|
|
4
11
|
import { Database } from "bun:sqlite";
|
|
5
12
|
import * as Config from "effect/Config";
|
|
13
|
+
import * as Context from "effect/Context";
|
|
6
14
|
import * as Effect from "effect/Effect";
|
|
7
15
|
import * as Fiber from "effect/Fiber";
|
|
8
16
|
import { identity } from "effect/Function";
|
|
9
17
|
import * as Layer from "effect/Layer";
|
|
10
18
|
import * as Scope from "effect/Scope";
|
|
11
19
|
import * as Semaphore from "effect/Semaphore";
|
|
12
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
13
20
|
import * as Stream from "effect/Stream";
|
|
14
21
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
15
22
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
16
|
-
import { SqlError } from "effect/unstable/sql/SqlError";
|
|
23
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError";
|
|
17
24
|
import * as Statement from "effect/unstable/sql/Statement";
|
|
18
25
|
const ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
26
|
+
const classifyError = (cause, message, operation) => classifySqliteError(cause, {
|
|
27
|
+
message,
|
|
28
|
+
operation
|
|
29
|
+
});
|
|
19
30
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
31
|
+
* Runtime type identifier used to mark Bun `SqliteClient` values.
|
|
32
|
+
*
|
|
33
|
+
* @category type IDs
|
|
34
|
+
* @since 4.0.0
|
|
22
35
|
*/
|
|
23
36
|
export const TypeId = "~@effect/sql-sqlite-bun/SqliteClient";
|
|
24
37
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
38
|
+
* Service tag for the Bun SQLite client service.
|
|
39
|
+
*
|
|
40
|
+
* **When to use**
|
|
41
|
+
*
|
|
42
|
+
* Use to access or provide a Bun SQLite client through the Effect context.
|
|
43
|
+
*
|
|
44
|
+
* @category services
|
|
45
|
+
* @since 4.0.0
|
|
27
46
|
*/
|
|
28
|
-
export const SqliteClient = /*#__PURE__*/
|
|
47
|
+
export const SqliteClient = /*#__PURE__*/Context.Service("@effect/sql-sqlite-bun/Client");
|
|
29
48
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
49
|
+
* Creates a scoped Bun SQLite client for a database file, enabling WAL by default and serializing access. Streaming queries are not implemented.
|
|
50
|
+
*
|
|
51
|
+
* @category constructors
|
|
52
|
+
* @since 4.0.0
|
|
32
53
|
*/
|
|
33
54
|
export const make = options => Effect.gen(function* () {
|
|
34
55
|
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
@@ -45,29 +66,27 @@ export const make = options => Effect.gen(function* () {
|
|
|
45
66
|
}
|
|
46
67
|
const run = (sql, params = []) => Effect.withFiber(fiber => {
|
|
47
68
|
const statement = db.query(sql);
|
|
48
|
-
const useSafeIntegers =
|
|
69
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers);
|
|
49
70
|
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
50
71
|
statement.safeIntegers(useSafeIntegers);
|
|
51
72
|
try {
|
|
52
73
|
return Effect.succeed(statement.all(...params) ?? []);
|
|
53
74
|
} catch (cause) {
|
|
54
75
|
return Effect.fail(new SqlError({
|
|
55
|
-
cause,
|
|
56
|
-
message: "Failed to execute statement"
|
|
76
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
57
77
|
}));
|
|
58
78
|
}
|
|
59
79
|
});
|
|
60
80
|
const runValues = (sql, params = []) => Effect.withFiber(fiber => {
|
|
61
81
|
const statement = db.query(sql);
|
|
62
|
-
const useSafeIntegers =
|
|
82
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers);
|
|
63
83
|
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
64
84
|
statement.safeIntegers(useSafeIntegers);
|
|
65
85
|
try {
|
|
66
86
|
return Effect.succeed(statement.values(...params) ?? []);
|
|
67
87
|
} catch (cause) {
|
|
68
88
|
return Effect.fail(new SqlError({
|
|
69
|
-
cause,
|
|
70
|
-
message: "Failed to execute statement"
|
|
89
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
71
90
|
}));
|
|
72
91
|
}
|
|
73
92
|
});
|
|
@@ -90,15 +109,13 @@ export const make = options => Effect.gen(function* () {
|
|
|
90
109
|
export: Effect.try({
|
|
91
110
|
try: () => db.serialize(),
|
|
92
111
|
catch: cause => new SqlError({
|
|
93
|
-
cause,
|
|
94
|
-
message: "Failed to export database"
|
|
112
|
+
reason: classifyError(cause, "Failed to export database", "export")
|
|
95
113
|
})
|
|
96
114
|
}),
|
|
97
115
|
loadExtension: path => Effect.try({
|
|
98
116
|
try: () => db.loadExtension(path),
|
|
99
117
|
catch: cause => new SqlError({
|
|
100
|
-
cause,
|
|
101
|
-
message: "Failed to load extension"
|
|
118
|
+
reason: classifyError(cause, "Failed to load extension", "loadExtension")
|
|
102
119
|
})
|
|
103
120
|
})
|
|
104
121
|
});
|
|
@@ -108,7 +125,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
108
125
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
109
126
|
const transactionAcquirer = Effect.uninterruptibleMask(restore => {
|
|
110
127
|
const fiber = Fiber.getCurrent();
|
|
111
|
-
const scope =
|
|
128
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope);
|
|
112
129
|
return Effect.as(Effect.tap(restore(semaphore.take(1)), () => Scope.addFinalizer(scope, semaphore.release(1))), connection);
|
|
113
130
|
});
|
|
114
131
|
return Object.assign(yield* Client.make({
|
|
@@ -125,13 +142,17 @@ export const make = options => Effect.gen(function* () {
|
|
|
125
142
|
});
|
|
126
143
|
});
|
|
127
144
|
/**
|
|
145
|
+
* Creates a layer from a `Config`-wrapped Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
146
|
+
*
|
|
128
147
|
* @category layers
|
|
129
|
-
* @since
|
|
148
|
+
* @since 4.0.0
|
|
130
149
|
*/
|
|
131
|
-
export const layerConfig = config => Layer.
|
|
150
|
+
export const layerConfig = config => Layer.effectContext(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));
|
|
132
151
|
/**
|
|
152
|
+
* Creates a layer from a concrete Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
153
|
+
*
|
|
133
154
|
* @category layers
|
|
134
|
-
* @since
|
|
155
|
+
* @since 4.0.0
|
|
135
156
|
*/
|
|
136
|
-
export const layer = config => Layer.
|
|
157
|
+
export const layer = config => Layer.effectContext(Effect.map(make(config), client => Context.make(SqliteClient, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
|
|
137
158
|
//# sourceMappingURL=SqliteClient.js.map
|
package/dist/SqliteClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteClient.js","names":["Database","Config","Effect","Fiber","identity","Layer","Scope","Semaphore","
|
|
1
|
+
{"version":3,"file":"SqliteClient.js","names":["Database","Config","Context","Effect","Fiber","identity","Layer","Scope","Semaphore","Stream","Reactivity","Client","classifySqliteError","SqlError","Statement","ATTR_DB_SYSTEM_NAME","classifyError","cause","message","operation","TypeId","SqliteClient","Service","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","makeConnection","db","filename","readonly","readwrite","create","addFinalizer","sync","close","disableWAL","run","sql","params","withFiber","fiber","statement","query","useSafeIntegers","get","context","SafeIntegers","safeIntegers","succeed","all","fail","reason","runValues","values","execute","map","executeRaw","executeValues","executeUnprepared","executeStream","_sql","_params","die","export","try","serialize","catch","loadExtension","path","semaphore","connection","acquirer","withPermits","transactionAcquirer","uninterruptibleMask","restore","getCurrent","scope","getUnsafe","as","tap","take","release","Object","assign","spanAttributes","entries","config","flatMap","_","layerConfig","effectContext","unwrap","pipe","client","add","SqlClient","provide","layer"],"sources":["../src/SqliteClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;AAUA,SAASA,QAAQ,QAAQ,YAAY;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAKC,MAAM,MAAM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C,CAAC","ignoreList":[]}
|
package/dist/SqliteMigrator.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Runs database migrations for Bun SQLite projects that use Effect SQL.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports the shared migration loaders and errors, then provides
|
|
5
|
+
* `run` and `layer` helpers that apply pending migration files with the current
|
|
6
|
+
* `SqlClient`. It does not add Bun-specific schema dump support; migration
|
|
7
|
+
* execution is handled by the shared SQL migrator.
|
|
8
|
+
*
|
|
9
|
+
* @since 4.0.0
|
|
3
10
|
*/
|
|
4
11
|
import type * as Effect from "effect/Effect";
|
|
5
12
|
import * as Layer from "effect/Layer";
|
|
@@ -7,17 +14,21 @@ import * as Migrator from "effect/unstable/sql/Migrator";
|
|
|
7
14
|
import type * as Client from "effect/unstable/sql/SqlClient";
|
|
8
15
|
import type { SqlError } from "effect/unstable/sql/SqlError";
|
|
9
16
|
/**
|
|
10
|
-
* @since
|
|
17
|
+
* @since 4.0.0
|
|
11
18
|
*/
|
|
12
19
|
export * from "effect/unstable/sql/Migrator";
|
|
13
20
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
21
|
+
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
22
|
+
*
|
|
23
|
+
* @category constructors
|
|
24
|
+
* @since 4.0.0
|
|
16
25
|
*/
|
|
17
26
|
export declare const run: <R2 = never>(options: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>;
|
|
18
27
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
28
|
+
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
29
|
+
*
|
|
30
|
+
* @category constructors
|
|
31
|
+
* @since 4.0.0
|
|
21
32
|
*/
|
|
22
33
|
export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, SqlError | Migrator.MigrationError, Client.SqlClient | R>;
|
|
23
34
|
//# sourceMappingURL=SqliteMigrator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteMigrator.d.ts","sourceRoot":"","sources":["../src/SqliteMigrator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"SqliteMigrator.d.ts","sourceRoot":"","sources":["../src/SqliteMigrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAA;AACxD,OAAO,KAAK,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAE5D;;GAEG;AACH,cAAc,8BAA8B,CAAA;AAE5C;;;;;GAKG;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,CA2CrB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EACrB,SAAS,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CACZ,KAAK,EACL,QAAQ,GAAG,QAAQ,CAAC,cAAc,EAClC,MAAM,CAAC,SAAS,GAAG,CAAC,CACgB,CAAA"}
|
package/dist/SqliteMigrator.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as Layer from "effect/Layer";
|
|
2
2
|
import * as Migrator from "effect/unstable/sql/Migrator";
|
|
3
3
|
/**
|
|
4
|
-
* @since
|
|
4
|
+
* @since 4.0.0
|
|
5
5
|
*/
|
|
6
6
|
export * from "effect/unstable/sql/Migrator";
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
9
|
+
*
|
|
10
|
+
* @category constructors
|
|
11
|
+
* @since 4.0.0
|
|
10
12
|
*/
|
|
11
13
|
export const run = /*#__PURE__*/Migrator.make({
|
|
12
14
|
// dumpSchema(path, table) {
|
|
@@ -52,8 +54,10 @@ export const run = /*#__PURE__*/Migrator.make({
|
|
|
52
54
|
// }
|
|
53
55
|
});
|
|
54
56
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
+
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
58
|
+
*
|
|
59
|
+
* @category constructors
|
|
60
|
+
* @since 4.0.0
|
|
57
61
|
*/
|
|
58
62
|
export const layer = options => Layer.effectDiscard(run(options));
|
|
59
63
|
//# sourceMappingURL=SqliteMigrator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/SqliteMigrator.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"file":"SqliteMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/SqliteMigrator.ts"],"sourcesContent":[null],"mappings":"AAWA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,8BAA8B;AAIxD;;;AAGA,cAAc,8BAA8B;AAE5C;;;;;;AAMA,OAAO,MAAMC,GAAG,gBAMZD,QAAQ,CAACE,IAAI,CAAC;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AAAA,CACD,CAAC;AAEF;;;;;;AAMA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAKjCL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* @since
|
|
5
|
+
* @since 4.0.0
|
|
6
6
|
*/
|
|
7
7
|
export * as SqliteClient from "./SqliteClient.ts";
|
|
8
8
|
/**
|
|
9
|
-
* @since
|
|
9
|
+
* @since 4.0.0
|
|
10
10
|
*/
|
|
11
11
|
export * as SqliteMigrator from "./SqliteMigrator.ts";
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
5
5
|
/**
|
|
6
|
-
* @since
|
|
6
|
+
* @since 4.0.0
|
|
7
7
|
*/
|
|
8
8
|
export * as SqliteClient from "./SqliteClient.js";
|
|
9
9
|
/**
|
|
10
|
-
* @since
|
|
10
|
+
* @since 4.0.0
|
|
11
11
|
*/
|
|
12
12
|
export * as SqliteMigrator from "./SqliteMigrator.js";
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-sqlite-bun",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.80",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A SQLite toolkit for Effect",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"provenance": true
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/bun": "^1.3.
|
|
47
|
-
"@effect/platform-bun": "^4.0.0-beta.
|
|
48
|
-
"effect": "^4.0.0-beta.
|
|
46
|
+
"@types/bun": "^1.3.13",
|
|
47
|
+
"@effect/platform-bun": "^4.0.0-beta.80",
|
|
48
|
+
"effect": "^4.0.0-beta.80"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"effect": "^4.0.0-beta.
|
|
51
|
+
"effect": "^4.0.0-beta.80"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"codegen": "effect-utils codegen",
|
package/src/SqliteClient.ts
CHANGED
|
@@ -1,39 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Connects Effect SQL to SQLite when running on Bun, using `bun:sqlite`.
|
|
3
|
+
*
|
|
4
|
+
* This module opens a SQLite database and exposes it as both `SqliteClient` and
|
|
5
|
+
* the generic Effect SQL client. It serializes access to the database, enables
|
|
6
|
+
* WAL mode unless disabled, and supports database export and extension loading.
|
|
7
|
+
* Streaming queries and `updateValues` are not supported by this driver.
|
|
8
|
+
*
|
|
9
|
+
* @since 4.0.0
|
|
3
10
|
*/
|
|
4
11
|
import { Database } from "bun:sqlite"
|
|
5
12
|
import * as Config from "effect/Config"
|
|
13
|
+
import * as Context from "effect/Context"
|
|
6
14
|
import * as Effect from "effect/Effect"
|
|
7
15
|
import * as Fiber from "effect/Fiber"
|
|
8
16
|
import { identity } from "effect/Function"
|
|
9
17
|
import * as Layer from "effect/Layer"
|
|
10
18
|
import * as Scope from "effect/Scope"
|
|
11
19
|
import * as Semaphore from "effect/Semaphore"
|
|
12
|
-
import * as ServiceMap from "effect/ServiceMap"
|
|
13
20
|
import * as Stream from "effect/Stream"
|
|
14
21
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity"
|
|
15
22
|
import * as Client from "effect/unstable/sql/SqlClient"
|
|
16
23
|
import type { Connection } from "effect/unstable/sql/SqlConnection"
|
|
17
|
-
import { SqlError } from "effect/unstable/sql/SqlError"
|
|
24
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
|
|
18
25
|
import * as Statement from "effect/unstable/sql/Statement"
|
|
19
26
|
|
|
20
27
|
const ATTR_DB_SYSTEM_NAME = "db.system.name"
|
|
21
28
|
|
|
29
|
+
const classifyError = (cause: unknown, message: string, operation: string) =>
|
|
30
|
+
classifySqliteError(cause, { message, operation })
|
|
31
|
+
|
|
22
32
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
33
|
+
* Runtime type identifier used to mark Bun `SqliteClient` values.
|
|
34
|
+
*
|
|
35
|
+
* @category type IDs
|
|
36
|
+
* @since 4.0.0
|
|
25
37
|
*/
|
|
26
38
|
export const TypeId: TypeId = "~@effect/sql-sqlite-bun/SqliteClient"
|
|
27
39
|
|
|
28
40
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
41
|
+
* Type-level identifier used to mark Bun `SqliteClient` values.
|
|
42
|
+
*
|
|
43
|
+
* @category type IDs
|
|
44
|
+
* @since 4.0.0
|
|
31
45
|
*/
|
|
32
46
|
export type TypeId = "~@effect/sql-sqlite-bun/SqliteClient"
|
|
33
47
|
|
|
34
48
|
/**
|
|
49
|
+
* Bun SQLite client service, extending `SqlClient` with database export and extension loading helpers. `updateValues` is not supported.
|
|
50
|
+
*
|
|
35
51
|
* @category models
|
|
36
|
-
* @since
|
|
52
|
+
* @since 4.0.0
|
|
37
53
|
*/
|
|
38
54
|
export interface SqliteClient extends Client.SqlClient {
|
|
39
55
|
readonly [TypeId]: TypeId
|
|
@@ -46,14 +62,22 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
46
62
|
}
|
|
47
63
|
|
|
48
64
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
65
|
+
* Service tag for the Bun SQLite client service.
|
|
66
|
+
*
|
|
67
|
+
* **When to use**
|
|
68
|
+
*
|
|
69
|
+
* Use to access or provide a Bun SQLite client through the Effect context.
|
|
70
|
+
*
|
|
71
|
+
* @category services
|
|
72
|
+
* @since 4.0.0
|
|
51
73
|
*/
|
|
52
|
-
export const SqliteClient =
|
|
74
|
+
export const SqliteClient = Context.Service<SqliteClient>("@effect/sql-sqlite-bun/Client")
|
|
53
75
|
|
|
54
76
|
/**
|
|
77
|
+
* Configuration for a Bun SQLite client, including filename, open mode flags, WAL behavior, span attributes, and query/result name transforms.
|
|
78
|
+
*
|
|
55
79
|
* @category models
|
|
56
|
-
* @since
|
|
80
|
+
* @since 4.0.0
|
|
57
81
|
*/
|
|
58
82
|
export interface SqliteClientConfig {
|
|
59
83
|
readonly filename: string
|
|
@@ -74,8 +98,10 @@ interface SqliteConnection extends Connection {
|
|
|
74
98
|
}
|
|
75
99
|
|
|
76
100
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
101
|
+
* Creates a scoped Bun SQLite client for a database file, enabling WAL by default and serializing access. Streaming queries are not implemented.
|
|
102
|
+
*
|
|
103
|
+
* @category constructors
|
|
104
|
+
* @since 4.0.0
|
|
79
105
|
*/
|
|
80
106
|
export const make = (
|
|
81
107
|
options: SqliteClientConfig
|
|
@@ -106,13 +132,13 @@ export const make = (
|
|
|
106
132
|
) =>
|
|
107
133
|
Effect.withFiber<Array<any>, SqlError>((fiber) => {
|
|
108
134
|
const statement = db.query(sql)
|
|
109
|
-
const useSafeIntegers =
|
|
135
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers)
|
|
110
136
|
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
111
137
|
statement.safeIntegers(useSafeIntegers)
|
|
112
138
|
try {
|
|
113
139
|
return Effect.succeed((statement.all(...(params as any)) ?? []) as Array<any>)
|
|
114
140
|
} catch (cause) {
|
|
115
|
-
return Effect.fail(new SqlError({ cause,
|
|
141
|
+
return Effect.fail(new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") }))
|
|
116
142
|
}
|
|
117
143
|
})
|
|
118
144
|
|
|
@@ -122,13 +148,13 @@ export const make = (
|
|
|
122
148
|
) =>
|
|
123
149
|
Effect.withFiber<Array<any>, SqlError>((fiber) => {
|
|
124
150
|
const statement = db.query(sql)
|
|
125
|
-
const useSafeIntegers =
|
|
151
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers)
|
|
126
152
|
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
127
153
|
statement.safeIntegers(useSafeIntegers)
|
|
128
154
|
try {
|
|
129
155
|
return Effect.succeed((statement.values(...(params as any)) ?? []) as Array<any>)
|
|
130
156
|
} catch (cause) {
|
|
131
|
-
return Effect.fail(new SqlError({ cause,
|
|
157
|
+
return Effect.fail(new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") }))
|
|
132
158
|
}
|
|
133
159
|
})
|
|
134
160
|
|
|
@@ -152,12 +178,13 @@ export const make = (
|
|
|
152
178
|
},
|
|
153
179
|
export: Effect.try({
|
|
154
180
|
try: () => db.serialize(),
|
|
155
|
-
catch: (cause) => new SqlError({ cause,
|
|
181
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to export database", "export") })
|
|
156
182
|
}),
|
|
157
183
|
loadExtension: (path) =>
|
|
158
184
|
Effect.try({
|
|
159
185
|
try: () => db.loadExtension(path),
|
|
160
|
-
catch: (cause) =>
|
|
186
|
+
catch: (cause) =>
|
|
187
|
+
new SqlError({ reason: classifyError(cause, "Failed to load extension", "loadExtension") })
|
|
161
188
|
})
|
|
162
189
|
})
|
|
163
190
|
})
|
|
@@ -168,7 +195,7 @@ export const make = (
|
|
|
168
195
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
|
|
169
196
|
const transactionAcquirer = Effect.uninterruptibleMask((restore) => {
|
|
170
197
|
const fiber = Fiber.getCurrent()!
|
|
171
|
-
const scope =
|
|
198
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope)
|
|
172
199
|
return Effect.as(
|
|
173
200
|
Effect.tap(
|
|
174
201
|
restore(semaphore.take(1)),
|
|
@@ -199,33 +226,37 @@ export const make = (
|
|
|
199
226
|
})
|
|
200
227
|
|
|
201
228
|
/**
|
|
229
|
+
* Creates a layer from a `Config`-wrapped Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
230
|
+
*
|
|
202
231
|
* @category layers
|
|
203
|
-
* @since
|
|
232
|
+
* @since 4.0.0
|
|
204
233
|
*/
|
|
205
234
|
export const layerConfig = (
|
|
206
235
|
config: Config.Wrap<SqliteClientConfig>
|
|
207
236
|
): Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError> =>
|
|
208
|
-
Layer.
|
|
209
|
-
Config.unwrap(config).
|
|
237
|
+
Layer.effectContext(
|
|
238
|
+
Config.unwrap(config).pipe(
|
|
210
239
|
Effect.flatMap(make),
|
|
211
240
|
Effect.map((client) =>
|
|
212
|
-
|
|
213
|
-
|
|
241
|
+
Context.make(SqliteClient, client).pipe(
|
|
242
|
+
Context.add(Client.SqlClient, client)
|
|
214
243
|
)
|
|
215
244
|
)
|
|
216
245
|
)
|
|
217
246
|
).pipe(Layer.provide(Reactivity.layer))
|
|
218
247
|
|
|
219
248
|
/**
|
|
249
|
+
* Creates a layer from a concrete Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
250
|
+
*
|
|
220
251
|
* @category layers
|
|
221
|
-
* @since
|
|
252
|
+
* @since 4.0.0
|
|
222
253
|
*/
|
|
223
254
|
export const layer = (
|
|
224
255
|
config: SqliteClientConfig
|
|
225
256
|
): Layer.Layer<SqliteClient | Client.SqlClient> =>
|
|
226
|
-
Layer.
|
|
257
|
+
Layer.effectContext(
|
|
227
258
|
Effect.map(make(config), (client) =>
|
|
228
|
-
|
|
229
|
-
|
|
259
|
+
Context.make(SqliteClient, client).pipe(
|
|
260
|
+
Context.add(Client.SqlClient, client)
|
|
230
261
|
))
|
|
231
262
|
).pipe(Layer.provide(Reactivity.layer))
|
package/src/SqliteMigrator.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Runs database migrations for Bun SQLite projects that use Effect SQL.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports the shared migration loaders and errors, then provides
|
|
5
|
+
* `run` and `layer` helpers that apply pending migration files with the current
|
|
6
|
+
* `SqlClient`. It does not add Bun-specific schema dump support; migration
|
|
7
|
+
* execution is handled by the shared SQL migrator.
|
|
8
|
+
*
|
|
9
|
+
* @since 4.0.0
|
|
3
10
|
*/
|
|
4
11
|
import type * as Effect from "effect/Effect"
|
|
5
12
|
import * as Layer from "effect/Layer"
|
|
@@ -8,13 +15,15 @@ import type * as Client from "effect/unstable/sql/SqlClient"
|
|
|
8
15
|
import type { SqlError } from "effect/unstable/sql/SqlError"
|
|
9
16
|
|
|
10
17
|
/**
|
|
11
|
-
* @since
|
|
18
|
+
* @since 4.0.0
|
|
12
19
|
*/
|
|
13
20
|
export * from "effect/unstable/sql/Migrator"
|
|
14
21
|
|
|
15
22
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
23
|
+
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
24
|
+
*
|
|
25
|
+
* @category constructors
|
|
26
|
+
* @since 4.0.0
|
|
18
27
|
*/
|
|
19
28
|
export const run: <R2 = never>(
|
|
20
29
|
options: Migrator.MigratorOptions<R2>
|
|
@@ -67,8 +76,10 @@ export const run: <R2 = never>(
|
|
|
67
76
|
})
|
|
68
77
|
|
|
69
78
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
79
|
+
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
80
|
+
*
|
|
81
|
+
* @category constructors
|
|
82
|
+
* @since 4.0.0
|
|
72
83
|
*/
|
|
73
84
|
export const layer = <R>(
|
|
74
85
|
options: Migrator.MigratorOptions<R>
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @since
|
|
8
|
+
* @since 4.0.0
|
|
9
9
|
*/
|
|
10
10
|
export * as SqliteClient from "./SqliteClient.ts"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @since
|
|
13
|
+
* @since 4.0.0
|
|
14
14
|
*/
|
|
15
15
|
export * as SqliteMigrator from "./SqliteMigrator.ts"
|