dyedgreen / deno-sqlite

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

Add an api to write the DB to a file #232

Closed sigmaSd closed 1 year ago

sigmaSd commented 1 year ago

I'm using deno-sqlite, to open an in memory db that I populate with data, this works really well

But today it happened that I wanted to export this to sqlite file, is it possible to add an api to do that DB.writeToFile("mydb.sql") ?

dyedgreen commented 1 year ago

You can just get the underlying data using DB.serialize, and then write it using the Deno file system API.

sigmaSd commented 1 year ago

thanks @dyedgreen , one question

import { DB } from "https://deno.land/x/sqlite@v3.7.2/mod.ts";
const db = new DB(":memory:", { memory: true });
db.serialize("temp") //  Failed to serialize database 'temp'
db.serialize() // works

from the docs I thought that if I use the in memory database I have to use temp schema but that doesn't seem to be the case, I needed to use the main schema to serialize it