SQLiteTable
SQLiteTable is a class that helps you deal with sqlite database. It's very simple and useful for small projects when you don't want any kind of ORM but also you don't wont to find yourself in writing simple queries over and over again.
SQLiteTable is written in TypeScript and it provides typings if you would like to use it with this language (which is recommended) hovewer you can use SQLiteTable with plain JavaScript also.
SQLiteTable is designed in OOP manner and it's best to inherit from it.
Installation
npm install sqlite-table
Example usage
var SQLiteTable = ;var sqlite3 = ; // UserTable class:var { SQLiteTable; thistableName = 'user';};UserTableprototype = Object; // example usagevar db = ':memory:';db;
API
get many records
public allnext:void:void;public allparams?:any, next?:void:void;
You can get many records using all
method. If you will not specify param
object then
you will get all the records.
You can specify params
object and set the search criteria. For example:
var db = ':memory:';var userTable = db; userTableallfirstName: 'Szymon' { /// users is an array of all the users with first name Szymon.};
limited get many records
public allLimitedwhere?:any, limit: = , next:void =:void;
var db = ':memory:';var userTable = db; userTable;
count
public countwhere:any = , next:void =:void;
save
public savedata:any, next:void:void;
if data.id
is set then update
method is invoked, otherwise insert
. next
callback receive
the saved record as a recult.
get one record
public findparams:string, next:void:void;public findparams:any, next:void:void;
Works same as all
method but returns only one record.
insert
public insertdata:any, next:void:void;
Insert data
into database. Second param of the next
callback function
will be an id
of the new record and data.id
property will be set.
update
public updatedata:any, next:void:void;
Update record by data.id
. The field: data.id
must be set, otherwise an error is thrown.
remove
public removeid:string, next:void:void;
Removes record by id.
Joins
If you want to do something with the record before retrieving it by find
or all
methods then you can implement the joins(record:any, done:(err:Error, record?:any)=>void):void
method.
LICENSE: ISC
ISC license is even simpler MIT like license. Check out the LICENSE file.