Database

Moduleejs.db
Namespace"ejs.db"
Definition class Database
InheritanceDatabase inherit Object

SQLite database support.


Properties

QualifiersPropertyTypeDescription
public static const DatatypeToSqliteObject 
public static const SqliteToDatatypeObject 
public static const SqliteToEjsObject 

Database Methods

QualifiersMethod
public addColumn(table: String, column: String, datatype: String, options: Object): Void
public addIndex(table: String, column: String, indexName: String): Void
public changeColumn(table: String, column: String, datatype: String, options: Object): Void
public close(): Void
 Close the database connection.
public connect(connectionString: String): Void
 Reconnect to the database using a new connection string.
public get connection(): String
 Get the database connection string.
public createDatabase(name: String, options: Object): Void
public createTable(table: String, columns: Array): Void
Database(connectionString: String)
 Initialize a SQLite database connection using the supplied database connection string.
public static set defaultDatabase(db: Database): Void
 Set the default database for the application.
public static get defaultDatabase(): Database
 Get the default database for the application.
public destroyDatabase(name: String): Void
public destroyTable(table: String): Void
public getColumns(table: String): Array
public getTables(): Array
 Return list of tables in a database.
public get name(): String
 Get the name of the database.
public query(cmd: String): Array
 Execute a SQL command on the database.
public removeColumns(table: String, columns: Array): Void
public removeIndex(table: String, indexName: String): Void
public renameColumn(table: String, oldColumn: String, newColumn: String): Void
public renameTable(oldTable: String, newTable: String): Void
public sql(cmd: String): Array
 Execute a SQL command on the database.
public static trace(on: Boolean): Void
 Trace SQL statements.

Method Detail

public addColumn(table: String, column: String, datatype: String, options: Object): Void

public addIndex(table: String, column: String, indexName: String): Void

public changeColumn(table: String, column: String, datatype: String, options: Object): Void

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 connect(connectionString: String): Void

Reconnect to the database using a new connection string.

Parameters
connectionString: String See Database() for information about connection string formats.

get public connection(): String

Get the database connection string.


public createDatabase(name: String, options: Object): Void

public createTable(table: String, columns: Array): Void

Database(connectionString: String)

Initialize a SQLite database connection using the supplied database connection string.

Parameters
connectionString: String Connection string stipulating how to connect to the database. The format is one of the following forms:
  • filename
In the future, connection strings will support other databases using a format a format like:
  • adapter://host/database/username/password
  • filename

static set public defaultDatabase(db: Database): Void

Set the default database for the application.

Parameters

static get public defaultDatabase(): Database

Get the default database for the application.

Returns
The default database defined via the $defaultDatabase setter method.

public destroyDatabase(name: String): Void

public destroyTable(table: String): Void

public getColumns(table: String): Array

public getTables(): Array

Return list of tables in a database.

Returns
An array containing list of table names present in the currently opened database.

get public name(): String

Get the name of the database.

Returns
The database name defined via the connection string.

public query(cmd: String): Array

Execute a SQL command on the database.

Parameters
Returns
An array of row results where each row is represented by an Object hash containing the column names and values.

public removeColumns(table: String, columns: Array): Void

public removeIndex(table: String, indexName: String): Void

public renameColumn(table: String, oldColumn: String, newColumn: String): Void

public renameTable(oldTable: String, newTable: String): Void

public sql(cmd: String): Array

Execute a SQL command on the database.

Description
This is a low level SQL command interface that bypasses logging. Use.
Parameters
Returns
An array of row results where each row is represented by an Object hash containing the column names and values.

static public trace(on: Boolean): Void

Trace SQL statements.

Description
Control whether trace is enabled for the actual SQL statements issued against the database.
Parameters
on: Boolean If true, display each SQL statement to the log