denodrivers / sqlite3

The fastest and correct SQLite3 module for Deno runtime
https://jsr.io/@db/sqlite
Apache License 2.0
265 stars 22 forks source link

Error: Uncaught TypeError: Invalid ffi #42

Closed Bartvelp closed 2 years ago

Bartvelp commented 2 years ago

Hi,

I'd like to use this library over the WASM based one so I can use WAL mode. Unfortunately the example code already fails for me with the error:

error: Uncaught TypeError: Invalid ffi arg value, expected TypedArray, UnsafePointer or null
  const result = lib.sqlite3_prepare_v2(
                     ^
    at prepareArgs (deno:ext/ffi/00_ffi.js:170:17)
    at Object.fn [as sqlite3_prepare_v2] (deno:ext/ffi/00_ffi.js:302:43)
    at sqlite3_prepare_v2 (https://deno.land/x/sqlite3@0.4.3/src/ffi.ts:499:22)
    at Database.prepare (https://deno.land/x/sqlite3@0.4.3/src/database.ts:222:20)
    at Database.queryArray (https://deno.land/x/sqlite3@0.4.3/src/database.ts:267:23)
    at file:///home/<snipped>/use-deno-driver.ts:5:22

it does create an empty test.db file. I use the so file from libsqlite3-dev, but I tried another one and had the same problem.

I use this to execute:

[12:53] bart@host:~$ uname -a
Linux host 5.10.0-17-amd64 #1 SMP Debian 5.10.136-1 (2022-08-13) x86_64 GNU/Linux
[12:53] bart@host:~$ deno --version
deno 1.23.0 (release, x86_64-unknown-linux-gnu)
v8 10.4.132.5
typescript 4.7.2
[12:53] bart@host:~$ deno run -A --allow-ffi --unstable use-deno-driver.ts 

What could be the cause of this error and what am I doing wrong?

example code: ```typescript import { Database } from "https://deno.land/x/sqlite3@0.4.3/mod.ts"; const db = new Database("test.db"); const [version] = db.queryArray("select sqlite_version()")[0]; console.log(version); db.close(); ```
DjDeveloperr commented 2 years ago

Hi, this should be fixed in v0.4.4. Also make sure to use latest Deno version