tursodatabase / libsql-client-ts

TypeScript/JavaScript client API for libSQL
https://docs.turso.tech/sdk/ts/quickstart
MIT License
226 stars 32 forks source link

Excecute only runs the first statement #132

Open pdenapo opened 10 months ago

pdenapo commented 10 months ago

Consider the following code

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

const file_name = process.cwd() + "/test.db";
const db_url = "file:" + file_name;

const db_client = createClient({
  url: db_url,
});

const rs = await db_client.execute(
  "CREATE TABLE a(a1 integer); CREATE TABLE b(b1 integer);"
);
console.log(rs);

Only the table a is created. The second create statement is silently ignored.

This is different from what better-sqlite3 does. Supporting multiple statements would be useful for reading sql statements form a file as in the example at

https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#execstring---this

const migration = fs.readFileSync('migrate-schema.sql', 'utf8');
db.exec(migration);
pdenapo commented 10 months ago

I have found that the code works by replacing excecute by executeMultiple. I think that this API difference is annoying and error-prone (if you won't output any error when multiple statements are in the input string).