Skip to content

@effect/sql-sqlite-react-native silently fails with latest op-sqlite #5499

@subtleGradient

Description

@subtleGradient

What version of Effect is running?

@effect/[email protected] + @op-engineering/[email protected]

What steps can reproduce the bug?

import * as Reactivity from "@effect/experimental/Reactivity";
import * as RNSqlClient from "@effect/sql-sqlite-react-native/SqliteClient";
import * as Console from "effect/Console";
import * as Effect from "effect/Effect";

Effect.gen(function* () {
	const sql = yield* RNSqlClient.make({ filename: ":memory:" });
	yield* Console.log(`SELECT 123`, yield* sql`SELECT 123`);
})
	.pipe(Effect.provide(Reactivity.layer), Effect.scoped, Effect.runPromise)
	.catch(console.error);

What is the expected behavior?

LOG SELECT 123 [{"123": 123}]

What do you see instead?

LOG SELECT 123 []

Silent failure. No warnings. No errors.

Additional information

HYPOTHESIS: the API changed between @op-engineering/[email protected] – @op-engineering/[email protected]

"@op-engineering/op-sqlite": "7.1.0",

PROBLEM 1:

try: () => db.execute(sql, params as Array<any>).rows?._array ?? [],

  • db.execute is async, this should be db.executeSync
  • someRandomPromise.rows?._array will always be undefined

PROBLEM 2:

(result) => result.rows?._array ?? []

try: () => db.execute(sql, params as Array<any>).rows?._array ?? [],

  • there is no ._array field on .rows
  • this is the correct shape:

https://github.com/OP-Engineering/op-sqlite/blob/4089ec4c10afde73700a35d7bdf4056c4e11f555/src/types.ts#L9-L31

export type QueryResult = {
  insertId?: number;
  rowsAffected: number;
  res?: any[];
  rows: Array<Record<string, Scalar>>;
  // An array of intermediate results, just values without column names
  rawRows?: Scalar[][];
  columnNames?: string[];
  /**
   * Query metadata, available only for select query results
   */
  metadata?: ColumnMetadata[];
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions