@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 59 lines 2.27 KB
Raw
1 /**
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 * @stability unstable
21 * @since 4.0.0
22 */
23 import type * as Effect from "effect/Effect"
24 import * as Layer from "effect/Layer"
25 import * as Migrator from "effect/sql/Migrator"
26 import type * as Client from "effect/sql/SqlClient"
27 import type { SqlError } from "effect/sql/SqlError"
28
29 /**
30 * @since 4.0.0
31 */
32 export * from "effect/sql/Migrator"
33 // No `fromFileSystem` re-export: its dynamic `import()` breaks Metro.
34
35 /**
36 * Runs SQL migrations for a React Native SQLite database using the shared `Migrator` implementation and the current `SqlClient`.
37 *
38 * @stability unstable
39 * @category running
40 * @since 4.0.0
41 */
42 export const run: <R>(
43 options: Migrator.MigratorOptions<R>
44 ) => Effect.Effect<
45 ReadonlyArray<readonly [id: number, name: string]>,
46 SqlError | Migrator.MigrationError,
47 Client.SqlClient | R
48 > = Migrator.make({})
49
50 /**
51 * Creates a layer that runs the configured React Native SQLite migrations during layer construction and provides no services.
52 *
53 * @stability unstable
54 * @category layers
55 * @since 4.0.0
56 */
57 export const layer = <R>(
58 options: Migrator.MigratorOptions<R>
59 ): Layer.Layer<never, SqlError | Migrator.MigrationError, R | Client.SqlClient> => Layer.effectDiscard(run(options))