Finally, in (6), we create a select prepared statement and then run it with query.all(), outputting the results to the console:
$ node –experimental-sqlite physicists.mjs
[
{
id: 1,
name: ‘Albert Einstein’,
quote: “I believe in Spinoza’s God”
},
{
id: 2,
name: ‘Marie Curie’,
quote: ‘Nothing in life is to be feared, it is only to be understood’
},
{
id: 3,
name: ‘Richard Feynman’,
quote: ‘Nobody understands quantum mechanics.’
}
]
If we want to save the table to disk, we can change the database parameter to a filename where the data will be stored:
const database = new DatabaseSync(‘myFile.db’);
With that simple change, we have a persistent mechanism for sharing data across different processes and programs. If we run our earlier example with this configuration, we will see the myFilename.db file on disk: