sqlite-model
Extend this class to easily create your data models based on sqlite3
Install
npm install sqlite-model
Usage example
This library provides a base class with the basics method to access a SQLite database and promisified statement.
The easiest way to use the class, is extending it when implementing your model class.
To show it, we are going to implement a small model to get and set jsonified values, which will use the following data definition and SQL queries:
-- table definitionCREATE TABLE IF NOT EXISTS example key text NOT NULL PRIMARY KEY, value text NOT NULL,; -- query to set dataINSERT INTO example VALUES?, ?); -- query to get dataSELECT value FROM example WHERE key = ?; -- if the value already exists, update itUPDATE example SET value = ? WHERE key = ?;
The implementation for this model would be the following one:
; ;
And that's all.
As you can see, with this class as a base, you only need to implement the logic of your model without worrying about database operations, preparing statements or dirty old-styled callbacks returned by the statement functions.