dyedgreen / deno-sqlite

Deno SQLite module
https://deno.land/x/sqlite
MIT License
409 stars 36 forks source link

error reading local database #225

Closed navtoj closed 1 year ago

navtoj commented 1 year ago
Console
error: Uncaught SqliteError: file is not a database
      throw new SqliteError(this.#wasm);
            ^
    at DB.prepareQuery (https://deno.land/x/sqlite@v3.7.0/src/db.ts:366:13)
    at DB.query (https://deno.land/x/sqlite@v3.7.0/src/db.ts:258:24)
    at file:///Users/navtoj/Developer/raycast/scripts/get-text-code.ts:51:26
Editor
// deno run --allow-all script.ts
import { DB } from 'https://deno.land/x/sqlite@v3.7.0/mod.ts';

// set the path to the database
const dbPath = `/var/folders/8w/3px3xm390bn_452_tps27bs00000gn/0/com.apple.notificationcenter/db2/db`;

// open the database
const db = new DB(dbPath);

// get the most recent unread inbound text message
const result = await db.query(
    `SELECT
        record.data
    FROM
        app
    INNER JOIN
        record
    ON
        app.app_id = record.app_id
    WHERE
        app.identifier = "com.tunabelly.androidsms"
    ORDER BY
        record.delivered_date
    DESC LIMIT
        1`
);

// print result to console
console.log(result);
file /var/folders/8w/.../0/com.apple.notificationcenter/db2/db
/var/folders/8w/.../0/com.apple.notificationcenter/db2/db: SQLite 3.x database, 
last written using SQLite version 3037000, writer version 2, read version 2, 
file counter 298, database pages 50, 1st free page 21, free pages 27, 
cookie 0x9, schema 4, UTF-8, version-valid-for 298
dyedgreen commented 1 year ago

Does the database use WAL journal mode?

navtoj commented 1 year ago

Does the database use WAL journal mode?

@dyedgreen Yes, it does.

dyedgreen commented 1 year ago

WAL Mode is unfortunately not properly supported at this time, since it requires mmapped files which we don’t have in deno.