@effect/sql-sqlite-react-native 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 +42 -17
- package/dist/SqliteClient.d.ts.map +1 -1
- package/dist/SqliteClient.js +58 -23
- package/dist/SqliteClient.js.map +1 -1
- package/dist/SqliteMigrator.d.ts +28 -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 +6 -7
- package/src/SqliteClient.ts +73 -38
- package/src/SqliteMigrator.ts +28 -6
- package/src/index.ts +3 -3
package/README.md
CHANGED
package/dist/SqliteClient.d.ts
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
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
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Runtime identifier attached to SQLite React Native client values.
|
|
10
|
+
*
|
|
11
|
+
* @category type IDs
|
|
12
|
+
* @since 4.0.0
|
|
11
13
|
*/
|
|
12
14
|
export declare const TypeId: TypeId;
|
|
13
15
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* Type-level identifier for SQLite React Native client values.
|
|
17
|
+
*
|
|
18
|
+
* @category type IDs
|
|
19
|
+
* @since 4.0.0
|
|
16
20
|
*/
|
|
17
21
|
export type TypeId = "~@effect/sql-sqlite-react-native/SqliteClient";
|
|
18
22
|
/**
|
|
23
|
+
* React Native SQLite client service interface, extending `SqlClient` with its configuration and marking `updateValues` as unsupported for SQLite.
|
|
24
|
+
*
|
|
19
25
|
* @category models
|
|
20
|
-
* @since
|
|
26
|
+
* @since 4.0.0
|
|
21
27
|
*/
|
|
22
28
|
export interface SqliteClient extends Client.SqlClient {
|
|
23
29
|
readonly [TypeId]: TypeId;
|
|
@@ -26,13 +32,17 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
26
32
|
readonly updateValues: never;
|
|
27
33
|
}
|
|
28
34
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
35
|
+
* Service tag for the React Native SQLite client.
|
|
36
|
+
*
|
|
37
|
+
* @category services
|
|
38
|
+
* @since 4.0.0
|
|
31
39
|
*/
|
|
32
|
-
export declare const SqliteClient:
|
|
40
|
+
export declare const SqliteClient: Context.Service<SqliteClient, SqliteClient>;
|
|
33
41
|
/**
|
|
42
|
+
* Configuration for a React Native SQLite client, including the database filename, optional location and encryption key, span attributes, and query/result name transforms.
|
|
43
|
+
*
|
|
34
44
|
* @category models
|
|
35
|
-
* @since
|
|
45
|
+
* @since 4.0.0
|
|
36
46
|
*/
|
|
37
47
|
export interface SqliteClientConfig {
|
|
38
48
|
readonly filename: string;
|
|
@@ -43,28 +53,43 @@ export interface SqliteClientConfig {
|
|
|
43
53
|
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
44
54
|
}
|
|
45
55
|
/**
|
|
56
|
+
* Fiber reference that makes the React Native SQLite client run queries through the asynchronous `execute` API instead of `executeSync`.
|
|
57
|
+
*
|
|
58
|
+
* **When to use**
|
|
59
|
+
*
|
|
60
|
+
* Use to switch React Native SQLite query execution to the asynchronous driver
|
|
61
|
+
* API for a scoped effect.
|
|
62
|
+
*
|
|
46
63
|
* @category fiber refs
|
|
47
|
-
* @since
|
|
64
|
+
* @since 4.0.0
|
|
48
65
|
*/
|
|
49
|
-
export declare const AsyncQuery:
|
|
66
|
+
export declare const AsyncQuery: Context.Reference<boolean>;
|
|
50
67
|
/**
|
|
68
|
+
* Runs an effect with `AsyncQuery` enabled, causing React Native SQLite queries in that effect to use the asynchronous driver API.
|
|
69
|
+
*
|
|
51
70
|
* @category fiber refs
|
|
52
|
-
* @since
|
|
71
|
+
* @since 4.0.0
|
|
53
72
|
*/
|
|
54
73
|
export declare const withAsyncQuery: <R, E, A>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, never>>;
|
|
55
74
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
75
|
+
* Creates a scoped React Native SQLite client from the supplied configuration, using a single serialized connection and honoring `AsyncQuery` for query execution.
|
|
76
|
+
*
|
|
77
|
+
* @category constructors
|
|
78
|
+
* @since 4.0.0
|
|
58
79
|
*/
|
|
59
80
|
export declare const make: (options: SqliteClientConfig) => Effect.Effect<SqliteClient, never, Scope.Scope | Reactivity.Reactivity>;
|
|
60
81
|
/**
|
|
82
|
+
* Builds a layer from an Effect `Config` value, providing both the React Native `SqliteClient` service and the generic `SqlClient` service.
|
|
83
|
+
*
|
|
61
84
|
* @category layers
|
|
62
|
-
* @since
|
|
85
|
+
* @since 4.0.0
|
|
63
86
|
*/
|
|
64
87
|
export declare const layerConfig: (config: Config.Wrap<SqliteClientConfig>) => Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError>;
|
|
65
88
|
/**
|
|
89
|
+
* Builds a layer from a React Native SQLite client configuration, providing both `SqliteClient` and the generic `SqlClient` service.
|
|
90
|
+
*
|
|
66
91
|
* @category layers
|
|
67
|
-
* @since
|
|
92
|
+
* @since 4.0.0
|
|
68
93
|
*/
|
|
69
94
|
export declare const layer: (config: SqliteClientConfig) => Layer.Layer<SqliteClient | Client.SqlClient>;
|
|
70
95
|
//# sourceMappingURL=SqliteClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteClient.d.ts","sourceRoot":"","sources":["../src/SqliteClient.ts"],"names":[],"mappings":"
|
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B,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;CACrE;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,4BAGtB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CACrB,CAAA;AAIjD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,YACN,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CAsGrE,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,45 +1,75 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Connects Effect SQL to SQLite in React Native using
|
|
3
|
+
* `@op-engineering/op-sqlite`.
|
|
4
|
+
*
|
|
5
|
+
* This module opens an on-device SQLite database and exposes it as both
|
|
6
|
+
* `SqliteClient` and the generic Effect SQL client. It serializes access,
|
|
7
|
+
* supports normal and value-based queries, and uses the driver's synchronous
|
|
8
|
+
* query API by default. `AsyncQuery` and `withAsyncQuery` switch a scoped effect
|
|
9
|
+
* to the driver's asynchronous query API. Streaming queries and `updateValues`
|
|
10
|
+
* are not supported by this driver.
|
|
11
|
+
*
|
|
12
|
+
* @since 4.0.0
|
|
3
13
|
*/
|
|
4
14
|
import * as Sqlite from "@op-engineering/op-sqlite";
|
|
5
15
|
import * as Config from "effect/Config";
|
|
16
|
+
import * as Context from "effect/Context";
|
|
6
17
|
import * as Effect from "effect/Effect";
|
|
7
18
|
import * as Fiber from "effect/Fiber";
|
|
8
19
|
import { constFalse, identity } from "effect/Function";
|
|
9
20
|
import * as Layer from "effect/Layer";
|
|
10
21
|
import * as Scope from "effect/Scope";
|
|
11
|
-
import * as
|
|
22
|
+
import * as Semaphore from "effect/Semaphore";
|
|
12
23
|
import * as Stream from "effect/Stream";
|
|
13
24
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
14
25
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
15
|
-
import { SqlError } from "effect/unstable/sql/SqlError";
|
|
26
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError";
|
|
16
27
|
import * as Statement from "effect/unstable/sql/Statement";
|
|
17
28
|
const ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
29
|
+
const classifyError = (cause, message, operation) => classifySqliteError(cause, {
|
|
30
|
+
message,
|
|
31
|
+
operation
|
|
32
|
+
});
|
|
18
33
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
34
|
+
* Runtime identifier attached to SQLite React Native client values.
|
|
35
|
+
*
|
|
36
|
+
* @category type IDs
|
|
37
|
+
* @since 4.0.0
|
|
21
38
|
*/
|
|
22
39
|
export const TypeId = "~@effect/sql-sqlite-react-native/SqliteClient";
|
|
23
40
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
41
|
+
* Service tag for the React Native SQLite client.
|
|
42
|
+
*
|
|
43
|
+
* @category services
|
|
44
|
+
* @since 4.0.0
|
|
26
45
|
*/
|
|
27
|
-
export const SqliteClient = /*#__PURE__*/
|
|
46
|
+
export const SqliteClient = /*#__PURE__*/Context.Service("@effect/sql-sqlite-react-native/SqliteClient");
|
|
28
47
|
/**
|
|
48
|
+
* Fiber reference that makes the React Native SQLite client run queries through the asynchronous `execute` API instead of `executeSync`.
|
|
49
|
+
*
|
|
50
|
+
* **When to use**
|
|
51
|
+
*
|
|
52
|
+
* Use to switch React Native SQLite query execution to the asynchronous driver
|
|
53
|
+
* API for a scoped effect.
|
|
54
|
+
*
|
|
29
55
|
* @category fiber refs
|
|
30
|
-
* @since
|
|
56
|
+
* @since 4.0.0
|
|
31
57
|
*/
|
|
32
|
-
export const AsyncQuery = /*#__PURE__*/
|
|
58
|
+
export const AsyncQuery = /*#__PURE__*/Context.Reference("@effect/sql-sqlite-react-native/Client/asyncQuery", {
|
|
33
59
|
defaultValue: constFalse
|
|
34
60
|
});
|
|
35
61
|
/**
|
|
62
|
+
* Runs an effect with `AsyncQuery` enabled, causing React Native SQLite queries in that effect to use the asynchronous driver API.
|
|
63
|
+
*
|
|
36
64
|
* @category fiber refs
|
|
37
|
-
* @since
|
|
65
|
+
* @since 4.0.0
|
|
38
66
|
*/
|
|
39
67
|
export const withAsyncQuery = effect => Effect.provideService(effect, AsyncQuery, true);
|
|
40
68
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
69
|
+
* Creates a scoped React Native SQLite client from the supplied configuration, using a single serialized connection and honoring `AsyncQuery` for query execution.
|
|
70
|
+
*
|
|
71
|
+
* @category constructors
|
|
72
|
+
* @since 4.0.0
|
|
43
73
|
*/
|
|
44
74
|
export const make = options => Effect.gen(function* () {
|
|
45
75
|
const clientOptions = {
|
|
@@ -61,8 +91,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
61
91
|
return Effect.map(Effect.tryPromise({
|
|
62
92
|
try: () => db.execute(sql, params),
|
|
63
93
|
catch: cause => new SqlError({
|
|
64
|
-
cause,
|
|
65
|
-
message: "Failed to execute statement (async)"
|
|
94
|
+
reason: classifyError(cause, "Failed to execute statement (async)", "execute")
|
|
66
95
|
})
|
|
67
96
|
}), result => values ? result.rawRows ?? [] : result.rows);
|
|
68
97
|
}
|
|
@@ -72,8 +101,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
72
101
|
return values ? result.rawRows ?? [] : result.rows;
|
|
73
102
|
},
|
|
74
103
|
catch: cause => new SqlError({
|
|
75
|
-
cause,
|
|
76
|
-
message: "Failed to execute statement"
|
|
104
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
77
105
|
})
|
|
78
106
|
});
|
|
79
107
|
});
|
|
@@ -87,6 +115,9 @@ export const make = options => Effect.gen(function* () {
|
|
|
87
115
|
executeValues(sql, params) {
|
|
88
116
|
return run(sql, params, true);
|
|
89
117
|
},
|
|
118
|
+
executeValuesUnprepared(sql, params) {
|
|
119
|
+
return run(sql, params, true);
|
|
120
|
+
},
|
|
90
121
|
executeUnprepared(sql, params, transformRows) {
|
|
91
122
|
return this.execute(sql, params, transformRows);
|
|
92
123
|
},
|
|
@@ -95,12 +126,12 @@ export const make = options => Effect.gen(function* () {
|
|
|
95
126
|
}
|
|
96
127
|
});
|
|
97
128
|
});
|
|
98
|
-
const semaphore = yield*
|
|
129
|
+
const semaphore = yield* Semaphore.make(1);
|
|
99
130
|
const connection = yield* makeConnection;
|
|
100
131
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
101
132
|
const transactionAcquirer = Effect.uninterruptibleMask(restore => {
|
|
102
133
|
const fiber = Fiber.getCurrent();
|
|
103
|
-
const scope =
|
|
134
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope);
|
|
104
135
|
return Effect.as(Effect.tap(restore(semaphore.take(1)), () => Scope.addFinalizer(scope, semaphore.release(1))), connection);
|
|
105
136
|
});
|
|
106
137
|
return Object.assign(yield* Client.make({
|
|
@@ -115,13 +146,17 @@ export const make = options => Effect.gen(function* () {
|
|
|
115
146
|
});
|
|
116
147
|
});
|
|
117
148
|
/**
|
|
149
|
+
* Builds a layer from an Effect `Config` value, providing both the React Native `SqliteClient` service and the generic `SqlClient` service.
|
|
150
|
+
*
|
|
118
151
|
* @category layers
|
|
119
|
-
* @since
|
|
152
|
+
* @since 4.0.0
|
|
120
153
|
*/
|
|
121
|
-
export const layerConfig = config => Layer.
|
|
154
|
+
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));
|
|
122
155
|
/**
|
|
156
|
+
* Builds a layer from a React Native SQLite client configuration, providing both `SqliteClient` and the generic `SqlClient` service.
|
|
157
|
+
*
|
|
123
158
|
* @category layers
|
|
124
|
-
* @since
|
|
159
|
+
* @since 4.0.0
|
|
125
160
|
*/
|
|
126
|
-
export const layer = config => Layer.
|
|
161
|
+
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));
|
|
127
162
|
//# sourceMappingURL=SqliteClient.js.map
|
package/dist/SqliteClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteClient.js","names":["Sqlite","Config","Effect","Fiber","constFalse","identity","Layer","Scope","
|
|
1
|
+
{"version":3,"file":"SqliteClient.js","names":["Sqlite","Config","Context","Effect","Fiber","constFalse","identity","Layer","Scope","Semaphore","Stream","Reactivity","Client","classifySqliteError","SqlError","Statement","ATTR_DB_SYSTEM_NAME","classifyError","cause","message","operation","TypeId","SqliteClient","Service","AsyncQuery","Reference","defaultValue","withAsyncQuery","effect","provideService","make","options","gen","clientOptions","name","filename","location","encryptionKey","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","makeConnection","db","open","addFinalizer","sync","close","run","sql","params","values","withFiber","fiber","getRef","map","tryPromise","try","execute","catch","reason","result","rawRows","rows","executeSync","executeRaw","executeValues","executeValuesUnprepared","executeUnprepared","executeStream","die","semaphore","connection","acquirer","withPermits","succeed","transactionAcquirer","uninterruptibleMask","restore","getCurrent","scope","getUnsafe","context","as","tap","take","release","Object","assign","spanAttributes","entries","config","layerConfig","effectContext","unwrap","pipe","flatMap","client","add","SqlClient","provide","layer"],"sources":["../src/SqliteClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;AAaA,OAAO,KAAKA,MAAM,MAAM,2BAA2B;AACnD,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,UAAU,EAAEC,QAAQ,QAAQ,iBAAiB;AACtD,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,+CAA+C;AAwB7E;;;;;;AAMA,OAAO,MAAMC,YAAY,gBAAGpB,OAAO,CAACqB,OAAO,CAAe,8CAA8C,CAAC;AAiBzG;;;;;;;;;;;AAWA,OAAO,MAAMC,UAAU,gBAAGtB,OAAO,CAACuB,SAAS,CACzC,mDAAmD,EACnD;EAAEC,YAAY,EAAErB;AAAU,CAAE,CAC7B;AAED;;;;;;AAMA,OAAO,MAAMsB,cAAc,GAAaC,MAA8B,IACpEzB,MAAM,CAAC0B,cAAc,CAACD,MAAM,EAAEJ,U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AAC,CAChC;IACDyB;GACD,CAAC,EACF;IACE,CAACpB,MAAM,GAAGA,MAAM;IAChB0E,MAAM,EAAEhE;GACT,CACF;AACH,CAAC,CAAC;AAEJ;;;;;;AAMA,OAAO,MAAMiE,WAAW,GACtBD,MAAuC,IAEvCxF,KAAK,CAAC0F,aAAa,CACjBhG,MAAM,CAACiG,MAAM,CAACH,MAAM,CAAC,CAACI,IAAI,CACxBhG,MAAM,CAACiG,OAAO,CAACtE,IAAI,CAAC,EACpB3B,MAAM,CAACwD,GAAG,CAAE0C,MAAM,IAChBnG,OAAO,CAAC4B,IAAI,CAACR,YAAY,EAAE+E,MAAM,CAAC,CAACF,IAAI,CACrCjG,OAAO,CAACoG,GAAG,CAAC1F,MAAM,CAAC2F,SAAS,EAAEF,MAAM,CAAC,CACtC,CACF,CACF,CACF,CAACF,IAAI,CAAC5F,KAAK,CAACiG,OAAO,CAAC7F,UAAU,CAAC8F,KAAK,CAAC,CAAC;AAEzC;;;;;;AAMA,OAAO,MAAMA,KAAK,GAChBV,MAA0B,IAE1BxF,KAAK,CAAC0F,aAAa,CACjB9F,MAAM,CAACwD,GAAG,CAAC7B,IAAI,CAACiE,MAAM,CAAC,EAAGM,MAAM,IAC9BnG,OAAO,CAAC4B,IAAI,CAACR,YAAY,EAAE+E,MAAM,CAAC,CAACF,IAAI,CACrCjG,OAAO,CAACoG,GAAG,CAAC1F,MAAM,CAAC2F,SAAS,EAAEF,MAAM,CAAC,CACtC,CAAC,CACL,CAACF,IAAI,CAAC5F,KAAK,CAACiG,OAAO,CAAC7F,UAAU,CAAC8F,KAAK,CAAC,CAAC","ignoreList":[]}
|
package/dist/SqliteMigrator.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Utilities for applying Effect SQL migrations to React Native SQLite databases.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
5
|
+
* provides `run` and `layer` helpers that execute ordered migrations through the
|
|
6
|
+
* current React Native SQLite `SqlClient`. Use it when a mobile app needs to
|
|
7
|
+
* bring its on-device database schema up to date during startup, before opening
|
|
8
|
+
* repositories or sync services, or in integration tests that create app-local
|
|
9
|
+
* database files.
|
|
10
|
+
*
|
|
11
|
+
* React Native SQLite databases are scoped by the client configuration, so the
|
|
12
|
+
* migrator should be run with the same `filename`, `location`, and encryption
|
|
13
|
+
* key as the rest of the application. Migrations run through the package's
|
|
14
|
+
* single serialized connection; by default statements use the synchronous
|
|
15
|
+
* driver API and can block the JS thread, so long migration sets may want to run
|
|
16
|
+
* under `SqliteClient.withAsyncQuery`. Mobile upgrades can be interrupted by app
|
|
17
|
+
* suspension or process death, so keep migrations transaction-aware and avoid
|
|
18
|
+
* assuming a fresh database on every launch.
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
import type * as Effect from "effect/Effect";
|
|
5
23
|
import * as Layer from "effect/Layer";
|
|
@@ -7,17 +25,21 @@ import * as Migrator from "effect/unstable/sql/Migrator";
|
|
|
7
25
|
import type * as Client from "effect/unstable/sql/SqlClient";
|
|
8
26
|
import type { SqlError } from "effect/unstable/sql/SqlError";
|
|
9
27
|
/**
|
|
10
|
-
* @since
|
|
28
|
+
* @since 4.0.0
|
|
11
29
|
*/
|
|
12
30
|
export * from "effect/unstable/sql/Migrator";
|
|
13
31
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
32
|
+
* Runs SQL migrations for a React Native SQLite database using the shared `Migrator` implementation and the current `SqlClient`.
|
|
33
|
+
*
|
|
34
|
+
* @category constructors
|
|
35
|
+
* @since 4.0.0
|
|
16
36
|
*/
|
|
17
37
|
export declare const run: <R>(options: Migrator.MigratorOptions<R>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, SqlError | Migrator.MigrationError, Client.SqlClient | R>;
|
|
18
38
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
39
|
+
* Creates a layer that runs the configured React Native SQLite migrations during layer construction and provides no services.
|
|
40
|
+
*
|
|
41
|
+
* @category constructors
|
|
42
|
+
* @since 4.0.0
|
|
21
43
|
*/
|
|
22
44
|
export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, SqlError | Migrator.MigrationError, R | Client.SqlClient>;
|
|
23
45
|
//# 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;;;;;;;;;;;;;;;;;;;;GAoBG;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,CAAC,EAClB,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACjC,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,GAAG,QAAQ,CAAC,cAAc,EAClC,MAAM,CAAC,SAAS,GAAG,CAAC,CACD,CAAA;AAErB;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,WACZ,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,CAAsC,CAAA"}
|
package/dist/SqliteMigrator.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
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 React Native 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
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
+
* Creates a layer that runs the configured React Native SQLite migrations during layer construction and provides no services.
|
|
16
|
+
*
|
|
17
|
+
* @category constructors
|
|
18
|
+
* @since 4.0.0
|
|
15
19
|
*/
|
|
16
20
|
export const layer = options => Layer.effectDiscard(run(options));
|
|
17
21
|
//# 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":"AAsBA,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,EAAE,CAAC;AAErB;;;;;;AAMA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAC6CL,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-react-native",
|
|
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-react-native"
|
|
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
|
-
"@op-engineering/op-sqlite": "
|
|
47
|
-
"effect": "^4.0.0-beta.
|
|
46
|
+
"@op-engineering/op-sqlite": "17.1.2",
|
|
47
|
+
"effect": "^4.0.0-beta.100"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@op-engineering/op-sqlite": "15.0.4",
|
|
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,58 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Connects Effect SQL to SQLite in React Native using
|
|
3
|
+
* `@op-engineering/op-sqlite`.
|
|
4
|
+
*
|
|
5
|
+
* This module opens an on-device SQLite database and exposes it as both
|
|
6
|
+
* `SqliteClient` and the generic Effect SQL client. It serializes access,
|
|
7
|
+
* supports normal and value-based queries, and uses the driver's synchronous
|
|
8
|
+
* query API by default. `AsyncQuery` and `withAsyncQuery` switch a scoped effect
|
|
9
|
+
* to the driver's asynchronous query API. Streaming queries and `updateValues`
|
|
10
|
+
* are not supported by this driver.
|
|
11
|
+
*
|
|
12
|
+
* @since 4.0.0
|
|
3
13
|
*/
|
|
4
14
|
import * as Sqlite from "@op-engineering/op-sqlite"
|
|
5
15
|
import * as Config from "effect/Config"
|
|
16
|
+
import * as Context from "effect/Context"
|
|
6
17
|
import * as Effect from "effect/Effect"
|
|
7
18
|
import * as Fiber from "effect/Fiber"
|
|
8
19
|
import { constFalse, identity } from "effect/Function"
|
|
9
20
|
import * as Layer from "effect/Layer"
|
|
10
21
|
import * as Scope from "effect/Scope"
|
|
11
|
-
import * as
|
|
22
|
+
import * as Semaphore from "effect/Semaphore"
|
|
12
23
|
import * as Stream from "effect/Stream"
|
|
13
24
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity"
|
|
14
25
|
import * as Client from "effect/unstable/sql/SqlClient"
|
|
15
26
|
import type { Connection } from "effect/unstable/sql/SqlConnection"
|
|
16
|
-
import { SqlError } from "effect/unstable/sql/SqlError"
|
|
27
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
|
|
17
28
|
import * as Statement from "effect/unstable/sql/Statement"
|
|
18
29
|
|
|
19
30
|
const ATTR_DB_SYSTEM_NAME = "db.system.name"
|
|
20
31
|
|
|
32
|
+
const classifyError = (cause: unknown, message: string, operation: string) =>
|
|
33
|
+
classifySqliteError(cause, { message, operation })
|
|
34
|
+
|
|
21
35
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
36
|
+
* Runtime identifier attached to SQLite React Native client values.
|
|
37
|
+
*
|
|
38
|
+
* @category type IDs
|
|
39
|
+
* @since 4.0.0
|
|
24
40
|
*/
|
|
25
41
|
export const TypeId: TypeId = "~@effect/sql-sqlite-react-native/SqliteClient"
|
|
26
42
|
|
|
27
43
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
44
|
+
* Type-level identifier for SQLite React Native client values.
|
|
45
|
+
*
|
|
46
|
+
* @category type IDs
|
|
47
|
+
* @since 4.0.0
|
|
30
48
|
*/
|
|
31
49
|
export type TypeId = "~@effect/sql-sqlite-react-native/SqliteClient"
|
|
32
50
|
|
|
33
51
|
/**
|
|
52
|
+
* React Native SQLite client service interface, extending `SqlClient` with its configuration and marking `updateValues` as unsupported for SQLite.
|
|
53
|
+
*
|
|
34
54
|
* @category models
|
|
35
|
-
* @since
|
|
55
|
+
* @since 4.0.0
|
|
36
56
|
*/
|
|
37
57
|
export interface SqliteClient extends Client.SqlClient {
|
|
38
58
|
readonly [TypeId]: TypeId
|
|
@@ -43,14 +63,18 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
43
63
|
}
|
|
44
64
|
|
|
45
65
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
66
|
+
* Service tag for the React Native SQLite client.
|
|
67
|
+
*
|
|
68
|
+
* @category services
|
|
69
|
+
* @since 4.0.0
|
|
48
70
|
*/
|
|
49
|
-
export const SqliteClient =
|
|
71
|
+
export const SqliteClient = Context.Service<SqliteClient>("@effect/sql-sqlite-react-native/SqliteClient")
|
|
50
72
|
|
|
51
73
|
/**
|
|
74
|
+
* Configuration for a React Native SQLite client, including the database filename, optional location and encryption key, span attributes, and query/result name transforms.
|
|
75
|
+
*
|
|
52
76
|
* @category models
|
|
53
|
-
* @since
|
|
77
|
+
* @since 4.0.0
|
|
54
78
|
*/
|
|
55
79
|
export interface SqliteClientConfig {
|
|
56
80
|
readonly filename: string
|
|
@@ -62,17 +86,26 @@ export interface SqliteClientConfig {
|
|
|
62
86
|
}
|
|
63
87
|
|
|
64
88
|
/**
|
|
89
|
+
* Fiber reference that makes the React Native SQLite client run queries through the asynchronous `execute` API instead of `executeSync`.
|
|
90
|
+
*
|
|
91
|
+
* **When to use**
|
|
92
|
+
*
|
|
93
|
+
* Use to switch React Native SQLite query execution to the asynchronous driver
|
|
94
|
+
* API for a scoped effect.
|
|
95
|
+
*
|
|
65
96
|
* @category fiber refs
|
|
66
|
-
* @since
|
|
97
|
+
* @since 4.0.0
|
|
67
98
|
*/
|
|
68
|
-
export const AsyncQuery =
|
|
99
|
+
export const AsyncQuery = Context.Reference<boolean>(
|
|
69
100
|
"@effect/sql-sqlite-react-native/Client/asyncQuery",
|
|
70
101
|
{ defaultValue: constFalse }
|
|
71
102
|
)
|
|
72
103
|
|
|
73
104
|
/**
|
|
105
|
+
* Runs an effect with `AsyncQuery` enabled, causing React Native SQLite queries in that effect to use the asynchronous driver API.
|
|
106
|
+
*
|
|
74
107
|
* @category fiber refs
|
|
75
|
-
* @since
|
|
108
|
+
* @since 4.0.0
|
|
76
109
|
*/
|
|
77
110
|
export const withAsyncQuery = <R, E, A>(effect: Effect.Effect<A, E, R>) =>
|
|
78
111
|
Effect.provideService(effect, AsyncQuery, true)
|
|
@@ -80,8 +113,10 @@ export const withAsyncQuery = <R, E, A>(effect: Effect.Effect<A, E, R>) =>
|
|
|
80
113
|
interface SqliteConnection extends Connection {}
|
|
81
114
|
|
|
82
115
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
116
|
+
* Creates a scoped React Native SQLite client from the supplied configuration, using a single serialized connection and honoring `AsyncQuery` for query execution.
|
|
117
|
+
*
|
|
118
|
+
* @category constructors
|
|
119
|
+
* @since 4.0.0
|
|
85
120
|
*/
|
|
86
121
|
export const make = (
|
|
87
122
|
options: SqliteClientConfig
|
|
@@ -116,7 +151,8 @@ export const make = (
|
|
|
116
151
|
return Effect.map(
|
|
117
152
|
Effect.tryPromise({
|
|
118
153
|
try: () => db.execute(sql, params as Array<any>),
|
|
119
|
-
catch: (cause) =>
|
|
154
|
+
catch: (cause) =>
|
|
155
|
+
new SqlError({ reason: classifyError(cause, "Failed to execute statement (async)", "execute") })
|
|
120
156
|
}),
|
|
121
157
|
(result) => values ? result.rawRows ?? [] : result.rows
|
|
122
158
|
)
|
|
@@ -126,7 +162,7 @@ export const make = (
|
|
|
126
162
|
const result = db.executeSync(sql, params as Array<any>)
|
|
127
163
|
return values ? result.rawRows ?? [] : result.rows
|
|
128
164
|
},
|
|
129
|
-
catch: (cause) => new SqlError({ cause,
|
|
165
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
|
|
130
166
|
})
|
|
131
167
|
})
|
|
132
168
|
|
|
@@ -142,6 +178,9 @@ export const make = (
|
|
|
142
178
|
executeValues(sql, params) {
|
|
143
179
|
return run(sql, params, true)
|
|
144
180
|
},
|
|
181
|
+
executeValuesUnprepared(sql, params) {
|
|
182
|
+
return run(sql, params, true)
|
|
183
|
+
},
|
|
145
184
|
executeUnprepared(sql, params, transformRows) {
|
|
146
185
|
return this.execute(sql, params, transformRows)
|
|
147
186
|
},
|
|
@@ -151,13 +190,13 @@ export const make = (
|
|
|
151
190
|
})
|
|
152
191
|
})
|
|
153
192
|
|
|
154
|
-
const semaphore = yield*
|
|
193
|
+
const semaphore = yield* Semaphore.make(1)
|
|
155
194
|
const connection = yield* makeConnection
|
|
156
195
|
|
|
157
196
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
|
|
158
197
|
const transactionAcquirer = Effect.uninterruptibleMask((restore) => {
|
|
159
198
|
const fiber = Fiber.getCurrent()!
|
|
160
|
-
const scope =
|
|
199
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope)
|
|
161
200
|
return Effect.as(
|
|
162
201
|
Effect.tap(
|
|
163
202
|
restore(semaphore.take(1)),
|
|
@@ -186,34 +225,38 @@ export const make = (
|
|
|
186
225
|
})
|
|
187
226
|
|
|
188
227
|
/**
|
|
228
|
+
* Builds a layer from an Effect `Config` value, providing both the React Native `SqliteClient` service and the generic `SqlClient` service.
|
|
229
|
+
*
|
|
189
230
|
* @category layers
|
|
190
|
-
* @since
|
|
231
|
+
* @since 4.0.0
|
|
191
232
|
*/
|
|
192
233
|
export const layerConfig = (
|
|
193
234
|
config: Config.Wrap<SqliteClientConfig>
|
|
194
235
|
): Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError> =>
|
|
195
|
-
Layer.
|
|
196
|
-
Config.unwrap(config).
|
|
236
|
+
Layer.effectContext(
|
|
237
|
+
Config.unwrap(config).pipe(
|
|
197
238
|
Effect.flatMap(make),
|
|
198
239
|
Effect.map((client) =>
|
|
199
|
-
|
|
200
|
-
|
|
240
|
+
Context.make(SqliteClient, client).pipe(
|
|
241
|
+
Context.add(Client.SqlClient, client)
|
|
201
242
|
)
|
|
202
243
|
)
|
|
203
244
|
)
|
|
204
245
|
).pipe(Layer.provide(Reactivity.layer))
|
|
205
246
|
|
|
206
247
|
/**
|
|
248
|
+
* Builds a layer from a React Native SQLite client configuration, providing both `SqliteClient` and the generic `SqlClient` service.
|
|
249
|
+
*
|
|
207
250
|
* @category layers
|
|
208
|
-
* @since
|
|
251
|
+
* @since 4.0.0
|
|
209
252
|
*/
|
|
210
253
|
export const layer = (
|
|
211
254
|
config: SqliteClientConfig
|
|
212
255
|
): Layer.Layer<SqliteClient | Client.SqlClient> =>
|
|
213
|
-
Layer.
|
|
256
|
+
Layer.effectContext(
|
|
214
257
|
Effect.map(make(config), (client) =>
|
|
215
|
-
|
|
216
|
-
|
|
258
|
+
Context.make(SqliteClient, client).pipe(
|
|
259
|
+
Context.add(Client.SqlClient, client)
|
|
217
260
|
))
|
|
218
261
|
).pipe(Layer.provide(Reactivity.layer))
|
|
219
262
|
|
|
@@ -240,10 +283,6 @@ interface DB {
|
|
|
240
283
|
*
|
|
241
284
|
* If you are writing to the database YOU SHOULD BE USING TRANSACTIONS!
|
|
242
285
|
* Transactions protect you from partial writes and ensure that your data is always in a consistent state
|
|
243
|
-
*
|
|
244
|
-
* @param query
|
|
245
|
-
* @param params
|
|
246
|
-
* @returns QueryResult
|
|
247
286
|
*/
|
|
248
287
|
executeSync: (query: string, params?: Array<any>) => QueryResult
|
|
249
288
|
/**
|
|
@@ -261,10 +300,6 @@ interface DB {
|
|
|
261
300
|
* Transactions protect you from partial writes and ensure that your data is always in a consistent state
|
|
262
301
|
*
|
|
263
302
|
* If you need a large amount of queries ran as fast as possible you should be using `executeBatch`, `executeRaw`, `loadFile` or `executeWithHostObjects`
|
|
264
|
-
*
|
|
265
|
-
* @param query string of your SQL query
|
|
266
|
-
* @param params a list of parameters to bind to the query, if any
|
|
267
|
-
* @returns Promise<QueryResult> with the result of the query
|
|
268
303
|
*/
|
|
269
304
|
execute: (query: string, params?: Array<any>) => Promise<QueryResult>
|
|
270
305
|
/**
|
package/src/SqliteMigrator.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Utilities for applying Effect SQL migrations to React Native SQLite databases.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
5
|
+
* provides `run` and `layer` helpers that execute ordered migrations through the
|
|
6
|
+
* current React Native SQLite `SqlClient`. Use it when a mobile app needs to
|
|
7
|
+
* bring its on-device database schema up to date during startup, before opening
|
|
8
|
+
* repositories or sync services, or in integration tests that create app-local
|
|
9
|
+
* database files.
|
|
10
|
+
*
|
|
11
|
+
* React Native SQLite databases are scoped by the client configuration, so the
|
|
12
|
+
* migrator should be run with the same `filename`, `location`, and encryption
|
|
13
|
+
* key as the rest of the application. Migrations run through the package's
|
|
14
|
+
* single serialized connection; by default statements use the synchronous
|
|
15
|
+
* driver API and can block the JS thread, so long migration sets may want to run
|
|
16
|
+
* under `SqliteClient.withAsyncQuery`. Mobile upgrades can be interrupted by app
|
|
17
|
+
* suspension or process death, so keep migrations transaction-aware and avoid
|
|
18
|
+
* assuming a fresh database on every launch.
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
import type * as Effect from "effect/Effect"
|
|
5
23
|
import * as Layer from "effect/Layer"
|
|
@@ -8,13 +26,15 @@ import type * as Client from "effect/unstable/sql/SqlClient"
|
|
|
8
26
|
import type { SqlError } from "effect/unstable/sql/SqlError"
|
|
9
27
|
|
|
10
28
|
/**
|
|
11
|
-
* @since
|
|
29
|
+
* @since 4.0.0
|
|
12
30
|
*/
|
|
13
31
|
export * from "effect/unstable/sql/Migrator"
|
|
14
32
|
|
|
15
33
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
34
|
+
* Runs SQL migrations for a React Native SQLite database using the shared `Migrator` implementation and the current `SqlClient`.
|
|
35
|
+
*
|
|
36
|
+
* @category constructors
|
|
37
|
+
* @since 4.0.0
|
|
18
38
|
*/
|
|
19
39
|
export const run: <R>(
|
|
20
40
|
options: Migrator.MigratorOptions<R>
|
|
@@ -25,8 +45,10 @@ export const run: <R>(
|
|
|
25
45
|
> = Migrator.make({})
|
|
26
46
|
|
|
27
47
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
48
|
+
* Creates a layer that runs the configured React Native SQLite migrations during layer construction and provides no services.
|
|
49
|
+
*
|
|
50
|
+
* @category constructors
|
|
51
|
+
* @since 4.0.0
|
|
30
52
|
*/
|
|
31
53
|
export const layer = <R>(
|
|
32
54
|
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"
|