| ... | @@ -50,11 +50,35 @@ export interface SqliteMemoryClientConfig extends Omit< | ... | @@ -50,11 +50,35 @@ export interface SqliteMemoryClientConfig extends Omit< |
| 50 | "filename" | "readonly" | 50 | "filename" | "readonly" |
| 51 | > {} | 51 | > {} |
| 52 | | 52 | |
| | 53 | /** |
| | 54 | * Verify that the current Node.js version includes the `node:sqlite` APIs |
| | 55 | * used by `NodeSqliteClient` — specifically `StatementSync.columns()` (added |
| | 56 | * in Node 22.16.0 / 23.11.0). |
| | 57 | * |
| | 58 | * @see https://github.com/nodejs/node/pull/57490 |
| | 59 | */ |
| | 60 | const checkNodeSqliteCompat = () => { |
| | 61 | const parts = process.versions.node.split(".").map(Number); |
| | 62 | const major = parts[0] ?? 0; |
| | 63 | const minor = parts[1] ?? 0; |
| | 64 | const supported = (major === 22 && minor >= 16) || (major === 23 && minor >= 11) || major >= 24; |
| | 65 | |
| | 66 | if (!supported) { |
| | 67 | return Effect.die( |
| | 68 | `Node.js ${process.versions.node} is missing required node:sqlite APIs ` + |
| | 69 | `(StatementSync.columns). Upgrade to Node.js >=22.16, >=23.11, or >=24.`, |
| | 70 | ); |
| | 71 | } |
| | 72 | return Effect.void; |
| | 73 | }; |
| | 74 | |
| 53 | const makeWithDatabase = ( | 75 | const makeWithDatabase = ( |
| 54 | options: SqliteClientConfig, | 76 | options: SqliteClientConfig, |
| 55 | openDatabase: () => DatabaseSync, | 77 | openDatabase: () => DatabaseSync, |
| 56 | ): Effect.Effect<Client.SqlClient, never, Scope.Scope | Reactivity.Reactivity> => | 78 | ): Effect.Effect<Client.SqlClient, never, Scope.Scope | Reactivity.Reactivity> => |
| 57 | Effect.gen(function* () { | 79 | Effect.gen(function* () { |
| | 80 | yield* checkNodeSqliteCompat(); |
| | 81 | |
| 58 | const compiler = Statement.makeCompilerSqlite(options.transformQueryNames); | 82 | const compiler = Statement.makeCompilerSqlite(options.transformQueryNames); |
| 59 | const transformRows = options.transformResultNames | 83 | const transformRows = options.transformResultNames |
| 60 | ? Statement.defaultTransforms(options.transformResultNames).array | 84 | ? Statement.defaultTransforms(options.transformResultNames).array |