DatabaseConnector
Module | ejs.db |
Definition | class DatabaseConnector |
Specified | ejscript-1.1 |
Stability | Evolving. |
Database interface connector.
This interface is implemented by database connectors such as SQLite.
Properties
Qualifiers | Property | Type | Description |
---|---|---|---|
No properties defined |
DatabaseConnector Methods
Qualifiers | Method |
---|---|
public | addColumn(table: String, column: String, datatype: String, options: Object = null): Void |
Add a column to a table.param options. | |
public | addIndex(table: String, column: String, index: String): Void |
Add an index on a column. | |
public | changeColumn(table: String, column: String, datatype: String, options: Object = null): Void |
Change a column.param options. | |
public | close(): Void |
Close the database connection. | |
public | commit(): Void |
Commit a database transaction. | |
public | createDatabase(name: String, options: Object = null): Void |
Create a new database.param options. | |
public | createTable(table: String, columns: Array = null): Void |
Create a new table.param columns. | |
public | dataTypeToSqlType(dataType: String): String |
Map the database independant data type to a database dependant SQL data type. | |
public | destroyDatabase(name: String): Void |
Destroy a database. | |
public | destroyTable(table: String): Void |
Destroy a table. | |
public | getColumns(table: String): Array |
Get column information. | |
public | getTables(): Array |
Return list of tables in a database. | |
public | removeColumns(table: String, columns: Array): Void |
Remove columns from a table. | |
public | removeIndex(table: String, index: String): Void |
Remove an index. | |
public | renameColumn(table: String, oldColumn: String, newColumn: String): Void |
Rename a column. | |
public | renameTable(oldTable: String, newTable: String): Void |
Rename a table. | |
public | sql(cmd: String): Array |
Execute a SQL command on the database. | |
public | sqlTypeToDataType(sqlType: String): String |
Map the SQL type to a database independant data type. | |
public | sqlTypeToEjsType(sqlType: String): String |
Map the SQL type to an Ejscript type class. | |
public | startTransaction(): Void |
Start a new database transaction. |
Method Detail
Add a column to a table.param options.
- Parameters
table: String Name of the table. column: String Name of the column to add. datatype: String Database independant type of the column. Valid types are: binary, boolean, date, datetime, decimal, float, integer, number, string, text, time and timestamp. options: Object Optional parameters. [default: null]
Change a column.param options.
- Parameters
table: String Name of the table holding the column. column: String Name of the column to change. datatype: String Database independant type of the column. Valid types are: binary, boolean, date, datetime, decimal, float, integer, number, string, text, time and timestamp. options: Object Optional parameters. [default: null]
public close(): Void
Close the database connection.
- Description
- Database connections should be closed when no longer needed rather than waiting for the garbage collector to automatically close the connection when disposing the database instance.
public commit(): Void
Commit a database transaction.
Map the database independant data type to a database dependant SQL data type.
- Parameters
dataType: String Data type to map.
- Returns
- The corresponding SQL database type.
Destroy a database.
- Parameters
name: String Name of the database to remove.
Destroy a table.
- Parameters
table: String Name of the table to destroy.
Get column information.
- Parameters
table: String Name of the table to examine.
- Returns
- An array of column data. This is database specific content and will vary depending on the database connector in use.
public getTables(): Array
Return list of tables in a database.
- Returns
- An array containing list of table names present in the currently opened database.
Execute a SQL command on the database.
- Description
- This is a low level SQL command interface that bypasses logging. Use.
- Parameters
cmd: String SQL command to issue. Note: "SELECT" is automatically prepended and ";" is appended for you.
- Returns
- An array of row results where each row is represented by an Object hash containing the column names and values.
Map the SQL type to a database independant data type.
- Parameters
sqlType: String SQL Data type to map.
- Returns
- The corresponding database independant type.
Map the SQL type to an Ejscript type class.
- Parameters
sqlType: String SQL Data type to map.
- Returns
- The corresponding type class.
public startTransaction(): Void
Start a new database transaction.