Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript client can't insert into FTS5 tables #1811

Open
abdurahmanshiine opened this issue Nov 12, 2024 · 0 comments
Open

Typescript client can't insert into FTS5 tables #1811

abdurahmanshiine opened this issue Nov 12, 2024 · 0 comments

Comments

@abdurahmanshiine
Copy link

abdurahmanshiine commented Nov 12, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant