dal-lite
v0.1.1
Published
A lightweight database abstraction layer
Readme
dal-lite
Modules
dals/sqlite3
dals/sqlite3~SqliteDal ⇐ Dal
DAL that connects to sqlite3 databases
Kind: inner class of dals/sqlite3
Extends: Dal
See: module:index~Dal
- ~SqliteDal ⇐ Dal
sqliteDal.type
Kind: instance property of SqliteDal
See: module:index.Dal#type
sqliteDal.connect()
Kind: instance method of SqliteDal
See: Dal.connect
sqliteDal.tableExists()
Kind: instance method of SqliteDal
See: Dal.tableExists
sqliteDal.createTable()
Kind: instance method of SqliteDal
See: Dal.createTable
sqliteDal.dropTable()
Kind: instance method of SqliteDal
See: Dal.dropTable
sqliteDal.exec()
Kind: instance method of SqliteDal
See: Dal.exec
sqliteDal.query()
Kind: instance method of SqliteDal
See: Dal.query
sqliteDal.quoteIdentifier()
Kind: instance method of SqliteDal
See: Dal.quoteIdentifier
sqliteDal.quoteValue()
Kind: instance method of SqliteDal
See: Dal.quoteValue
sqliteDal.insert()
Kind: instance method of SqliteDal
See: Dal.insert
sqliteDal.update()
Kind: instance method of SqliteDal
See: Dal.update
sqliteDal.select()
Kind: instance method of SqliteDal
See: Dal.select
sqliteDal.delete()
Kind: instance method of SqliteDal
See: Dal.delete
sqliteDal.close()
Kind: instance method of SqliteDal
See: Dal.close
index
- index
- ~Dal
- new Dal(uri, [_options])
- instance
- .type ⇒ string
- .connect([_options]) ⇒ Promise
- .tableExists(table, [_options]) ⇒ Promise
- .createTable(table, tableDef, [_options]) ⇒ Promise
- .alterTable(table, defChanges, [_options]) ⇒ Promise
- .dropTable(table, [_options]) ⇒ Promise
- .quoteIdentifier(name, [_options]) ⇒ string
- .quoteValue(value, type, [_options]) ⇒ string
- .exec(sql, [_options]) ⇒ Promise
- .query(sql, [_options]) ⇒ Promise
- .insert(into, values, [_options]) ⇒ Promise
- .update(table, changes, [_options]) ⇒ Promise
- .select(columns, from, [_options]) ⇒ Promise
- .delete(from, [_options]) ⇒ Promise
- .applyDataDefinition(def, [_options]) ⇒ Promise
- .close() ⇒ Promise
- static
- .getDal(uri, [_options]) ⇒ Dal
- ~TableSpec : string | object | Array.<string>
- ~ColumnDef : object
- ~PrimaryKeyDef : string | Array.<string>
- ~ForeignKeyDef : object
- ~TableDef : object
- ~IndexDef : object
- ~ViewDef : object
- ~DataDef : object
- ~ChangeDef : object
- ~Dal
index~Dal
Abstract class that selects a DAL for a given connection string (URI) via @function getDal
Kind: inner class of index
- ~Dal
- new Dal(uri, [_options])
- instance
- .type ⇒ string
- .connect([_options]) ⇒ Promise
- .tableExists(table, [_options]) ⇒ Promise
- .createTable(table, tableDef, [_options]) ⇒ Promise
- .alterTable(table, defChanges, [_options]) ⇒ Promise
- .dropTable(table, [_options]) ⇒ Promise
- .quoteIdentifier(name, [_options]) ⇒ string
- .quoteValue(value, type, [_options]) ⇒ string
- .exec(sql, [_options]) ⇒ Promise
- .query(sql, [_options]) ⇒ Promise
- .insert(into, values, [_options]) ⇒ Promise
- .update(table, changes, [_options]) ⇒ Promise
- .select(columns, from, [_options]) ⇒ Promise
- .delete(from, [_options]) ⇒ Promise
- .applyDataDefinition(def, [_options]) ⇒ Promise
- .close() ⇒ Promise
- static
- .getDal(uri, [_options]) ⇒ Dal
new Dal(uri, [_options])
| Param | Type | Description | | --- | --- | --- | | uri | string | Connection string used to attach to the database | | [_options] | object | Options |
dal.type ⇒ string
Gets the underlying DAL type of this DAL
Kind: instance abstract property of Dal
Returns: string - The underlying DAL type
dal.connect([_options]) ⇒ Promise
Connects the specified database. This is only necessary if you specified connect=false in the options to getDal
Kind: instance abstract method of Dal
| Param | Type | Description | | --- | --- | --- | | [_options] | object | Options |
dal.tableExists(table, [_options]) ⇒ Promise
Checks if a table exists
Kind: instance abstract method of Dal
| Param | Type | Description | | --- | --- | --- | | table | TableSpec | Table specifier | | [_options] | object | Options |
dal.createTable(table, tableDef, [_options]) ⇒ Promise
Creates a table from a given table definition
Kind: instance abstract method of Dal
| Param | Type | Description | | --- | --- | --- | | table | TableSpec | Table specifier TableSpec | | tableDef | TableDef | Table definition | | [_options] | object | Options |
dal.alterTable(table, defChanges, [_options]) ⇒ Promise
Alters an existing table to match a given table definition
Kind: instance abstract method of Dal
Returns: Promise - Promise that resolves when table is altered or rejects for errors
| Param | Type | Description | | --- | --- | --- | | table | TableSpec | Table specifier | | defChanges | object | Changes to apply to table | | [_options] | object | Options |
dal.dropTable(table, [_options]) ⇒ Promise
Kind: instance abstract method of Dal
Returns: Promise - Promise that resolves for successful table drop or rejects for errors
| Param | Type | Description | | --- | --- | --- | | table | TableSpec | Table specifier | | [_options] | object | Options |
dal.quoteIdentifier(name, [_options]) ⇒ string
Quotes a given identifier (e.g. table, column name)
Kind: instance abstract method of Dal
Returns: string - Quoted name
| Param | Type | Description | | --- | --- | --- | | name | string | | | [_options] | object | Options |
dal.quoteValue(value, type, [_options]) ⇒ string
Quotes a given value according to a specified type
Kind: instance abstract method of Dal
Returns: string - Quoted value
| Param | Type | Description | | --- | --- | --- | | value | * | | | type | string | | | [_options] | object | Options |
dal.exec(sql, [_options]) ⇒ Promise
Executes a given SQL query that does not return data
Kind: instance abstract method of Dal
Returns: Promise - Promise that will resolve with no data or reject
| Param | Type | Description | | --- | --- | --- | | sql | string | The query | | [_options] | object | Options |
dal.query(sql, [_options]) ⇒ Promise
Run a query that returns data from the database.
Kind: instance abstract method of Dal
Returns: Promise - Promise that resolves with data or rejects
| Param | Type | Description | | --- | --- | --- | | sql | string | The query | | [_options] | object | Options |
dal.insert(into, values, [_options]) ⇒ Promise
Insert data into the database.
Kind: instance abstract method of Dal
Returns: Promise - Promise that resolves for a successful insert or rejects
| Param | Type | Description | | --- | --- | --- | | into | TableSpec | Table specifier | | values | object | Array.<object> | Array or singular column to value map (object where keys are the column name and the values are the values for the column). | | [_options] | object | Options |
dal.update(table, changes, [_options]) ⇒ Promise
Update data within the database.
Kind: instance abstract method of Dal
Returns: Promise - Promise that resolves for a successful update or rejects
| Param | Type | Default | Description | | --- | --- | --- | --- | | table | TableSpec | | Table specifier | | changes | Array.<ChangeDef> | | | | [_options] | object | | Options | | _options.where | string | | Where clause |
dal.select(columns, from, [_options]) ⇒ Promise
Select data from the database
Kind: instance abstract method of Dal
Returns: Promise - Promise that resolves with returned data or rejects
| Param | Type | Description | | --- | --- | --- | | columns | Array.<string> | | | from | TableSpec | Table specifier | | [_options] | object | Options | | _options.where | string | Where clause | | _options.groupBy | string | Group by clause | | _options.orderBy | string | Order by clause | | _options.limit.limit | number | Limit results to this value | | _options.limit.offset | number | Offset results by this value |
dal.delete(from, [_options]) ⇒ Promise
Delete data from the database.
Kind: instance abstract method of Dal
Returns: Promise - Promise that resolves with a successful delete or rejects
| Param | Type | Description | | --- | --- | --- | | from | TableSpec | Table specifier TODO joins, etc. | | [_options] | object | Options | | _options.where | string | Where clause |
dal.applyDataDefinition(def, [_options]) ⇒ Promise
Uses a DataDef to specify a desired database schema state.
Kind: instance method of Dal
Returns: Promise - Promise that resolves for successful application or rejects
| Param | Type | Description | | --- | --- | --- | | def | DataDef | DataDef describing the expected state of the database | | [_options] | object | Options |
dal.close() ⇒ Promise
Closes the connection to the database. The instance should not be used after this.
Kind: instance abstract method of Dal
Returns: Promise - Promise that resolves when the connection is closed or rejects for errors
Dal.getDal(uri, [_options]) ⇒ Dal
Given a connection string (URI) chooses a matching subclass of Dal that implements that database dialect and instantiates it
Kind: static method of Dal
Returns: Dal - The subclass of Dal for the database type specified by the uri
| Param | Type | Description | | --- | --- | --- | | uri | string | Connection string/URI | | [_options] | object | Options | | [_options.connect] | boolean | Auto-connect to the database. Defaults to true. |
index~TableSpec : string | object | Array.<string>
Table specifier. Can be a string, an array or an object. If a string, the simple (no schema) name of the table. If an array, it must have a length of 2; the first element is the schema, the second element is the table name. If an object, it must have a property tableName that is the name of the table and an optional property schema that is the name of the schema.
Kind: inner typedef of index
Properties
| Name | Type | Description | | --- | --- | --- | | table | string | The table name | | schema | string | The table schema |
index~ColumnDef : object
Column definition.
Kind: inner typedef of index
Properties
| Name | Type | Description | | --- | --- | --- | | type | string | Type of the column (based on types compatible with underlying DAL) | | [notNull] | boolean | True if column can contain NULL values. Defaults to false. |
index~PrimaryKeyDef : string | Array.<string>
Primary key definition. Can be a column name or an array of column names.
Kind: inner typedef of index
index~ForeignKeyDef : object
Foreign key definition.
Kind: inner typedef of index
Properties
| Name | Type | Description | | --- | --- | --- | | columns | string | Array.<string> | Array of column names or string of a singular column name | | references | object | Definition of the target the column references. | | references.table | string | Name of the table referenced. | | references.columns | string | Array.<string> | Names of the columns or singular name referenced by this foreign key. Should match up with .columns |
index~TableDef : object
Table definition.
Kind: inner typedef of index
Properties
| Name | Type | Description | | --- | --- | --- | | columns | Object.<string, ColumnDef> | Object keyed with column names mapping to ColumnDefs | | [primaryKey] | PrimaryKeyDef | Primary key definition | | [foreignKeys] | Array.<ForeignKeyDef> | Definitions of foreign keys within the table |
index~IndexDef : object
Index definition.
Kind: inner typedef of index
index~ViewDef : object
View definition.
Kind: inner typedef of index
index~DataDef : object
Database schema definition.
Kind: inner typedef of index
Properties
| Name | Type | Description | | --- | --- | --- | | tables | Array.<TableDef> | The individual TableDefs | | indexes | Array.<IndexDef> | The individual IndexDefs | | views | Array.<ViewDef> | The individual ViewDefs |
index~ChangeDef : object
Change to apply to a table's data
Kind: inner typedef of index
Properties
| Name | Type | Description | | --- | --- | --- | | column | string | The column to update | | value | * | The new value of the column |
