| 1 | /** |
| 2 | * libSQL migration support for Effect SQL applications. |
| 3 | * |
| 4 | * This module adapts the shared SQL migrator to libSQL. It re-exports the |
| 5 | * common migration loaders and errors, then provides {@link run} and |
| 6 | * {@link layer} helpers that apply pending migrations with the current |
| 7 | * libSQL-backed `SqlClient`. `run` returns the applied migration IDs and names, |
| 8 | * while `layer` runs migrations during layer construction and provides no |
| 9 | * services. |
| 10 | * |
| 11 | * @since 4.0.0 |
| 12 | */ |
| 13 | import type * as Effect from "effect/Effect" |
| 14 | import * as Layer from "effect/Layer" |
| 15 | import * as Migrator from "effect/sql/Migrator" |
| 16 | import type * as Client from "effect/sql/SqlClient" |
| 17 | import type { SqlError } from "effect/sql/SqlError" |
| 18 | |
| 19 | /** |
| 20 | * @since 4.0.0 |
| 21 | */ |
| 22 | export * from "effect/sql/Migrator" |
| 23 | |
| 24 | /** |
| 25 | * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied. |
| 26 | * |
| 27 | * @category running |
| 28 | * @since 4.0.0 |
| 29 | */ |
| 30 | export const run: <R2 = never>( |
| 31 | options: Migrator.MigratorOptions<R2> |
| 32 | ) => Effect.Effect< |
| 33 | ReadonlyArray<readonly [id: number, name: string]>, |
| 34 | Migrator.MigrationError | SqlError, |
| 35 | Client.SqlClient | R2 |
| 36 | > = Migrator.make({}) |
| 37 | |
| 38 | /** |
| 39 | * Creates a layer that runs the configured SQL migrations during layer construction. |
| 40 | * |
| 41 | * @category layers |
| 42 | * @since 4.0.0 |
| 43 | */ |
| 44 | export const layer = <R>( |
| 45 | options: Migrator.MigratorOptions<R> |
| 46 | ): Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R> => Layer.effectDiscard(run(options)) |