@effect/sql-sqlite-bun 4.0.0-beta.1 → 4.0.0-beta.100
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/README.md +1 -1
- package/dist/SqliteClient.d.ts +34 -14
- package/dist/SqliteClient.d.ts.map +1 -1
- package/dist/SqliteClient.js +57 -32
- 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 +7 -8
- package/src/SqliteClient.ts +77 -39
- package/src/SqliteMigrator.ts +17 -6
- package/src/index.ts +3 -3
package/README.md
CHANGED
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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,eAAO,MAAM,IAAI,YACN,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CA4HrE,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,WACd,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,WACR,kBAAkB,KACzB,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,CAML,CAAA"}
|
package/dist/SqliteClient.js
CHANGED
|
@@ -1,33 +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
|
-
import * as
|
|
19
|
+
import * as Semaphore from "effect/Semaphore";
|
|
12
20
|
import * as Stream from "effect/Stream";
|
|
13
21
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
14
22
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
15
|
-
import { SqlError } from "effect/unstable/sql/SqlError";
|
|
23
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError";
|
|
16
24
|
import * as Statement from "effect/unstable/sql/Statement";
|
|
17
25
|
const ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
26
|
+
const classifyError = (cause, message, operation) => classifySqliteError(cause, {
|
|
27
|
+
message,
|
|
28
|
+
operation
|
|
29
|
+
});
|
|
18
30
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
31
|
+
* Runtime type identifier used to mark Bun `SqliteClient` values.
|
|
32
|
+
*
|
|
33
|
+
* @category type IDs
|
|
34
|
+
* @since 4.0.0
|
|
21
35
|
*/
|
|
22
36
|
export const TypeId = "~@effect/sql-sqlite-bun/SqliteClient";
|
|
23
37
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
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
|
|
26
46
|
*/
|
|
27
|
-
export const SqliteClient = /*#__PURE__*/
|
|
47
|
+
export const SqliteClient = /*#__PURE__*/Context.Service("@effect/sql-sqlite-bun/Client");
|
|
28
48
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
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
|
|
31
53
|
*/
|
|
32
54
|
export const make = options => Effect.gen(function* () {
|
|
33
55
|
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
@@ -42,31 +64,29 @@ export const make = options => Effect.gen(function* () {
|
|
|
42
64
|
if (options.disableWAL !== true) {
|
|
43
65
|
db.run("PRAGMA journal_mode = WAL;");
|
|
44
66
|
}
|
|
45
|
-
const
|
|
67
|
+
const prepare = (sql, useSafeIntegers) => {
|
|
46
68
|
const statement = db.query(sql);
|
|
47
|
-
const useSafeIntegers = ServiceMap.get(fiber.services, Client.SafeIntegers);
|
|
48
69
|
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
49
70
|
statement.safeIntegers(useSafeIntegers);
|
|
71
|
+
return statement;
|
|
72
|
+
};
|
|
73
|
+
const run = (sql, params = []) => Effect.withFiber(fiber => {
|
|
74
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers);
|
|
50
75
|
try {
|
|
51
|
-
return Effect.succeed(
|
|
76
|
+
return Effect.succeed(prepare(sql, useSafeIntegers).all(...params) ?? []);
|
|
52
77
|
} catch (cause) {
|
|
53
78
|
return Effect.fail(new SqlError({
|
|
54
|
-
cause,
|
|
55
|
-
message: "Failed to execute statement"
|
|
79
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
56
80
|
}));
|
|
57
81
|
}
|
|
58
82
|
});
|
|
59
83
|
const runValues = (sql, params = []) => Effect.withFiber(fiber => {
|
|
60
|
-
const
|
|
61
|
-
const useSafeIntegers = ServiceMap.get(fiber.services, Client.SafeIntegers);
|
|
62
|
-
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
63
|
-
statement.safeIntegers(useSafeIntegers);
|
|
84
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers);
|
|
64
85
|
try {
|
|
65
|
-
return Effect.succeed(
|
|
86
|
+
return Effect.succeed(prepare(sql, useSafeIntegers).values(...params) ?? []);
|
|
66
87
|
} catch (cause) {
|
|
67
88
|
return Effect.fail(new SqlError({
|
|
68
|
-
cause,
|
|
69
|
-
message: "Failed to execute statement"
|
|
89
|
+
reason: classifyError(cause, "Failed to execute statement", "executeValues")
|
|
70
90
|
}));
|
|
71
91
|
}
|
|
72
92
|
});
|
|
@@ -80,6 +100,9 @@ export const make = options => Effect.gen(function* () {
|
|
|
80
100
|
executeValues(sql, params) {
|
|
81
101
|
return runValues(sql, params);
|
|
82
102
|
},
|
|
103
|
+
executeValuesUnprepared(sql, params) {
|
|
104
|
+
return runValues(sql, params);
|
|
105
|
+
},
|
|
83
106
|
executeUnprepared(sql, params, transformRows) {
|
|
84
107
|
return this.execute(sql, params, transformRows);
|
|
85
108
|
},
|
|
@@ -89,25 +112,23 @@ export const make = options => Effect.gen(function* () {
|
|
|
89
112
|
export: Effect.try({
|
|
90
113
|
try: () => db.serialize(),
|
|
91
114
|
catch: cause => new SqlError({
|
|
92
|
-
cause,
|
|
93
|
-
message: "Failed to export database"
|
|
115
|
+
reason: classifyError(cause, "Failed to export database", "export")
|
|
94
116
|
})
|
|
95
117
|
}),
|
|
96
118
|
loadExtension: path => Effect.try({
|
|
97
119
|
try: () => db.loadExtension(path),
|
|
98
120
|
catch: cause => new SqlError({
|
|
99
|
-
cause,
|
|
100
|
-
message: "Failed to load extension"
|
|
121
|
+
reason: classifyError(cause, "Failed to load extension", "loadExtension")
|
|
101
122
|
})
|
|
102
123
|
})
|
|
103
124
|
});
|
|
104
125
|
});
|
|
105
|
-
const semaphore = yield*
|
|
126
|
+
const semaphore = yield* Semaphore.make(1);
|
|
106
127
|
const connection = yield* makeConnection;
|
|
107
128
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
108
129
|
const transactionAcquirer = Effect.uninterruptibleMask(restore => {
|
|
109
130
|
const fiber = Fiber.getCurrent();
|
|
110
|
-
const scope =
|
|
131
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope);
|
|
111
132
|
return Effect.as(Effect.tap(restore(semaphore.take(1)), () => Scope.addFinalizer(scope, semaphore.release(1))), connection);
|
|
112
133
|
});
|
|
113
134
|
return Object.assign(yield* Client.make({
|
|
@@ -124,13 +145,17 @@ export const make = options => Effect.gen(function* () {
|
|
|
124
145
|
});
|
|
125
146
|
});
|
|
126
147
|
/**
|
|
148
|
+
* Creates a layer from a `Config`-wrapped Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
149
|
+
*
|
|
127
150
|
* @category layers
|
|
128
|
-
* @since
|
|
151
|
+
* @since 4.0.0
|
|
129
152
|
*/
|
|
130
|
-
export const layerConfig = config => Layer.
|
|
153
|
+
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));
|
|
131
154
|
/**
|
|
155
|
+
* Creates a layer from a concrete Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
156
|
+
*
|
|
132
157
|
* @category layers
|
|
133
|
-
* @since
|
|
158
|
+
* @since 4.0.0
|
|
134
159
|
*/
|
|
135
|
-
export const layer = config => Layer.
|
|
160
|
+
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));
|
|
136
161
|
//# 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","
|
|
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","prepare","sql","useSafeIntegers","statement","query","safeIntegers","params","withFiber","fiber","get","context","SafeIntegers","succeed","all","fail","reason","runValues","values","execute","map","executeRaw","executeValues","executeValuesUnprepared","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,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,uCAAuC;AACnE,OAAO,KAAKC,MAAM,MAAM,+BAA+B;AAEvD,SAASC,mBAAmB,EAAEC,QAAQ,QAAQ,8BAA8B;AAC5E,OAAO,KAAKC,SAAS,MAAM,+BAA+B;AAE1D,MAAMC,mBAAmB,GAAG,gBAAgB;AAE5C,MAAMC,aAAa,GAAGA,CAACC,KAAc,EAAEC,OAAe,EAAEC,SAAiB,KACvEP,mBAAmB,CAACK,KAAK,EAAE;EAAEC,OAAO;EAAEC;AAAS,CAAE,CAAC;AAEpD;;;;;;AAMA,OAAO,MAAMC,MAAM,GAAW,sCAAsC;AA0BpE;;;;;;;;;;AAUA,OAAO,MAAMC,YAAY,gBAAGnB,OAAO,CAACoB,OAAO,CAAe,+BAA+B,CAAC;AA0B1F;;;;;;AAMA,OAAO,MAAMC,IAAI,GACfC,OAA2B,IAE3BrB,MAAM,CAACsB,GAAG,CAAC,aAAS;EAClB,MAAMC,QAAQ,GAAGZ,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,IAAI,CACxBpG,MAAM,CAAC+F,OAAO,CAAC3E,IAAI,CAAC,EACpBpB,MAAM,CAAC6D,GAAG,CAAEwC,MAAM,IAChBtG,OAAO,CAACqB,IAAI,CAACF,YAAY,EAAEmF,MAAM,CAAC,CAACD,IAAI,CACrCrG,OAAO,CAACuG,GAAG,CAAC9F,MAAM,CAAC+F,SAAS,EAAEF,MAAM,CAAC,CACtC,CACF,CACF,CACF,CAACD,IAAI,CAACjG,KAAK,CAACqG,OAAO,CAACjG,UAAU,CAACkG,KAAK,CAAC,CAAC;AAEzC;;;;;;AAMA,OAAO,MAAMA,KAAK,GAChBX,MAA0B,IAE1B3F,KAAK,CAAC+F,aAAa,CACjBlG,MAAM,CAAC6D,GAAG,CAACzC,IAAI,CAAC0E,MAAM,CAAC,EAAGO,MAAM,IAC9BtG,OAAO,CAACqB,IAAI,CAACF,YAAY,EAAEmF,MAAM,CAAC,CAACD,IAAI,CACrCrG,OAAO,CAACuG,GAAG,CAAC9F,MAAM,CAAC+F,SAAS,EAAEF,MAAM,CAAC,CACtC,CAAC,CACL,CAACD,IAAI,CAACjG,KAAK,CAACqG,OAAO,CAACjG,UAAU,CAACkG,KAAK,CAAC,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,WACZ,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,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-sqlite-bun",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.100",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A SQLite toolkit for Effect",
|
|
7
7
|
"homepage": "https://effect.website",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/Effect-TS/effect
|
|
10
|
+
"url": "https://github.com/Effect-TS/effect.git",
|
|
11
11
|
"directory": "packages/sql/sqlite-bun"
|
|
12
12
|
},
|
|
13
13
|
"bugs": {
|
|
14
|
-
"url": "https://github.com/Effect-TS/effect
|
|
14
|
+
"url": "https://github.com/Effect-TS/effect/issues"
|
|
15
15
|
},
|
|
16
16
|
"tags": [
|
|
17
17
|
"typescript",
|
|
@@ -43,17 +43,16 @@
|
|
|
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.14",
|
|
47
|
+
"@effect/platform-bun": "^4.0.0-beta.100",
|
|
48
|
+
"effect": "^4.0.0-beta.100"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"effect": "^4.0.0-beta.
|
|
51
|
+
"effect": "^4.0.0-beta.100"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"codegen": "effect-utils codegen",
|
|
55
55
|
"build": "tsc -b tsconfig.json && pnpm babel",
|
|
56
|
-
"build:tsgo": "tsgo -b tsconfig.json && pnpm babel",
|
|
57
56
|
"babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
|
|
58
57
|
"check": "tsc -b tsconfig.json",
|
|
59
58
|
"test": "vitest",
|
package/src/SqliteClient.ts
CHANGED
|
@@ -1,38 +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
|
-
import * as
|
|
19
|
+
import * as Semaphore from "effect/Semaphore"
|
|
12
20
|
import * as Stream from "effect/Stream"
|
|
13
21
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity"
|
|
14
22
|
import * as Client from "effect/unstable/sql/SqlClient"
|
|
15
23
|
import type { Connection } from "effect/unstable/sql/SqlConnection"
|
|
16
|
-
import { SqlError } from "effect/unstable/sql/SqlError"
|
|
24
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
|
|
17
25
|
import * as Statement from "effect/unstable/sql/Statement"
|
|
18
26
|
|
|
19
27
|
const ATTR_DB_SYSTEM_NAME = "db.system.name"
|
|
20
28
|
|
|
29
|
+
const classifyError = (cause: unknown, message: string, operation: string) =>
|
|
30
|
+
classifySqliteError(cause, { message, operation })
|
|
31
|
+
|
|
21
32
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
33
|
+
* Runtime type identifier used to mark Bun `SqliteClient` values.
|
|
34
|
+
*
|
|
35
|
+
* @category type IDs
|
|
36
|
+
* @since 4.0.0
|
|
24
37
|
*/
|
|
25
38
|
export const TypeId: TypeId = "~@effect/sql-sqlite-bun/SqliteClient"
|
|
26
39
|
|
|
27
40
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
41
|
+
* Type-level identifier used to mark Bun `SqliteClient` values.
|
|
42
|
+
*
|
|
43
|
+
* @category type IDs
|
|
44
|
+
* @since 4.0.0
|
|
30
45
|
*/
|
|
31
46
|
export type TypeId = "~@effect/sql-sqlite-bun/SqliteClient"
|
|
32
47
|
|
|
33
48
|
/**
|
|
49
|
+
* Bun SQLite client service, extending `SqlClient` with database export and extension loading helpers. `updateValues` is not supported.
|
|
50
|
+
*
|
|
34
51
|
* @category models
|
|
35
|
-
* @since
|
|
52
|
+
* @since 4.0.0
|
|
36
53
|
*/
|
|
37
54
|
export interface SqliteClient extends Client.SqlClient {
|
|
38
55
|
readonly [TypeId]: TypeId
|
|
@@ -45,14 +62,22 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
45
62
|
}
|
|
46
63
|
|
|
47
64
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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
|
|
50
73
|
*/
|
|
51
|
-
export const SqliteClient =
|
|
74
|
+
export const SqliteClient = Context.Service<SqliteClient>("@effect/sql-sqlite-bun/Client")
|
|
52
75
|
|
|
53
76
|
/**
|
|
77
|
+
* Configuration for a Bun SQLite client, including filename, open mode flags, WAL behavior, span attributes, and query/result name transforms.
|
|
78
|
+
*
|
|
54
79
|
* @category models
|
|
55
|
-
* @since
|
|
80
|
+
* @since 4.0.0
|
|
56
81
|
*/
|
|
57
82
|
export interface SqliteClientConfig {
|
|
58
83
|
readonly filename: string
|
|
@@ -73,8 +98,10 @@ interface SqliteConnection extends Connection {
|
|
|
73
98
|
}
|
|
74
99
|
|
|
75
100
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
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
|
|
78
105
|
*/
|
|
79
106
|
export const make = (
|
|
80
107
|
options: SqliteClientConfig
|
|
@@ -99,19 +126,23 @@ export const make = (
|
|
|
99
126
|
db.run("PRAGMA journal_mode = WAL;")
|
|
100
127
|
}
|
|
101
128
|
|
|
129
|
+
const prepare = (sql: string, useSafeIntegers: boolean) => {
|
|
130
|
+
const statement = db.query(sql)
|
|
131
|
+
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
132
|
+
statement.safeIntegers(useSafeIntegers)
|
|
133
|
+
return statement
|
|
134
|
+
}
|
|
135
|
+
|
|
102
136
|
const run = (
|
|
103
137
|
sql: string,
|
|
104
138
|
params: ReadonlyArray<unknown> = []
|
|
105
139
|
) =>
|
|
106
140
|
Effect.withFiber<Array<any>, SqlError>((fiber) => {
|
|
107
|
-
const
|
|
108
|
-
const useSafeIntegers = ServiceMap.get(fiber.services, Client.SafeIntegers)
|
|
109
|
-
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
110
|
-
statement.safeIntegers(useSafeIntegers)
|
|
141
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers)
|
|
111
142
|
try {
|
|
112
|
-
return Effect.succeed((
|
|
143
|
+
return Effect.succeed((prepare(sql, useSafeIntegers).all(...(params as any)) ?? []) as Array<any>)
|
|
113
144
|
} catch (cause) {
|
|
114
|
-
return Effect.fail(new SqlError({ cause,
|
|
145
|
+
return Effect.fail(new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") }))
|
|
115
146
|
}
|
|
116
147
|
})
|
|
117
148
|
|
|
@@ -120,14 +151,13 @@ export const make = (
|
|
|
120
151
|
params: ReadonlyArray<unknown> = []
|
|
121
152
|
) =>
|
|
122
153
|
Effect.withFiber<Array<any>, SqlError>((fiber) => {
|
|
123
|
-
const
|
|
124
|
-
const useSafeIntegers = ServiceMap.get(fiber.services, Client.SafeIntegers)
|
|
125
|
-
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
126
|
-
statement.safeIntegers(useSafeIntegers)
|
|
154
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers)
|
|
127
155
|
try {
|
|
128
|
-
return Effect.succeed((
|
|
156
|
+
return Effect.succeed((prepare(sql, useSafeIntegers).values(...(params as any)) ?? []) as Array<any>)
|
|
129
157
|
} catch (cause) {
|
|
130
|
-
return Effect.fail(
|
|
158
|
+
return Effect.fail(
|
|
159
|
+
new SqlError({ reason: classifyError(cause, "Failed to execute statement", "executeValues") })
|
|
160
|
+
)
|
|
131
161
|
}
|
|
132
162
|
})
|
|
133
163
|
|
|
@@ -143,6 +173,9 @@ export const make = (
|
|
|
143
173
|
executeValues(sql, params) {
|
|
144
174
|
return runValues(sql, params)
|
|
145
175
|
},
|
|
176
|
+
executeValuesUnprepared(sql, params) {
|
|
177
|
+
return runValues(sql, params)
|
|
178
|
+
},
|
|
146
179
|
executeUnprepared(sql, params, transformRows) {
|
|
147
180
|
return this.execute(sql, params, transformRows)
|
|
148
181
|
},
|
|
@@ -151,23 +184,24 @@ export const make = (
|
|
|
151
184
|
},
|
|
152
185
|
export: Effect.try({
|
|
153
186
|
try: () => db.serialize(),
|
|
154
|
-
catch: (cause) => new SqlError({ cause,
|
|
187
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to export database", "export") })
|
|
155
188
|
}),
|
|
156
189
|
loadExtension: (path) =>
|
|
157
190
|
Effect.try({
|
|
158
191
|
try: () => db.loadExtension(path),
|
|
159
|
-
catch: (cause) =>
|
|
192
|
+
catch: (cause) =>
|
|
193
|
+
new SqlError({ reason: classifyError(cause, "Failed to load extension", "loadExtension") })
|
|
160
194
|
})
|
|
161
195
|
})
|
|
162
196
|
})
|
|
163
197
|
|
|
164
|
-
const semaphore = yield*
|
|
198
|
+
const semaphore = yield* Semaphore.make(1)
|
|
165
199
|
const connection = yield* makeConnection
|
|
166
200
|
|
|
167
201
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
|
|
168
202
|
const transactionAcquirer = Effect.uninterruptibleMask((restore) => {
|
|
169
203
|
const fiber = Fiber.getCurrent()!
|
|
170
|
-
const scope =
|
|
204
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope)
|
|
171
205
|
return Effect.as(
|
|
172
206
|
Effect.tap(
|
|
173
207
|
restore(semaphore.take(1)),
|
|
@@ -198,33 +232,37 @@ export const make = (
|
|
|
198
232
|
})
|
|
199
233
|
|
|
200
234
|
/**
|
|
235
|
+
* Creates a layer from a `Config`-wrapped Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
236
|
+
*
|
|
201
237
|
* @category layers
|
|
202
|
-
* @since
|
|
238
|
+
* @since 4.0.0
|
|
203
239
|
*/
|
|
204
240
|
export const layerConfig = (
|
|
205
241
|
config: Config.Wrap<SqliteClientConfig>
|
|
206
242
|
): Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError> =>
|
|
207
|
-
Layer.
|
|
208
|
-
Config.unwrap(config).
|
|
243
|
+
Layer.effectContext(
|
|
244
|
+
Config.unwrap(config).pipe(
|
|
209
245
|
Effect.flatMap(make),
|
|
210
246
|
Effect.map((client) =>
|
|
211
|
-
|
|
212
|
-
|
|
247
|
+
Context.make(SqliteClient, client).pipe(
|
|
248
|
+
Context.add(Client.SqlClient, client)
|
|
213
249
|
)
|
|
214
250
|
)
|
|
215
251
|
)
|
|
216
252
|
).pipe(Layer.provide(Reactivity.layer))
|
|
217
253
|
|
|
218
254
|
/**
|
|
255
|
+
* Creates a layer from a concrete Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
256
|
+
*
|
|
219
257
|
* @category layers
|
|
220
|
-
* @since
|
|
258
|
+
* @since 4.0.0
|
|
221
259
|
*/
|
|
222
260
|
export const layer = (
|
|
223
261
|
config: SqliteClientConfig
|
|
224
262
|
): Layer.Layer<SqliteClient | Client.SqlClient> =>
|
|
225
|
-
Layer.
|
|
263
|
+
Layer.effectContext(
|
|
226
264
|
Effect.map(make(config), (client) =>
|
|
227
|
-
|
|
228
|
-
|
|
265
|
+
Context.make(SqliteClient, client).pipe(
|
|
266
|
+
Context.add(Client.SqlClient, client)
|
|
229
267
|
))
|
|
230
268
|
).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"
|