| 1 | import { assert, describe, it } from "@effect/vitest" |
| 2 | import { Effect } from "effect" |
| 3 | import { Reactivity } from "effect/reactivity" |
| 4 | import { vi } from "vitest" |
| 5 | |
| 6 | const state = vi.hoisted(() => ({ |
| 7 | database: { |
| 8 | close() {}, |
| 9 | execute: async () => ({ rowsAffected: 0, rows: [{ value: 1 }] }), |
| 10 | executeRaw: async () => ({ rowsAffected: 0, rawRows: [[1]], columnNames: ["value"] }), |
| 11 | executeRawSync: () => ({ rowsAffected: 0, rawRows: [[1]], columnNames: ["value"] }), |
| 12 | executeSync: () => ({ rowsAffected: 0, rows: [{ value: 1 }] }) |
| 13 | } |
| 14 | })) |
| 15 | |
| 16 | vi.mock("@op-engineering/op-sqlite", () => ({ |
| 17 | open: () => state.database |
| 18 | })) |
| 19 | |
| 20 | import { SqliteClient } from "@effect/sql-sqlite-react-native" |
| 21 | |
| 22 | describe("Client", () => { |
| 23 | it.effect("should work", () => Effect.void) |
| 24 | |
| 25 | it.effect("returns array rows from synchronous values queries", () => |
| 26 | Effect.gen(function*() { |
| 27 | const sql = yield* SqliteClient.make({ filename: "test.db" }) |
| 28 | const rows = yield* sql`SELECT 1 AS value`.values |
| 29 | const unpreparedRows = yield* sql`SELECT 1 AS value`.valuesUnprepared |
| 30 | assert.deepStrictEqual(rows, [[1]]) |
| 31 | assert.deepStrictEqual(unpreparedRows, [[1]]) |
| 32 | }).pipe(Effect.provide(Reactivity.layer))) |
| 33 | |
| 34 | it.effect("returns array rows from asynchronous values queries", () => |
| 35 | Effect.gen(function*() { |
| 36 | const sql = yield* SqliteClient.make({ filename: "test.db" }) |
| 37 | const rows = yield* SqliteClient.withAsyncQuery(sql`SELECT 1 AS value`.values) |
| 38 | const unpreparedRows = yield* SqliteClient.withAsyncQuery(sql`SELECT 1 AS value`.valuesUnprepared) |
| 39 | assert.deepStrictEqual(rows, [[1]]) |
| 40 | assert.deepStrictEqual(unpreparedRows, [[1]]) |
| 41 | }).pipe(Effect.provide(Reactivity.layer))) |
| 42 | }) |