Skip to content

Latest commit

 

History

History
135 lines (106 loc) · 5.78 KB

File metadata and controls

135 lines (106 loc) · 5.78 KB

SQLiteHelper

A tool to make interactions with sqlite databases easier

Kind: global class

new SQLiteHelper([options])

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
});

sqLiteHelper.get(columnName, columnValue) ⇒ *

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.

sqLiteHelper.getAll() ⇒ object

Kind: instance method of SQLiteHelper
Returns: object - All rows of the table.

sqLiteHelper.set(options) ⇒ object | boolean

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'
    }
})

sqLiteHelper.has(columnName, columnValue) ⇒ boolean

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.

sqLiteHelper.ensure(columnName, columnValue, ensureValue) ⇒ *

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.

sqLiteHelper.delete(columnName, columnValue) ⇒ number

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.

sqLiteHelper.uncache([columnName], [columnValue]) ⇒ boolean

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.