Excecute only runs the first statement
pdenapo opened this issue · comments
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);
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).