A tool to make interactions with sqlite databases easier
Kind: global class
- SQLiteHelper
- new SQLiteHelper([options])
- .get(columnName, columnValue) ⇒
* - .getAll() ⇒
object - .set(options) ⇒
object|boolean - .has(columnName, columnValue) ⇒
boolean - .ensure(columnName, columnValue, ensureValue) ⇒
* - .delete(columnName, columnValue) ⇒
number - .uncache([columnName], [columnValue]) ⇒
boolean
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | object |
{} |
Options for SQLite. |
| [options.tableName] | string |
"database" |
Name of the table which SQLite should use. |
| [options.dir] | string |
"./data" |
Directory where the sqlite file is/will be located. |
| [options.filename] | string |
"sqlite.db" |
Name of the file where the sqlite database is/should be saved. Note: You cannot work with multiple tables in one SQLite, you should create a separate SQLite for that. |
| [options.columns] | object |
{} |
Columns that should be created on the table if it doesn't exist. |
| [options.caching] | boolean |
true |
Toggle whether to enable caching. |
| [options.fetchAll] | boolean |
false |
Whether to fetch all rows of the sqlite database on initialization. Note: This option cannot be set to true if options.caching is true. |
| [options.wal] | boolean |
false |
Whether to enable wal mode. (Read more about that here) |
Example
const db = new SQLite({
tableName: "foods",
columns: {
name: "text",
price: "int"
},
wal: true
});Kind: instance method of SQLiteHelper
Returns: * - Value retreived from the table.
| Param | Type | Description |
|---|---|---|
| columnName | string |
Name of the column to search by. |
| columnValue | * |
Value of the column to search by. |
Kind: instance method of SQLiteHelper
Returns: object - All rows of the table.
Kind: instance method of SQLiteHelper
Returns: object | boolean - New column values of the row or false if no rows were modified.
NOTE: If caching is not enabled, only changed column values will be returned.
| Param | Type | Description |
|---|---|---|
| options | array.<object> | object |
|
| [options.where] | object |
Column parameters which should be used to search rows by. If not provided, a new row will be inserted. |
| options.columns | object |
Columns to insert/modify. |
Example
sqlite.set({
where: {
first_name: 'Josh',
last_name: 'Smith'
},
columns: {
last_name: 'Jonas'
}
})Kind: instance method of SQLiteHelper
Returns: boolean - Whether a row with the provided column name and value exists.
| Param | Type | Description |
|---|---|---|
| columnName | string |
Name of the column to search by. |
| columnValue | * |
Value of the column to search by. |
Ensures that a value exists in the table
Kind: instance method of SQLiteHelper
Returns: * - Ensured value
| Param | Type | Description |
|---|---|---|
| columnName | string |
Name of the column to search by. |
| columnValue | * |
Value of the column to search by. |
| ensureValue | object |
Value of the columns to be ensured if the row does not exist. |
Deletes a single or multiple rows from the table.
Kind: instance method of SQLiteHelper
Returns: number - Number of rows that were deleted.
| Param | Type | Description |
|---|---|---|
| columnName | string |
Name of the column to search by. |
| columnValue | * |
Value of the column to search by. |
Removes a single value (or all values if no arguments are provided) from the cache.
Kind: instance method of SQLiteHelper
Returns: boolean - Whether the deletion was successful.
| Param | Type | Description |
|---|---|---|
| [columnName] | string |
Name of the column to search by. |
| [columnValue] | * |
Value of the column to search by. |