Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(sqlite): retry failed statement preparations #10584

Mergedyashranaway(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/10584/headmerged by shivamhwp(GitHub profile, opens in a new tab) View on GitHub

Showing 2 changed files with 53 additions and 3 deletions.

x
0 of 2 viewed, 2 left
48 additions and 0 deletionspackages/shared/src/nodeSqliteClient.test.tsModified
View file
@@ -1,6 +1,10 @@
+import * as NodeSqlite from "node:sqlite";
+import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
+import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
+import * as Path from "effect/Path";
import * as SqlClient from "effect/unstable/sql/SqlClient";
​
import * as SqliteClient from "./nodeSqliteClient.ts";
@@ -8,6 +12,21 @@
const layer = it.layer(SqliteClient.layer({ filename: ":memory:" }));
​
layer("NodeSqliteClient", (it) => {
+ it.effect("retries preparing a query after the missing schema becomes available", () =>
+ Effect.gen(function* () {
+ const sql = yield* SqlClient.SqlClient;
+ const select = sql<{ name: string }>`SELECT name FROM created_after_prepare_failure`;
+ const error = yield* select.pipe(Effect.flip);
+ assert.equal(error._tag, "SqlError");
+ assert.equal(error.reason.operation, "prepare");
+​
+ yield* sql`CREATE TABLE created_after_prepare_failure(name TEXT NOT NULL)`;
+ yield* sql`INSERT INTO created_after_prepare_failure VALUES ('recovered')`;
+ assert.deepEqual(yield* select, [{ name: "recovered" }]);
+ assert.deepEqual(yield* select.values, [["recovered"]]);
+ }),
+ );
+​