@effect/sql-sqlite-node 4.0.0-beta.9 → 4.0.0-beta.91
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 +33 -15
- package/dist/SqliteClient.d.ts.map +1 -1
- package/dist/SqliteClient.js +61 -28
- 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 +84 -32
- package/src/SqliteMigrator.ts +17 -6
- package/src/index.ts +3 -3
package/dist/SqliteClient.d.ts
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
import * as Config from "effect/Config";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
2
3
|
import * as Duration from "effect/Duration";
|
|
3
4
|
import * as Effect from "effect/Effect";
|
|
4
5
|
import * as Layer from "effect/Layer";
|
|
5
6
|
import * as Scope from "effect/Scope";
|
|
6
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
7
7
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
8
8
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
9
9
|
import { SqlError } from "effect/unstable/sql/SqlError";
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Runtime type identifier used to mark Node `SqliteClient` values.
|
|
12
|
+
*
|
|
13
|
+
* @category type IDs
|
|
14
|
+
* @since 4.0.0
|
|
13
15
|
*/
|
|
14
16
|
export declare const TypeId: TypeId;
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
+
* Type-level identifier used to mark Node `SqliteClient` values.
|
|
19
|
+
*
|
|
20
|
+
* @category type IDs
|
|
21
|
+
* @since 4.0.0
|
|
18
22
|
*/
|
|
19
23
|
export type TypeId = "~@effect/sql-sqlite-node/SqliteClient";
|
|
20
24
|
/**
|
|
25
|
+
* Node SQLite client service, extending `SqlClient` with database export, backup, and extension loading helpers. `updateValues` is not supported.
|
|
26
|
+
*
|
|
21
27
|
* @category models
|
|
22
|
-
* @since
|
|
28
|
+
* @since 4.0.0
|
|
23
29
|
*/
|
|
24
30
|
export interface SqliteClient extends Client.SqlClient {
|
|
25
31
|
readonly [TypeId]: TypeId;
|
|
@@ -31,21 +37,27 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
31
37
|
readonly updateValues: never;
|
|
32
38
|
}
|
|
33
39
|
/**
|
|
40
|
+
* Metadata returned from a Node SQLite backup operation, reporting total and remaining page counts.
|
|
41
|
+
*
|
|
34
42
|
* @category models
|
|
35
|
-
* @since
|
|
43
|
+
* @since 4.0.0
|
|
36
44
|
*/
|
|
37
45
|
export interface BackupMetadata {
|
|
38
46
|
readonly totalPages: number;
|
|
39
47
|
readonly remainingPages: number;
|
|
40
48
|
}
|
|
41
49
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
50
|
+
* Service tag for the node SQLite client implementation.
|
|
51
|
+
*
|
|
52
|
+
* @category services
|
|
53
|
+
* @since 4.0.0
|
|
44
54
|
*/
|
|
45
|
-
export declare const SqliteClient:
|
|
55
|
+
export declare const SqliteClient: Context.Service<SqliteClient, SqliteClient>;
|
|
46
56
|
/**
|
|
57
|
+
* Configuration for a node SQLite client backed by `better-sqlite3`, including the database filename, read-only mode, statement cache settings, WAL behavior, span attributes, and query/result name transforms.
|
|
58
|
+
*
|
|
47
59
|
* @category models
|
|
48
|
-
* @since
|
|
60
|
+
* @since 4.0.0
|
|
49
61
|
*/
|
|
50
62
|
export interface SqliteClientConfig {
|
|
51
63
|
readonly filename: string;
|
|
@@ -58,18 +70,24 @@ export interface SqliteClientConfig {
|
|
|
58
70
|
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
59
71
|
}
|
|
60
72
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
73
|
+
* Creates a scoped node SQLite client from the supplied configuration, using a single serialized connection with WAL enabled by default and exposing SQLite-specific `export`, `backup`, and `loadExtension` operations.
|
|
74
|
+
*
|
|
75
|
+
* @category constructors
|
|
76
|
+
* @since 4.0.0
|
|
63
77
|
*/
|
|
64
78
|
export declare const make: (options: SqliteClientConfig) => Effect.Effect<SqliteClient, never, Scope.Scope | Reactivity.Reactivity>;
|
|
65
79
|
/**
|
|
80
|
+
* Builds a layer from an Effect `Config` value, providing both the node `SqliteClient` service and the generic `SqlClient` service.
|
|
81
|
+
*
|
|
66
82
|
* @category layers
|
|
67
|
-
* @since
|
|
83
|
+
* @since 4.0.0
|
|
68
84
|
*/
|
|
69
85
|
export declare const layerConfig: (config: Config.Wrap<SqliteClientConfig>) => Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError>;
|
|
70
86
|
/**
|
|
87
|
+
* Builds a layer from a node SQLite client configuration, providing both `SqliteClient` and the generic `SqlClient` service.
|
|
88
|
+
*
|
|
71
89
|
* @category layers
|
|
72
|
-
* @since
|
|
90
|
+
* @since 4.0.0
|
|
73
91
|
*/
|
|
74
92
|
export declare const layer: (config: SqliteClientConfig) => Layer.Layer<SqliteClient | Client.SqlClient>;
|
|
75
93
|
//# 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":"AAaA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,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BAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9C,QAAQ,CAAC,eAAe,CAAC,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAA;IACrD,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACzC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IAE7D,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;IACrE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;CACrE;AAQD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GACf,SAAS,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CAmLrE,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,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Connects Effect SQL to SQLite on Node.js using `better-sqlite3`.
|
|
3
|
+
*
|
|
4
|
+
* This module opens a SQLite database and exposes it as both `SqliteClient` and
|
|
5
|
+
* the generic Effect SQL client. It serializes access through one connection,
|
|
6
|
+
* caches prepared statements, enables WAL mode unless disabled, and supports
|
|
7
|
+
* database export, backup, and extension loading. Streaming queries and
|
|
8
|
+
* `updateValues` are not supported by this driver.
|
|
9
|
+
*
|
|
10
|
+
* @since 4.0.0
|
|
3
11
|
*/
|
|
4
12
|
import Sqlite from "better-sqlite3";
|
|
5
13
|
import * as Cache from "effect/Cache";
|
|
6
14
|
import * as Config from "effect/Config";
|
|
15
|
+
import * as Context from "effect/Context";
|
|
7
16
|
import * as Duration from "effect/Duration";
|
|
8
17
|
import * as Effect from "effect/Effect";
|
|
9
18
|
import * as Fiber from "effect/Fiber";
|
|
@@ -11,26 +20,35 @@ import { identity } from "effect/Function";
|
|
|
11
20
|
import * as Layer from "effect/Layer";
|
|
12
21
|
import * as Scope from "effect/Scope";
|
|
13
22
|
import * as Semaphore from "effect/Semaphore";
|
|
14
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
15
23
|
import * as Stream from "effect/Stream";
|
|
16
24
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
17
25
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
18
|
-
import { SqlError } from "effect/unstable/sql/SqlError";
|
|
26
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError";
|
|
19
27
|
import * as Statement from "effect/unstable/sql/Statement";
|
|
20
28
|
const ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
29
|
+
const classifyError = (cause, message, operation) => classifySqliteError(cause, {
|
|
30
|
+
message,
|
|
31
|
+
operation
|
|
32
|
+
});
|
|
21
33
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
34
|
+
* Runtime type identifier used to mark Node `SqliteClient` values.
|
|
35
|
+
*
|
|
36
|
+
* @category type IDs
|
|
37
|
+
* @since 4.0.0
|
|
24
38
|
*/
|
|
25
39
|
export const TypeId = "~@effect/sql-sqlite-node/SqliteClient";
|
|
26
40
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
41
|
+
* Service tag for the node SQLite client implementation.
|
|
42
|
+
*
|
|
43
|
+
* @category services
|
|
44
|
+
* @since 4.0.0
|
|
29
45
|
*/
|
|
30
|
-
export const SqliteClient = /*#__PURE__*/
|
|
46
|
+
export const SqliteClient = /*#__PURE__*/Context.Service("@effect/sql-sqlite-node/SqliteClient");
|
|
31
47
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
48
|
+
* Creates a scoped node SQLite client from the supplied configuration, using a single serialized connection with WAL enabled by default and exposing SQLite-specific `export`, `backup`, and `loadExtension` operations.
|
|
49
|
+
*
|
|
50
|
+
* @category constructors
|
|
51
|
+
* @since 4.0.0
|
|
34
52
|
*/
|
|
35
53
|
export const make = options => Effect.gen(function* () {
|
|
36
54
|
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
@@ -50,13 +68,12 @@ export const make = options => Effect.gen(function* () {
|
|
|
50
68
|
lookup: sql => Effect.try({
|
|
51
69
|
try: () => db.prepare(sql),
|
|
52
70
|
catch: cause => new SqlError({
|
|
53
|
-
cause,
|
|
54
|
-
message: "Failed to prepare statement "
|
|
71
|
+
reason: classifyError(cause, "Failed to prepare statement", "prepare")
|
|
55
72
|
})
|
|
56
73
|
})
|
|
57
74
|
});
|
|
58
75
|
const runStatement = (statement, params, raw) => Effect.withFiber(fiber => {
|
|
59
|
-
if (
|
|
76
|
+
if (Context.get(fiber.context, Client.SafeIntegers)) {
|
|
60
77
|
statement.safeIntegers(true);
|
|
61
78
|
}
|
|
62
79
|
try {
|
|
@@ -67,8 +84,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
67
84
|
return Effect.succeed(raw ? result : []);
|
|
68
85
|
} catch (cause) {
|
|
69
86
|
return Effect.fail(new SqlError({
|
|
70
|
-
cause,
|
|
71
|
-
message: "Failed to execute statement"
|
|
87
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
72
88
|
}));
|
|
73
89
|
}
|
|
74
90
|
});
|
|
@@ -83,10 +99,23 @@ export const make = options => Effect.gen(function* () {
|
|
|
83
99
|
return [];
|
|
84
100
|
},
|
|
85
101
|
catch: cause => new SqlError({
|
|
86
|
-
cause,
|
|
87
|
-
message: "Failed to execute statement"
|
|
102
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
88
103
|
})
|
|
89
104
|
}), statement => Effect.sync(() => statement.reader && statement.raw(false)));
|
|
105
|
+
const runValuesUnprepared = (sql, params) => Effect.try({
|
|
106
|
+
try: () => {
|
|
107
|
+
const statement = db.prepare(sql);
|
|
108
|
+
if (statement.reader) {
|
|
109
|
+
statement.raw(true);
|
|
110
|
+
return statement.all(...params);
|
|
111
|
+
}
|
|
112
|
+
statement.run(...params);
|
|
113
|
+
return [];
|
|
114
|
+
},
|
|
115
|
+
catch: cause => new SqlError({
|
|
116
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
117
|
+
})
|
|
118
|
+
});
|
|
90
119
|
return identity({
|
|
91
120
|
execute(sql, params, transformRows) {
|
|
92
121
|
return transformRows ? Effect.map(run(sql, params), transformRows) : run(sql, params);
|
|
@@ -97,6 +126,9 @@ export const make = options => Effect.gen(function* () {
|
|
|
97
126
|
executeValues(sql, params) {
|
|
98
127
|
return runValues(sql, params);
|
|
99
128
|
},
|
|
129
|
+
executeValuesUnprepared(sql, params) {
|
|
130
|
+
return runValuesUnprepared(sql, params);
|
|
131
|
+
},
|
|
100
132
|
executeUnprepared(sql, params, transformRows) {
|
|
101
133
|
const effect = runStatement(db.prepare(sql), params ?? [], false);
|
|
102
134
|
return transformRows ? Effect.map(effect, transformRows) : effect;
|
|
@@ -107,16 +139,14 @@ export const make = options => Effect.gen(function* () {
|
|
|
107
139
|
export: Effect.try({
|
|
108
140
|
try: () => db.serialize(),
|
|
109
141
|
catch: cause => new SqlError({
|
|
110
|
-
cause,
|
|
111
|
-
message: "Failed to export database"
|
|
142
|
+
reason: classifyError(cause, "Failed to export database", "export")
|
|
112
143
|
})
|
|
113
144
|
}),
|
|
114
145
|
backup(destination) {
|
|
115
146
|
return Effect.tryPromise({
|
|
116
147
|
try: () => db.backup(destination),
|
|
117
148
|
catch: cause => new SqlError({
|
|
118
|
-
cause,
|
|
119
|
-
message: "Failed to backup database"
|
|
149
|
+
reason: classifyError(cause, "Failed to backup database", "backup")
|
|
120
150
|
})
|
|
121
151
|
});
|
|
122
152
|
},
|
|
@@ -124,8 +154,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
124
154
|
return Effect.try({
|
|
125
155
|
try: () => db.loadExtension(path),
|
|
126
156
|
catch: cause => new SqlError({
|
|
127
|
-
cause,
|
|
128
|
-
message: "Failed to load extension"
|
|
157
|
+
reason: classifyError(cause, "Failed to load extension", "loadExtension")
|
|
129
158
|
})
|
|
130
159
|
});
|
|
131
160
|
}
|
|
@@ -136,7 +165,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
136
165
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
137
166
|
const transactionAcquirer = Effect.uninterruptibleMask(restore => {
|
|
138
167
|
const fiber = Fiber.getCurrent();
|
|
139
|
-
const scope =
|
|
168
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope);
|
|
140
169
|
return Effect.as(Effect.tap(restore(semaphore.take(1)), () => Scope.addFinalizer(scope, semaphore.release(1))), connection);
|
|
141
170
|
});
|
|
142
171
|
return Object.assign(yield* Client.make({
|
|
@@ -154,13 +183,17 @@ export const make = options => Effect.gen(function* () {
|
|
|
154
183
|
});
|
|
155
184
|
});
|
|
156
185
|
/**
|
|
186
|
+
* Builds a layer from an Effect `Config` value, providing both the node `SqliteClient` service and the generic `SqlClient` service.
|
|
187
|
+
*
|
|
157
188
|
* @category layers
|
|
158
|
-
* @since
|
|
189
|
+
* @since 4.0.0
|
|
159
190
|
*/
|
|
160
|
-
export const layerConfig = config => Layer.
|
|
191
|
+
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));
|
|
161
192
|
/**
|
|
193
|
+
* Builds a layer from a node SQLite client configuration, providing both `SqliteClient` and the generic `SqlClient` service.
|
|
194
|
+
*
|
|
162
195
|
* @category layers
|
|
163
|
-
* @since
|
|
196
|
+
* @since 4.0.0
|
|
164
197
|
*/
|
|
165
|
-
export const layer = config => Layer.
|
|
198
|
+
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));
|
|
166
199
|
//# sourceMappingURL=SqliteClient.js.map
|
package/dist/SqliteClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteClient.js","names":["Sqlite","Cache","Config","Duration","Effect","Fiber","identity","Layer","Scope","Semaphore","
|
|
1
|
+
{"version":3,"file":"SqliteClient.js","names":["Sqlite","Cache","Config","Context","Duration","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","scope","db","filename","readonly","addFinalizer","sync","close","disableWAL","pragma","prepareCache","capacity","prepareCacheSize","timeToLive","prepareCacheTTL","minutes","lookup","sql","try","prepare","catch","reason","runStatement","statement","params","raw","withFiber","fiber","get","context","SafeIntegers","safeIntegers","reader","succeed","all","result","run","fail","flatMap","s","runValues","acquireUseRelease","runValuesUnprepared","execute","map","executeRaw","executeValues","executeValuesUnprepared","executeUnprepared","effect","executeStream","_sql","_params","die","export","serialize","backup","destination","tryPromise","loadExtension","path","semaphore","connection","acquirer","withPermits","transactionAcquirer","uninterruptibleMask","restore","getCurrent","getUnsafe","as","tap","take","release","Object","assign","spanAttributes","entries","config","_","layerConfig","effectContext","unwrap","pipe","client","add","SqlClient","provide","layer"],"sources":["../src/Sqlite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AEiG,MAAM,CAAC,CAACD,IAAI,CACrCpH,OAAO,CAACsH,GAAG,CAAC5G,MAAM,CAAC6G,SAAS,EAAEF,MAAM,CAAC,CACtC,CAAC,CACL,CAACD,IAAI,CAAC/G,KAAK,CAACmH,OAAO,CAAC/G,UAAU,CAACgH,KAAK,CAAC,CAAC","ignoreList":[]}
|
package/dist/SqliteMigrator.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Runs database migrations for Node.js 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 Node-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 for a SQLite database using the shared `Migrator` implementation and the current `SqlClient`.
|
|
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 SQLite migrations during layer construction and provides no services.
|
|
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, Migrator.MigrationError | SqlError, 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,CAAC,cAAc,GAAG,QAAQ,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 for a SQLite database using the shared `Migrator` implementation and the current `SqlClient`.
|
|
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 SQLite migrations during layer construction and provides no services.
|
|
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-node",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.91",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A SQLite toolkit for Effect",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/better-sqlite3": "^7.6.13",
|
|
47
|
-
"@effect/platform-node": "^4.0.0-beta.
|
|
48
|
-
"effect": "^4.0.0-beta.
|
|
47
|
+
"@effect/platform-node": "^4.0.0-beta.91",
|
|
48
|
+
"effect": "^4.0.0-beta.91"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"effect": "^4.0.0-beta.
|
|
51
|
+
"effect": "^4.0.0-beta.91"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"better-sqlite3": "^12.
|
|
54
|
+
"better-sqlite3": "^12.9.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"codegen": "effect-utils codegen",
|
package/src/SqliteClient.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Connects Effect SQL to SQLite on Node.js using `better-sqlite3`.
|
|
3
|
+
*
|
|
4
|
+
* This module opens a SQLite database and exposes it as both `SqliteClient` and
|
|
5
|
+
* the generic Effect SQL client. It serializes access through one connection,
|
|
6
|
+
* caches prepared statements, enables WAL mode unless disabled, and supports
|
|
7
|
+
* database export, backup, and extension loading. Streaming queries and
|
|
8
|
+
* `updateValues` are not supported by this driver.
|
|
9
|
+
*
|
|
10
|
+
* @since 4.0.0
|
|
3
11
|
*/
|
|
4
12
|
import Sqlite from "better-sqlite3"
|
|
5
13
|
import * as Cache from "effect/Cache"
|
|
6
14
|
import * as Config from "effect/Config"
|
|
15
|
+
import * as Context from "effect/Context"
|
|
7
16
|
import * as Duration from "effect/Duration"
|
|
8
17
|
import * as Effect from "effect/Effect"
|
|
9
18
|
import * as Fiber from "effect/Fiber"
|
|
@@ -11,31 +20,39 @@ import { identity } from "effect/Function"
|
|
|
11
20
|
import * as Layer from "effect/Layer"
|
|
12
21
|
import * as Scope from "effect/Scope"
|
|
13
22
|
import * as Semaphore from "effect/Semaphore"
|
|
14
|
-
import * as ServiceMap from "effect/ServiceMap"
|
|
15
23
|
import * as Stream from "effect/Stream"
|
|
16
24
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity"
|
|
17
25
|
import * as Client from "effect/unstable/sql/SqlClient"
|
|
18
26
|
import type { Connection } from "effect/unstable/sql/SqlConnection"
|
|
19
|
-
import { SqlError } from "effect/unstable/sql/SqlError"
|
|
27
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
|
|
20
28
|
import * as Statement from "effect/unstable/sql/Statement"
|
|
21
29
|
|
|
22
30
|
const ATTR_DB_SYSTEM_NAME = "db.system.name"
|
|
23
31
|
|
|
32
|
+
const classifyError = (cause: unknown, message: string, operation: string) =>
|
|
33
|
+
classifySqliteError(cause, { message, operation })
|
|
34
|
+
|
|
24
35
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
36
|
+
* Runtime type identifier used to mark Node `SqliteClient` values.
|
|
37
|
+
*
|
|
38
|
+
* @category type IDs
|
|
39
|
+
* @since 4.0.0
|
|
27
40
|
*/
|
|
28
41
|
export const TypeId: TypeId = "~@effect/sql-sqlite-node/SqliteClient"
|
|
29
42
|
|
|
30
43
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
44
|
+
* Type-level identifier used to mark Node `SqliteClient` values.
|
|
45
|
+
*
|
|
46
|
+
* @category type IDs
|
|
47
|
+
* @since 4.0.0
|
|
33
48
|
*/
|
|
34
49
|
export type TypeId = "~@effect/sql-sqlite-node/SqliteClient"
|
|
35
50
|
|
|
36
51
|
/**
|
|
52
|
+
* Node SQLite client service, extending `SqlClient` with database export, backup, and extension loading helpers. `updateValues` is not supported.
|
|
53
|
+
*
|
|
37
54
|
* @category models
|
|
38
|
-
* @since
|
|
55
|
+
* @since 4.0.0
|
|
39
56
|
*/
|
|
40
57
|
export interface SqliteClient extends Client.SqlClient {
|
|
41
58
|
readonly [TypeId]: TypeId
|
|
@@ -49,8 +66,10 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
49
66
|
}
|
|
50
67
|
|
|
51
68
|
/**
|
|
69
|
+
* Metadata returned from a Node SQLite backup operation, reporting total and remaining page counts.
|
|
70
|
+
*
|
|
52
71
|
* @category models
|
|
53
|
-
* @since
|
|
72
|
+
* @since 4.0.0
|
|
54
73
|
*/
|
|
55
74
|
export interface BackupMetadata {
|
|
56
75
|
readonly totalPages: number
|
|
@@ -58,14 +77,18 @@ export interface BackupMetadata {
|
|
|
58
77
|
}
|
|
59
78
|
|
|
60
79
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
80
|
+
* Service tag for the node SQLite client implementation.
|
|
81
|
+
*
|
|
82
|
+
* @category services
|
|
83
|
+
* @since 4.0.0
|
|
63
84
|
*/
|
|
64
|
-
export const SqliteClient =
|
|
85
|
+
export const SqliteClient = Context.Service<SqliteClient>("@effect/sql-sqlite-node/SqliteClient")
|
|
65
86
|
|
|
66
87
|
/**
|
|
88
|
+
* Configuration for a node SQLite client backed by `better-sqlite3`, including the database filename, read-only mode, statement cache settings, WAL behavior, span attributes, and query/result name transforms.
|
|
89
|
+
*
|
|
67
90
|
* @category models
|
|
68
|
-
* @since
|
|
91
|
+
* @since 4.0.0
|
|
69
92
|
*/
|
|
70
93
|
export interface SqliteClientConfig {
|
|
71
94
|
readonly filename: string
|
|
@@ -86,8 +109,10 @@ interface SqliteConnection extends Connection {
|
|
|
86
109
|
}
|
|
87
110
|
|
|
88
111
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
112
|
+
* Creates a scoped node SQLite client from the supplied configuration, using a single serialized connection with WAL enabled by default and exposing SQLite-specific `export`, `backup`, and `loadExtension` operations.
|
|
113
|
+
*
|
|
114
|
+
* @category constructors
|
|
115
|
+
* @since 4.0.0
|
|
91
116
|
*/
|
|
92
117
|
export const make = (
|
|
93
118
|
options: SqliteClientConfig
|
|
@@ -117,7 +142,7 @@ export const make = (
|
|
|
117
142
|
lookup: (sql: string) =>
|
|
118
143
|
Effect.try({
|
|
119
144
|
try: () => db.prepare(sql),
|
|
120
|
-
catch: (cause) => new SqlError({ cause,
|
|
145
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to prepare statement", "prepare") })
|
|
121
146
|
})
|
|
122
147
|
})
|
|
123
148
|
|
|
@@ -127,7 +152,7 @@ export const make = (
|
|
|
127
152
|
raw: boolean
|
|
128
153
|
) =>
|
|
129
154
|
Effect.withFiber<ReadonlyArray<any>, SqlError>((fiber) => {
|
|
130
|
-
if (
|
|
155
|
+
if (Context.get(fiber.context, Client.SafeIntegers)) {
|
|
131
156
|
statement.safeIntegers(true)
|
|
132
157
|
}
|
|
133
158
|
try {
|
|
@@ -137,7 +162,7 @@ export const make = (
|
|
|
137
162
|
const result = statement.run(...params)
|
|
138
163
|
return Effect.succeed(raw ? result as unknown as ReadonlyArray<any> : [])
|
|
139
164
|
} catch (cause) {
|
|
140
|
-
return Effect.fail(new SqlError({ cause,
|
|
165
|
+
return Effect.fail(new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") }))
|
|
141
166
|
}
|
|
142
167
|
})
|
|
143
168
|
|
|
@@ -169,11 +194,30 @@ export const make = (
|
|
|
169
194
|
statement.run(...params)
|
|
170
195
|
return []
|
|
171
196
|
},
|
|
172
|
-
catch: (cause) => new SqlError({ cause,
|
|
197
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
|
|
173
198
|
}),
|
|
174
199
|
(statement) => Effect.sync(() => statement.reader && statement.raw(false))
|
|
175
200
|
)
|
|
176
201
|
|
|
202
|
+
const runValuesUnprepared = (
|
|
203
|
+
sql: string,
|
|
204
|
+
params: ReadonlyArray<unknown>
|
|
205
|
+
) =>
|
|
206
|
+
Effect.try({
|
|
207
|
+
try: () => {
|
|
208
|
+
const statement = db.prepare(sql)
|
|
209
|
+
if (statement.reader) {
|
|
210
|
+
statement.raw(true)
|
|
211
|
+
return statement.all(...params) as ReadonlyArray<
|
|
212
|
+
ReadonlyArray<unknown>
|
|
213
|
+
>
|
|
214
|
+
}
|
|
215
|
+
statement.run(...params)
|
|
216
|
+
return []
|
|
217
|
+
},
|
|
218
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
|
|
219
|
+
})
|
|
220
|
+
|
|
177
221
|
return identity<SqliteConnection>({
|
|
178
222
|
execute(sql, params, transformRows) {
|
|
179
223
|
return transformRows
|
|
@@ -186,6 +230,9 @@ export const make = (
|
|
|
186
230
|
executeValues(sql, params) {
|
|
187
231
|
return runValues(sql, params)
|
|
188
232
|
},
|
|
233
|
+
executeValuesUnprepared(sql, params) {
|
|
234
|
+
return runValuesUnprepared(sql, params)
|
|
235
|
+
},
|
|
189
236
|
executeUnprepared(sql, params, transformRows) {
|
|
190
237
|
const effect = runStatement(db.prepare(sql), params ?? [], false)
|
|
191
238
|
return transformRows ? Effect.map(effect, transformRows) : effect
|
|
@@ -195,18 +242,19 @@ export const make = (
|
|
|
195
242
|
},
|
|
196
243
|
export: Effect.try({
|
|
197
244
|
try: () => db.serialize(),
|
|
198
|
-
catch: (cause) => new SqlError({ cause,
|
|
245
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to export database", "export") })
|
|
199
246
|
}),
|
|
200
247
|
backup(destination) {
|
|
201
248
|
return Effect.tryPromise({
|
|
202
249
|
try: () => db.backup(destination),
|
|
203
|
-
catch: (cause) => new SqlError({ cause,
|
|
250
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to backup database", "backup") })
|
|
204
251
|
})
|
|
205
252
|
},
|
|
206
253
|
loadExtension(path) {
|
|
207
254
|
return Effect.try({
|
|
208
255
|
try: () => db.loadExtension(path),
|
|
209
|
-
catch: (cause) =>
|
|
256
|
+
catch: (cause) =>
|
|
257
|
+
new SqlError({ reason: classifyError(cause, "Failed to load extension", "loadExtension") })
|
|
210
258
|
})
|
|
211
259
|
}
|
|
212
260
|
})
|
|
@@ -218,7 +266,7 @@ export const make = (
|
|
|
218
266
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
|
|
219
267
|
const transactionAcquirer = Effect.uninterruptibleMask((restore) => {
|
|
220
268
|
const fiber = Fiber.getCurrent()!
|
|
221
|
-
const scope =
|
|
269
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope)
|
|
222
270
|
return Effect.as(
|
|
223
271
|
Effect.tap(
|
|
224
272
|
restore(semaphore.take(1)),
|
|
@@ -250,33 +298,37 @@ export const make = (
|
|
|
250
298
|
})
|
|
251
299
|
|
|
252
300
|
/**
|
|
301
|
+
* Builds a layer from an Effect `Config` value, providing both the node `SqliteClient` service and the generic `SqlClient` service.
|
|
302
|
+
*
|
|
253
303
|
* @category layers
|
|
254
|
-
* @since
|
|
304
|
+
* @since 4.0.0
|
|
255
305
|
*/
|
|
256
306
|
export const layerConfig = (
|
|
257
307
|
config: Config.Wrap<SqliteClientConfig>
|
|
258
308
|
): Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError> =>
|
|
259
|
-
Layer.
|
|
260
|
-
Config.unwrap(config).
|
|
309
|
+
Layer.effectContext(
|
|
310
|
+
Config.unwrap(config).pipe(
|
|
261
311
|
Effect.flatMap(make),
|
|
262
312
|
Effect.map((client) =>
|
|
263
|
-
|
|
264
|
-
|
|
313
|
+
Context.make(SqliteClient, client).pipe(
|
|
314
|
+
Context.add(Client.SqlClient, client)
|
|
265
315
|
)
|
|
266
316
|
)
|
|
267
317
|
)
|
|
268
318
|
).pipe(Layer.provide(Reactivity.layer))
|
|
269
319
|
|
|
270
320
|
/**
|
|
321
|
+
* Builds a layer from a node SQLite client configuration, providing both `SqliteClient` and the generic `SqlClient` service.
|
|
322
|
+
*
|
|
271
323
|
* @category layers
|
|
272
|
-
* @since
|
|
324
|
+
* @since 4.0.0
|
|
273
325
|
*/
|
|
274
326
|
export const layer = (
|
|
275
327
|
config: SqliteClientConfig
|
|
276
328
|
): Layer.Layer<SqliteClient | Client.SqlClient> =>
|
|
277
|
-
Layer.
|
|
329
|
+
Layer.effectContext(
|
|
278
330
|
Effect.map(make(config), (client) =>
|
|
279
|
-
|
|
280
|
-
|
|
331
|
+
Context.make(SqliteClient, client).pipe(
|
|
332
|
+
Context.add(Client.SqlClient, client)
|
|
281
333
|
))
|
|
282
334
|
).pipe(Layer.provide(Reactivity.layer))
|
package/src/SqliteMigrator.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Runs database migrations for Node.js 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 Node-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 for a SQLite database using the shared `Migrator` implementation and the current `SqlClient`.
|
|
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 SQLite migrations during layer construction and provides no services.
|
|
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"
|