@effect/sql-sqlite-bun 4.0.0-beta.9 → 4.0.0-beta.90
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 +55 -31
- 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 +75 -38
- 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,CA4HrE,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);
|
|
@@ -43,31 +64,29 @@ export const make = options => Effect.gen(function* () {
|
|
|
43
64
|
if (options.disableWAL !== true) {
|
|
44
65
|
db.run("PRAGMA journal_mode = WAL;");
|
|
45
66
|
}
|
|
46
|
-
const
|
|
67
|
+
const prepare = (sql, useSafeIntegers) => {
|
|
47
68
|
const statement = db.query(sql);
|
|
48
|
-
const useSafeIntegers = ServiceMap.get(fiber.services, Client.SafeIntegers);
|
|
49
69
|
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
50
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);
|
|
51
75
|
try {
|
|
52
|
-
return Effect.succeed(
|
|
76
|
+
return Effect.succeed(prepare(sql, useSafeIntegers).all(...params) ?? []);
|
|
53
77
|
} catch (cause) {
|
|
54
78
|
return Effect.fail(new SqlError({
|
|
55
|
-
cause,
|
|
56
|
-
message: "Failed to execute statement"
|
|
79
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
57
80
|
}));
|
|
58
81
|
}
|
|
59
82
|
});
|
|
60
83
|
const runValues = (sql, params = []) => Effect.withFiber(fiber => {
|
|
61
|
-
const
|
|
62
|
-
const useSafeIntegers = ServiceMap.get(fiber.services, Client.SafeIntegers);
|
|
63
|
-
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
64
|
-
statement.safeIntegers(useSafeIntegers);
|
|
84
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers);
|
|
65
85
|
try {
|
|
66
|
-
return Effect.succeed(
|
|
86
|
+
return Effect.succeed(prepare(sql, useSafeIntegers).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", "executeValues")
|
|
71
90
|
}));
|
|
72
91
|
}
|
|
73
92
|
});
|
|
@@ -81,6 +100,9 @@ export const make = options => Effect.gen(function* () {
|
|
|
81
100
|
executeValues(sql, params) {
|
|
82
101
|
return runValues(sql, params);
|
|
83
102
|
},
|
|
103
|
+
executeValuesUnprepared(sql, params) {
|
|
104
|
+
return runValues(sql, params);
|
|
105
|
+
},
|
|
84
106
|
executeUnprepared(sql, params, transformRows) {
|
|
85
107
|
return this.execute(sql, params, transformRows);
|
|
86
108
|
},
|
|
@@ -90,15 +112,13 @@ export const make = options => Effect.gen(function* () {
|
|
|
90
112
|
export: Effect.try({
|
|
91
113
|
try: () => db.serialize(),
|
|
92
114
|
catch: cause => new SqlError({
|
|
93
|
-
cause,
|
|
94
|
-
message: "Failed to export database"
|
|
115
|
+
reason: classifyError(cause, "Failed to export database", "export")
|
|
95
116
|
})
|
|
96
117
|
}),
|
|
97
118
|
loadExtension: path => Effect.try({
|
|
98
119
|
try: () => db.loadExtension(path),
|
|
99
120
|
catch: cause => new SqlError({
|
|
100
|
-
cause,
|
|
101
|
-
message: "Failed to load extension"
|
|
121
|
+
reason: classifyError(cause, "Failed to load extension", "loadExtension")
|
|
102
122
|
})
|
|
103
123
|
})
|
|
104
124
|
});
|
|
@@ -108,7 +128,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
108
128
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
109
129
|
const transactionAcquirer = Effect.uninterruptibleMask(restore => {
|
|
110
130
|
const fiber = Fiber.getCurrent();
|
|
111
|
-
const scope =
|
|
131
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope);
|
|
112
132
|
return Effect.as(Effect.tap(restore(semaphore.take(1)), () => Scope.addFinalizer(scope, semaphore.release(1))), connection);
|
|
113
133
|
});
|
|
114
134
|
return Object.assign(yield* Client.make({
|
|
@@ -125,13 +145,17 @@ export const make = options => Effect.gen(function* () {
|
|
|
125
145
|
});
|
|
126
146
|
});
|
|
127
147
|
/**
|
|
148
|
+
* Creates a layer from a `Config`-wrapped Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
149
|
+
*
|
|
128
150
|
* @category layers
|
|
129
|
-
* @since
|
|
151
|
+
* @since 4.0.0
|
|
130
152
|
*/
|
|
131
|
-
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));
|
|
132
154
|
/**
|
|
155
|
+
* Creates a layer from a concrete Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
156
|
+
*
|
|
133
157
|
* @category layers
|
|
134
|
-
* @since
|
|
158
|
+
* @since 4.0.0
|
|
135
159
|
*/
|
|
136
|
-
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));
|
|
137
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","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","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,SAAS,CAACa,kBAAkB,CAACH,OAAO,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AO,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,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.90",
|
|
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.90",
|
|
48
|
+
"effect": "^4.0.0-beta.90"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"effect": "^4.0.0-beta.
|
|
51
|
+
"effect": "^4.0.0-beta.90"
|
|
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
|
|
@@ -100,19 +126,23 @@ export const make = (
|
|
|
100
126
|
db.run("PRAGMA journal_mode = WAL;")
|
|
101
127
|
}
|
|
102
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
|
+
|
|
103
136
|
const run = (
|
|
104
137
|
sql: string,
|
|
105
138
|
params: ReadonlyArray<unknown> = []
|
|
106
139
|
) =>
|
|
107
140
|
Effect.withFiber<Array<any>, SqlError>((fiber) => {
|
|
108
|
-
const
|
|
109
|
-
const useSafeIntegers = ServiceMap.get(fiber.services, Client.SafeIntegers)
|
|
110
|
-
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
111
|
-
statement.safeIntegers(useSafeIntegers)
|
|
141
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers)
|
|
112
142
|
try {
|
|
113
|
-
return Effect.succeed((
|
|
143
|
+
return Effect.succeed((prepare(sql, useSafeIntegers).all(...(params as any)) ?? []) as Array<any>)
|
|
114
144
|
} catch (cause) {
|
|
115
|
-
return Effect.fail(new SqlError({ cause,
|
|
145
|
+
return Effect.fail(new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") }))
|
|
116
146
|
}
|
|
117
147
|
})
|
|
118
148
|
|
|
@@ -121,14 +151,13 @@ export const make = (
|
|
|
121
151
|
params: ReadonlyArray<unknown> = []
|
|
122
152
|
) =>
|
|
123
153
|
Effect.withFiber<Array<any>, SqlError>((fiber) => {
|
|
124
|
-
const
|
|
125
|
-
const useSafeIntegers = ServiceMap.get(fiber.services, Client.SafeIntegers)
|
|
126
|
-
// @ts-ignore bun-types missing safeIntegers method, fixed in https://github.com/oven-sh/bun/pull/26627
|
|
127
|
-
statement.safeIntegers(useSafeIntegers)
|
|
154
|
+
const useSafeIntegers = Context.get(fiber.context, Client.SafeIntegers)
|
|
128
155
|
try {
|
|
129
|
-
return Effect.succeed((
|
|
156
|
+
return Effect.succeed((prepare(sql, useSafeIntegers).values(...(params as any)) ?? []) as Array<any>)
|
|
130
157
|
} catch (cause) {
|
|
131
|
-
return Effect.fail(
|
|
158
|
+
return Effect.fail(
|
|
159
|
+
new SqlError({ reason: classifyError(cause, "Failed to execute statement", "executeValues") })
|
|
160
|
+
)
|
|
132
161
|
}
|
|
133
162
|
})
|
|
134
163
|
|
|
@@ -144,6 +173,9 @@ export const make = (
|
|
|
144
173
|
executeValues(sql, params) {
|
|
145
174
|
return runValues(sql, params)
|
|
146
175
|
},
|
|
176
|
+
executeValuesUnprepared(sql, params) {
|
|
177
|
+
return runValues(sql, params)
|
|
178
|
+
},
|
|
147
179
|
executeUnprepared(sql, params, transformRows) {
|
|
148
180
|
return this.execute(sql, params, transformRows)
|
|
149
181
|
},
|
|
@@ -152,12 +184,13 @@ export const make = (
|
|
|
152
184
|
},
|
|
153
185
|
export: Effect.try({
|
|
154
186
|
try: () => db.serialize(),
|
|
155
|
-
catch: (cause) => new SqlError({ cause,
|
|
187
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to export database", "export") })
|
|
156
188
|
}),
|
|
157
189
|
loadExtension: (path) =>
|
|
158
190
|
Effect.try({
|
|
159
191
|
try: () => db.loadExtension(path),
|
|
160
|
-
catch: (cause) =>
|
|
192
|
+
catch: (cause) =>
|
|
193
|
+
new SqlError({ reason: classifyError(cause, "Failed to load extension", "loadExtension") })
|
|
161
194
|
})
|
|
162
195
|
})
|
|
163
196
|
})
|
|
@@ -168,7 +201,7 @@ export const make = (
|
|
|
168
201
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
|
|
169
202
|
const transactionAcquirer = Effect.uninterruptibleMask((restore) => {
|
|
170
203
|
const fiber = Fiber.getCurrent()!
|
|
171
|
-
const scope =
|
|
204
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope)
|
|
172
205
|
return Effect.as(
|
|
173
206
|
Effect.tap(
|
|
174
207
|
restore(semaphore.take(1)),
|
|
@@ -199,33 +232,37 @@ export const make = (
|
|
|
199
232
|
})
|
|
200
233
|
|
|
201
234
|
/**
|
|
235
|
+
* Creates a layer from a `Config`-wrapped Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
236
|
+
*
|
|
202
237
|
* @category layers
|
|
203
|
-
* @since
|
|
238
|
+
* @since 4.0.0
|
|
204
239
|
*/
|
|
205
240
|
export const layerConfig = (
|
|
206
241
|
config: Config.Wrap<SqliteClientConfig>
|
|
207
242
|
): Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError> =>
|
|
208
|
-
Layer.
|
|
209
|
-
Config.unwrap(config).
|
|
243
|
+
Layer.effectContext(
|
|
244
|
+
Config.unwrap(config).pipe(
|
|
210
245
|
Effect.flatMap(make),
|
|
211
246
|
Effect.map((client) =>
|
|
212
|
-
|
|
213
|
-
|
|
247
|
+
Context.make(SqliteClient, client).pipe(
|
|
248
|
+
Context.add(Client.SqlClient, client)
|
|
214
249
|
)
|
|
215
250
|
)
|
|
216
251
|
)
|
|
217
252
|
).pipe(Layer.provide(Reactivity.layer))
|
|
218
253
|
|
|
219
254
|
/**
|
|
255
|
+
* Creates a layer from a concrete Bun SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
256
|
+
*
|
|
220
257
|
* @category layers
|
|
221
|
-
* @since
|
|
258
|
+
* @since 4.0.0
|
|
222
259
|
*/
|
|
223
260
|
export const layer = (
|
|
224
261
|
config: SqliteClientConfig
|
|
225
262
|
): Layer.Layer<SqliteClient | Client.SqlClient> =>
|
|
226
|
-
Layer.
|
|
263
|
+
Layer.effectContext(
|
|
227
264
|
Effect.map(make(config), (client) =>
|
|
228
|
-
|
|
229
|
-
|
|
265
|
+
Context.make(SqliteClient, client).pipe(
|
|
266
|
+
Context.add(Client.SqlClient, client)
|
|
230
267
|
))
|
|
231
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"
|