tursodatabase / libsql-js

A better-sqlite3 compatible API for libSQL that supports Bun, Deno, and Node
MIT License
192 stars 22 forks source link

Remote example is not working #53

Open penberg opened 11 months ago

penberg commented 11 months ago

Looks like missing execute_batch() in the libSQL remote protocol implementation:

penberg@vonneumann libsql-js % node examples/remote/example.js
thread '<unnamed>' panicked at 'not yet implemented', /Users/penberg/.cargo/git/checkouts/libsql-00c15cfa15b9f13b/c032b9f/libsql/src/hrana/mod.rs:277:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
zsh: abort      node examples/remote/example.js
GrantBirki commented 7 months ago

@penberg any follow ups to this?

I am doing the following and it is not working:

  1. Spin up a simple libsql-server and inject sample data into it

    curl -d '{"statements": ["CREATE TABLE IF NOT EXISTS users (username)", "INSERT INTO users VALUES (\"alice\")"]}' 127.0.0.1:8082
  2. Wrote a dead simple JS script to pull data from the table I created in step 1

    // script called libsql_testing.js
    const Database = require('libsql');
    
    const url = process.env.LIBSQL_URL;
    // const authToken = process.env.LIBSQL_AUTH_TOKEN;
    
    // const opts = {
    //   authToken: authToken,
    // };
    
    const opts = {};
    
    const db = new Database(url, opts);
    const row = db.prepare("SELECT * FROM users").get();
    console.log(row);
  3. I am greeted with the following error when running node libsql_testing.js

    $ node libsql_testing.js
    
    /app/node_modules/libsql/index.js:104
          throw new SqliteError(err.message, err.code, err.rawCode);
          ^
    SqliteError: no such table: users
        at Database.prepare (/app/node_modules/libsql/index.js:104:13)
        at Object.<anonymous> (/app/libsql_testing.js:13:16)
        at Module._compile (node:internal/modules/cjs/loader:1218:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
        at Module.load (node:internal/modules/cjs/loader:1081:32)
        at Module._load (node:internal/modules/cjs/loader:922:12)
        at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12)
        at node:internal/main/run_main_module:23:47 {
      code: 'SQLITE_ERROR',
      rawCode: 1
    }
    
    Node.js v19.3.0

I am not sure how to proceed as my setup could not be any simpler and this library is not working with the libsql project which it was designed upon