SQLite operation based on sql.js
.
$ npm install sync-sqlite
var options = {
dbPath: './test.db',
autoSave: true
};
var SQLite = require('sync-sqlite');
var db = new SQLite(options);
Connect and open database. If the target dbPath doesn't exist, it will be created automatically.
Set what table you want to operate.
tables: Table name, one table use string, more than one use array
Create a new data table in current database.
table: Table name
fields: Fields list(array)
Clear all data in the table and reset index.
table: Table name
Delete the table.
table: Table name
Append fields to the table.
table: Table name
fields: Fields list(array)
Query data, return a RecordSet object.
tables: Table name, string or array(more than one table)
fields: Fields, string or array
where: Optional, query condition
orders: Optional, order by
limit: Optional, query count
Query data, return a RecordSet object.
Insert data, return a JSON object. ar
means the affected rows, id
means the inserted id.
tables: Table name, string or array(more than one table)
fields: Fields, json object(key is field name, value is field value).
Insert data, return a JSON object. ar
means the affected rows, id
means the inserted id.
Update data, return a JSON object. ar
means the affected rows.
tables: Table name, string or array(more than one table)
fields: Fields, json object(key is field name, value is field value).
where: Optional, query condition
Update data, return a JSON object. ar
means the affected rows.
Remove data, return a JSON object. ar
means the affected rows.
tables: Table name, string or array(more than one table)
fields: Fields, string or array
where: Optional, query condition
orders: Optional, order by
limit: Optional, query count
Remove data, return a JSON object. ar
means the affected rows.
Execute sql string, the return values are the same as above.
Execute sql string, the return values are:
If not query, return undefined.
If query, return an array contains the query result.
Pagination query.
sql: The query sql string pageIndex: Page index, start from 1 pageSize: Record count per page
Get all table and fields information.
Get all fields information.
table: Table name
Get sqlite database version, such as 3.11.0
。
The query operation will return RecordSet object.
Convert query result to JSON. If you specify the index, it will return a json at the index, otherwise return the whole array, if no data, return null.
Convert query result to Array. If you specify the index, it will return a array at the index, otherwise return the whole array, if no data, return empty array.
Loop the query result.
Loop the query result.
Please check the examples directory to get more idea.
MIT