dyedgreen / deno-sqlite

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

Add support for read-only databases #121

Closed dyedgreen closed 3 years ago

dyedgreen commented 3 years ago

Currently all databases are opened with read and write permissions by default, with no way to change this setting. We should provide a mechanism for setting the database type to read only, and supporting other SQLite database options.

Read only databases should only require deno read permissions, while write and create databases will still require read and write permissions. This will involve passing the flags through to sqlite3_open_v2, and then handling the flags we set in out custom VFS.

Proposed (backwards compatible) API change:

interface SqliteOpenOptions {
  mode?: "read" | "write" | "create";
  memory?: boolean;
  uri?: boolean;
}

const defaultOpenOptions = {
  mode: "create",
};

class DB {
  constructor(path: string = ":memory:", options?: SqliteOpenOptions) { ... }
}

Potential additional flags to support