libsql icon indicating copy to clipboard operation
libsql copied to clipboard

Typescript client can't insert into FTS5 tables

Open abdurahmanshiine opened this issue 1 year ago • 1 comments

Hey there,

I'm trying to use the FTS5 extension with libsql, but the Typescript client is failing to insert anything into the table. Here is my code:

import { createClient } from "@libsql/client";

const client = createClient({
  url: Bun.env.TURSO_LOCAL_FILE as string,
  syncUrl: Bun.env.TURSO_DATABASE_URL as string,
  authToken: Bun.env.TURSO_AUTH_TOKEN as string,
});

const contents = await Bun.file(
  "./public/data.txt",
).text();

const chunks = contents.split("\n");

await client.execute(`DROP TABLE IF EXISTS docs;`);
await client.execute(
  `CREATE VIRTUAL TABLE IF NOT EXISTS docs USING fts5 (chunk);`,
);

let stms = [];
for (let i = 0; i < chunks.length; i++) {
  stms.push({
    sql: `
  INSERT INTO docs VALUES (:chunk);
  `,
    args: {
      chunk: chunks[i],
    },
  });
}

const results = await client.batch(stms, "write");
console.log(results.length);

client.close();

When I run this code, this is what I get:

thread '<unnamed>' panicked at src/statement.rs:360:62:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

But if I instead use an HTTP client like postman, it all works fine. Am I doing something wrong here?

abdurahmanshiine avatar Nov 12 '24 13:11 abdurahmanshiine

Did you get this resolved? I have the same problem when using an embedded database and doing inserts with arguments.

This works: await turso.execute("INSERT INTO users (name) VALUES ('name');");

This gives an error: await turso.execute({ sql: "INSERT INTO users (name) VALUES (:name);", args: { name: "name" }, });

gautema avatar Dec 03 '24 08:12 gautema

Same issue for me

fast-facts avatar Feb 10 '25 00:02 fast-facts

I am also experiencing this panic - here is the source code https://github.com/Makespace/members-app/blob/5a8b052587a07cdee2216b48aa8d470a4341f460/src/init-dependencies/google/get-cached-sheet-data.ts#L96

await dbClient.execute({
        sql: `
              INSERT INTO cached_sheet_data (cached_at, sheet_id, cached_data)
              VALUES ($cachedAt, $sheetId, $cachedData)
              ON CONFLICT (sheet_id) DO UPDATE SET
                cached_at = excluded.cached_at,
                cached_data = excluded.cached_data;
            `,
        args: {
          cachedAt: cacheTimestamp,
          sheetId,
          cachedData,
        },
      });

And the error

2025-02-15T17:26:55.474 app[148e200df35498] lhr [info] thread '<unnamed>' panicked at src/statement.rs:360:62:

2025-02-15T17:26:55.474 app[148e200df35498] lhr [info] called `Option::unwrap()` on a `None` value

2025-02-15T17:26:55.474 app[148e200df35498] lhr [info] stack backtrace:

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 0: 0x7f200b86a8be - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 1: 0x7f200b52768c - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 2: 0x7f200b83f6f2 - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 3: 0x7f200b86c16f - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 4: 0x7f200b86b978 - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 5: 0x7f200b86cabc - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 6: 0x7f200b86c488 - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 7: 0x7f200b86c416 - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 8: 0x7f200b86c403 - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 9: 0x7f200b496904 - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 10: 0x7f200b4969f2 - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 11: 0x7f200b496d45 - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 12: 0x7f200b51bb1e - <unknown>

2025-02-15T17:26:55.475 app[148e200df35498] lhr [info] 13: 0x7f200b4de14d - <unknown>

2025-02-15T17:26:55.491 app[148e200df35498] lhr [info] 14: 0xc51049 - _ZN6v8impl12_GLOBAL__N_123FunctionCallbackWrapper6InvokeERKN2v820FunctionCallbackInfoINS2_5ValueEEE

2025-02-15T17:26:55.491 app[148e200df35498] lhr [info] 15: 0xf57eaf - _ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE

2025-02-15T17:26:55.491 app[148e200df35498] lhr [info] 16: 0xf5871d - _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEENS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EEPmi

2025-02-15T17:26:55.491 app[148e200df35498] lhr [info] 17: 0xf58be5 - _ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE

2025-02-15T17:26:55.495 app[148e200df35498] lhr [info] 18: 0x1963df6 - Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit

This happens everytime and I can reliably recreate it

Lan2u avatar Feb 15 '25 17:02 Lan2u