Skip to content

infinity.database

The infinity.database module provides access to relational databases. You can work with classic SQL queries (with parameters set by setParamValue()) and navigate through the results, or use the document store functions (create(), insert(), find(), get() and others), which store JSON documents in a table. The database access is based on UniDAC. Supported database providers are Advantage Database Server, Amazon Redshift, DB2, DBF, InterBase/Firebird, Microsoft Access, MongoDB, MySQL/MariaDB, ODBC, Oracle, PostgreSQL, SAP Sybase Adaptive Server Enterprise, SQL Server and SQLite (Microsoft Access, Advantage Database Server and DB2 only on Windows). The connection can be customized through the specificOptions property.

The document store functions (clear(), count(), create(), drop(), exists(), find(), get(), has(), index(), insert(), remove() and update()) generate MySQL/MariaDB-specific SQL (JSON functions, generated columns, information_schema) and are therefore intended for the mysql provider. Table names, column names and orderBy are quoted as MySQL identifiers (backticks), string values are escaped MySQL-style. A document table has the columns id (auto increment primary key) and json (the document without id); index() adds further columns for single document properties.

A database object holds one connection and one query (result set). Use one object per thread.

Module: infinity.database

Performance

For optimal database performance:

  • Use transactions for batch operations (100-200× speedup)
  • Use connection pooling (enabled by default, 5-10× latency reduction)
  • Use parameterized queries (prevents SQL injection, enables caching)

See Database Benchmarks for detailed performance metrics and Performance Best Practices for optimization guidelines.


Classes

database

The class for operations on databases in INFINITY.JS.

Example:

infinity.loadModule('infinity.database');

let myDB = new infinity.database();

try {
  //setting database-specific options
  myDB.specificOptions['UseUnicode'] = true;
  //connecting to the database
  myDB.connect(infinity.database.provider.mysql, 'localhost', 3306, 'exampleDB', 'root', 'secret');

  //creating a document table
  if (!myDB.exists('testTable')) {
    myDB.create('testTable');

    //creating index columns for document properties
    myDB.index('testTable', 'username', infinity.database.indexType.string, infinity.database.columnType.virtual, true);
    myDB.index('testTable', 'email', infinity.database.indexType.string);
    myDB.index('testTable', 'modified', infinity.database.indexType.int);
  }

  //inserting documents (note the different notations)
  myDB.insert('testTable', { "username": "TheUserName1", "email": "theusername@email.com", "rights": ["read", "write", "create", "delete"] });
  myDB.insert('testTable', { "username": "AnotherUserName2", "email": "someother@email.net", "rights": ["read"] });
  myDB.insert('testTable', { username: "aUserName3", email: "yetanother@email.com" });

  //reading from the table with a parameterized SQL query
  myDB.sql = 'SELECT id, username, email FROM testTable WHERE email LIKE :email';
  myDB.setParamValue('email', '%.com');
  myDB.execute();
  let result = myDB.result();
  console.debug(result);
  //[["id","username","email"],[1,"TheUserName1","theusername@email.com"],[3,"aUserName3","yetanother@email.com"]]

  //searching with infinity.database.find()
  let ids = myDB.find('testTable', [['email', 'endswith', 'm']], 'username', infinity.database.orderDirection.ascending, 0, 0, infinity.database.outputMode.ids);
  console.debug(ids);
  //[1,3]

  //replacing a document with infinity.database.update()
  myDB.update('testTable', { id: 2, username: "aUserName", email: "yetanother@email.com", modified: Math.floor(Date.now() * 0.001) });

  //reading two documents
  let twoRows = myDB.get('testTable', [1, 2]);
  console.debug(twoRows);
  //[{"email":"theusername@email.com","id":1,"rights":["read","write","create","delete"],"username":"TheUserName1"},{"email":"yetanother@email.com","id":2,"modified":1613741246,"username":"aUserName"}]

  myDB.disconnect();
} finally {
  myDB.free();
}

Properties


autoCommit

Type: boolean

Turns on or off auto-committing database modifications. Default is true.


connectionLifetime

Type: number

Specifies how long a pooled database connection may be used before it is closed and recreated. 0 (default) means unlimited. Must be set before connect().


fieldCount

Type: number

Gets the number of columns of the result set of the last execute() call (0 for statements that return no result set).


lastInsertId

Type: number

Gets the value of the auto increment ID field after an INSERT statement executed with execute().


maxPoolSize

Type: number

Gets or sets the maximum number of connections allowed in the pool. Default is 64. Must be set before connect().


minPoolSize

Type: number

Gets or sets the minimum number of connections allowed in the pool. Default is 0. Must be set before connect().


pooling

Type: boolean

Gets or sets connection pooling. Default is true. Must be set before connect(). Not supported by some databases.


recordCount

Type: number

Gets the number of rows in the result set of the last execute() call (0 for statements that return no result set).


rowsAffected

Type: number

Gets the number of rows which were inserted, updated, or deleted by the last statement executed with execute() (0 for statements that return a result set).

The properties fieldCount, lastInsertId, recordCount and rowsAffected are only set by execute() and reset to 0 by disconnect(); the document store functions do not change them.


specificOptions

Provides extended connection settings for each database provider. All properties of this object are passed to the provider as name=value when connect() is called. See

Type: object

Example:

myDB.specificOptions['UseUnicode'] = true;

sql

Type: string

Gets or sets the SQL statement, which then can be executed with execute(). Parameters are written as :name and set with setParamValue().

Example:

myDB.sql = 'SELECT id, json FROM testTable WHERE id = :id';
myDB.setParamValue('id', 2);
myDB.execute();

Methods


constructor()

Lets you create an INFINITY.JS database object instance. Doesn't accept parameters.

Signature:

constructor()

Example:

infinity.loadModule('infinity.database');
let myDB = new infinity.database();

bof()

Returns true, if the cursor is pointing to the beginning of the current result set.

Signature:

bof(): boolean

Return type: boolean

Example:

myDB.last();

while( !myDB.bof() ) {
  console.debug(myDB.rowObject());
  myDB.prev();
}

clear()

Removes all rows from the specified table (TRUNCATE TABLE).

Signature:

clear( table: string ): void

Parameters:

  • table: string

    The table to clear data from.

Example:

myDB.clear('testTable');

commit()

Commits the transaction started with startTransaction().

Signature:

commit(): void

Example:

myDB.startTransaction();
try {
  myDB.execute('INSERT...');
  myDB.execute('UPDATE...');
  myDB.commit();
} catch (e) {
  myDB.rollback();
  throw e;
}

connect()

Establishes a connection to the specified database using the provided parameters. The properties pooling, minPoolSize, maxPoolSize, connectionLifetime and specificOptions are applied at this moment. Throws an error if the connection fails.

Signature:

connect( provider: infinity.database.provider, server: string, port: number, database: string, username?: string, password?: string ): void

Parameters:

  • provider: infinity.database.provider

    The database provider to be used according to the infinity.database.provider enums.

  • server: string

    Server address (empty string for file based databases like SQLite).

  • port: number

    Connection port (0 for the provider's default port or file based databases).

  • database: string

    The name of the database (for SQLite the database file).

  • username: string, optional

    The username for logging in.

  • password: string, optional

    The password for logging in. If a username is given without a password, an empty password is used.

Example:

infinity.loadModule('infinity.database');
let myDB = new infinity.database();
myDB.connect(infinity.database.provider.mysql, 'localhost', 3306, 'exampleDB', 'root');

let myLiteDB = new infinity.database();
myLiteDB.specificOptions['Direct'] = true;
myLiteDB.connect(infinity.database.provider.sqlite, '', 0, 'database.db');

count()

Returns the number of rows in the specified table.

Signature:

count( table: string ): number

Parameters:

  • table: string

    The table to examine.

Return type: number

Example:

let rowsInTable = myDB.count('testTable');

create()

Creates a document table with the specified name inside the connected database, if it does not exist yet. The table has the columns id (bigint, auto increment primary key) and json (json, the document).

Signature:

create( table: string ): void

Parameters:

  • table: string

    The name of the table to create.

Example:

myDB.create('testTable');

disconnect()

Closes the current result set and disconnects from the current database. Resets recordCount, rowsAffected, fieldCount and lastInsertId to 0.

Signature:

disconnect(): void

Example:

myDB.disconnect();
myDB.free();

drop()

Deletes the specified table from the connected database, if it exists.

Signature:

drop( table: string ): void

Parameters:

  • table: string

    The name of the table to delete.

Example:

myDB.drop('testTable');

eof()

Returns true, if the cursor is pointing to the end of the current result set.

Signature:

eof(): boolean

Return type: boolean

Example:

myDB.execute('SELECT id, username FROM testTable');

while( !myDB.eof() ) {
  console.debug(myDB.rowObject());
  myDB.next();
}

escape()

Converts a value into a string that can be inserted into an SQL statement. Prefer parameters (setParamValue()) over building SQL statements with escaped values.

  • Strings are escaped MySQL-style with a backslash (', ", \, line breaks, #0 and #26). No quotation marks are added, the string has to be enclosed in quotation marks in the SQL statement. This escaping is only valid for databases that treat the backslash as escape character (e.g. MySQL/MariaDB), not e.g. for SQLite or PostgreSQL with standard strings.
  • Booleans are returned as 1 or 0, numbers as their string representation.
  • Objects and arrays are returned as JSON text (not escaped).
  • Other values (e.g. null or undefined) throw an error.

Signature:

escape( value: any, asLikeString?: boolean ): string

Parameters:

  • value: any

    The value to escape.

  • asLikeString: boolean, optional

    If true, the wildcard characters % and _ in strings are additionally escaped with a backslash, for use with the LIKE operator. Default is false.

Return type: string

Example:

myDB.execute('SELECT i_id, c_title FROM documents WHERE c_title = "' + myDB.escape(title) + '";');
myDB.execute('SELECT i_id, c_title FROM documents WHERE c_title LIKE "' + myDB.escape(text, true) + '%";');

//preferred: parameters
myDB.sql = 'SELECT i_id, c_title FROM documents WHERE c_title = :title';
myDB.setParamValue('title', title);
myDB.execute();

execute()

Executes the SQL statement of the sql property, or the given statement (which is then stored in the sql property). Throws an error if the statement fails.

Returns true if a query returned at least one row, or if a statement without result set (INSERT, UPDATE, DELETE, ...) affected at least one row, otherwise false. Sets recordCount, fieldCount, rowsAffected and lastInsertId. The cursor is placed at the first row of the result set.

All parameters set with setParamValue() are removed after the execution (also if it fails), so they have to be set again before each call.

Signature:

execute( sql?: string ): boolean

Parameters:

  • sql: string, optional

    The SQL statement to execute.

Return type: boolean

Example:

if( myDB.execute('SELECT i_id, c_title FROM documents ORDER by i_id desc limit 10;') ) {
  //...
}

//Parameterized query using the sql-property:
myDB.sql = 'SELECT i_id, c_title FROM documents WHERE i_id = :id;';
myDB.setParamValue('id', 1);
myDB.execute();

exists()

Checks whether a table with the specified name exists inside the connected database (using information_schema.tables).

Signature:

exists( table: string ): boolean

Parameters:

  • table: string

    The table name to check for.

Return type: boolean

Example:

if( myDB.exists('testTable') ){
  //...
}

find()

Returns the documents of the specified document table matching the given query. The query is translated into an SQL WHERE clause; keys refer to table columns, so conditions (and orderBy) can only use id and the columns created with index().

Signature:

find( table: string, query: infinity.database.queryArray, orderBy?: string, orderDirection?: infinity.database.orderDirection, offset?: number, limit?: number, outputMode?: infinity.database.outputMode ): infinity.database.findResultArray

Parameters:

  • table: string

    The name of the table to be queried.

  • query: infinity.database.queryArray

    The query (see queryArray). An empty array returns all documents.

  • orderBy: string, optional

    The column the result is ordered by. Only used if orderDirection is not none.

  • orderDirection: infinity.database.orderDirection, optional

    Specifies the order direction. Default is infinity.database.orderDirection.none.

  • offset: number, optional

    The number of rows to skip. Only used if limit is greater than 0. Default is 0.

  • limit: number, optional

    The maximum number of rows to return. 0 or omitted means no limit.

  • outputMode: infinity.database.outputMode, optional

    Specifies how the data is returned. Default is infinity.database.outputMode.objects.

Return type: infinity.database.findResultArray

Example:

let ids = myDB.find('users', [['email', 'endswith', 'e']], 'email', infinity.database.orderDirection.ascending, 0, 0, infinity.database.outputMode.ids);
let users = myDB.find('users', [['email', 'endswith', 'e'], 'and', ['id', '>', 100]], 'id', infinity.database.orderDirection.descending, 0, 10);

first()

Places the cursor at the first row of the current result set.

Signature:

first(): void

Example:

myDB.execute('SELECT * FROM testTable');

console.debug(myDB.row());
myDB.next();
console.debug(myDB.row());
myDB.first();
console.debug(myDB.row());

free()

Closes the connection and frees the memory previously occupied by the database object instance. The object must not be used afterwards.

Signature:

free(): void

Example:

myDB.disconnect();
myDB.free();

get()

Returns the document with the given ID out of the specified document table (including the property id), or undefined if there is no such document.

Signature:

get( table: string, id: number ): object

Parameters:

  • table: string

    The name of the table to be queried.

  • id: number

    The ID of the row to be returned.

Return type: object

Example:

let secondRow = myDB.get('testTable', 2);

get()

Returns the documents with the given IDs out of the specified document table (each including the property id). IDs without a matching document are skipped, an empty array returns an empty array. Throws a TypeError if an ID is not a number.

Signature:

get( table: string, ids: infinity.database.idsArray ): infinity.database.getResultArray

Parameters:

  • table: string

    The name of the table to be queried.

  • ids: infinity.database.idsArray

    An array containing the IDs of the rows to be returned.

Return type: infinity.database.getResultArray

Example:

let someRows = myDB.get('testTable', [2, 3]);

getDatabaseNames()

Returns an array of the names of databases on the connected server.

Signature:

getDatabaseNames(): infinity.database.stringArray

Return type: infinity.database.stringArray

Example:

let dbNames = myDB.getDatabaseNames();

getFieldNames()

Returns an array of the field names of the specified table.

Signature:

getFieldNames( table: string ): infinity.database.stringArray

Parameters:

  • table: string

    The table to be queried.

Return type: infinity.database.stringArray

Example:

let fieldNames = myDB.getFieldNames('testTable');

getKeyFieldNames()

Returns an array of the names of the primary key fields of the specified table.

Signature:

getKeyFieldNames( table: string ): infinity.database.stringArray

Parameters:

  • table: string

    The table to be queried.

Return type: infinity.database.stringArray

Example:

let keyFieldNames = myDB.getKeyFieldNames('testTable');

getStoredProcNames()

Returns an array of stored procedures from the server.

Signature:

getStoredProcNames(): infinity.database.stringArray

Return type: infinity.database.stringArray

Example:

let storedProcNames = myDB.getStoredProcNames();

getTableNames()

Returns an array of the names of the tables on the connected database.

Signature:

getTableNames(): infinity.database.stringArray

Return type: infinity.database.stringArray

Example:

let tableNames = myDB.getTableNames();

has()

Indicates whether the specified table has a row with the given ID.

Signature:

has( table: string, id: number ): boolean

Parameters:

  • table: string

    The name of the table to be checked.

  • id: number

    The row to be checked.

Return type: boolean

Example:

if( myDB.has('testTable', 2) ){
  //...
}

index()

Adds a generated column for a property of the documents to the specified document table and creates an index on it. The column and the index are named like the property; the column value is taken from the JSON document (json_value(json, "$.key")). Indexed properties can be used in the queries of find(), update() and remove().

Signature:

index( table: string, key: string, indexType: infinity.database.indexType, columnType?: infinity.database.columnType, unique?: boolean ): void

Parameters:

  • table: string

    The name of the table to be altered.

  • key: string

    The name of the document property to index.

  • indexType: infinity.database.indexType

    Specifies the SQL data type of the column.

  • columnType: infinity.database.columnType, optional

    Defines whether the column is virtual or persistent. Default is infinity.database.columnType.virtual.

  • unique: boolean, optional

    Indicates whether the index should enforce uniqueness. Default is false.

Example:

myDB.index('testTable', 'username', infinity.database.indexType.string, infinity.database.columnType.virtual, true);
myDB.index('testTable', 'modified', infinity.database.indexType.int);

insert()

Inserts a new document into the specified document table and returns its ID. A property id of the document is ignored, the ID is always assigned by the database (auto increment).

Signature:

insert( table: string, document: object ): number

Parameters:

  • table: string

    The name of the table to be altered.

  • document: object

    An object containing the data to be inserted.

Return type: number

Example:

myDB.insert('testTable', { "username": "TheUserName1", "email": "theusername@email.com", "rights": ["read", "write", "create", "delete"] });

last()

Places the cursor at the last row of the current result set.

Signature:

last(): void

Example:

myDB.execute('SELECT * FROM testTable');

console.debug(myDB.row());
myDB.last();
console.debug(myDB.row());

next()

Places the cursor at the next row of the current result set.

Signature:

next(): void

Example:

myDB.execute('SELECT * FROM testTable');

console.debug(myDB.row());
myDB.next();
console.debug(myDB.row());

prev()

Places the cursor at the previous row of the current result set.

Signature:

prev(): void

Example:

myDB.execute('SELECT * FROM testTable');

console.debug(myDB.row());
myDB.next();
console.debug(myDB.row());
myDB.prev();
console.debug(myDB.row());

remove()

Removes all documents matching the given query from the specified document table. Returns the number of removed rows.

Signature:

remove( table: string, query: infinity.database.queryArray ): number

Parameters:

  • table: string

    The name of the table from which the row will be removed.

  • query: infinity.database.queryArray

    The query selecting the documents to remove. An empty array removes all documents.

Return type: number

Example:

let rowsAffected = myDB.remove('testTable', [['id', '=',  2]]);

remove()

Removes the document with the given ID from the specified document table. Returns the number of removed rows (0 or 1).

Signature:

remove( table: string, id: number ): number

Parameters:

  • table: string

    The name of the table from which the row will be removed.

  • id: number

    The ID of the document to be removed.

Return type: number

Example:

myDB.remove('testTable', 2);

result()

Returns the value of the specified column in the current row of the result set. Throws an error if the column does not exist.

Values are converted to JavaScript types: numeric columns to number, text columns to string, boolean columns to boolean, date and time columns to number (milliseconds since 1970-01-01), binary columns (BLOB, BINARY, VARBINARY) to string (the raw bytes, including #0 bytes), GUID columns to string. NULL values are returned as null, NULL date and time values as -62135683200000. Other column types throw an error.

Signature:

result( field: number|string ): any

Parameters:

  • field: number|string

    The column name or the column index (starting with 0).

Return type: any

Example:

myDB.execute('SELECT id, username, email FROM testTable');
let firstRowSecondColumn = myDB.result(1);
let firstRowOfEmailColumn = myDB.result('email');

result()

Returns the complete result set of the last query as an array of arrays. The first element contains the column names, each following element the values of one row (converted as described for result(field)). Moves the cursor from the first row to the end of the result set.

Signature:

result(): infinity.database.resultArray

Return type: infinity.database.resultArray

Example:

myDB.execute('SELECT id, username FROM testTable');
let result = myDB.result();
console.debug(result);
//[["id","username"],[1,"TheUserName1"],[2,"aUserName"]]

resultToStream()

Writes the content of the specified binary (BLOB) or memo column in the current row of the result set to the given stream. Throws an error if the column is not a BLOB/memo column.

Signature:

resultToStream( field: number|string, stream: infinity.stream ): void

Parameters:

  • field: number|string

    The column name or the column index (starting with 0).

  • stream: infinity.stream

    The stream to write to.

Example:

infinity.loadModule('infinity.stream');

let stream = new infinity.stream();

try {
  myDB.sql = 'SELECT data FROM files WHERE id = :id';
  myDB.setParamValue('id', 1);

  if (myDB.execute()) {
    myDB.resultToStream('data', stream);
  }
} finally {
  stream.free();
}

rollback()

The Rollback method is equivalent to the SQL ROLLBACK statement. The transaction can only be rolled back from a pending state (after infinity.database.startTransaction, but before infinity.database.commit has been called).

Signature:

rollback(): void

Example:

myDB.startTransaction();
try {
  myDB.execute('INSERT...');
  myDB.execute('UPDATE...');
  myDB.commit();
} catch (e) {
  myDB.rollback();
  throw e;
}

row()

Returns the current row of the result set as an array of values (converted as described for result(field)).

Signature:

row(): infinity.database.rowArray

Return type: infinity.database.rowArray

Example:

myDB.execute('SELECT * FROM testTable');
console.debug(myDB.row());

rowObject()

Returns the current row of the result set as an object with the column names as property names (values converted as described for result(field)).

Signature:

rowObject(): object

Return type: object

Example:

myDB.execute('SELECT * FROM testTable');
console.debug(myDB.rowObject());

setParamValue()

Sets the value of a parameter of the SQL statement. Parameters are written in the SQL statement with a preceding colon and without quotation marks (e.g. :id). The values are passed to the database separately from the SQL statement, so they don't have to be escaped. After execute() all parameters are removed.

The parameter type depends on the value: strings are passed as strings, booleans as booleans, integral numbers as 64-bit integers, other numbers as floating point numbers, objects and arrays as JSON text, streams as binary data (the whole stream content) and null as SQL NULL. Other values (e.g. undefined) throw an error.

Signature:

setParamValue( name: string, value: any ): void

Parameters:

  • name: string

    The name of the parameter (without colon).

  • value: any

    The value of the parameter.

Example:

myDB.sql = 'select i_id, c_title from documents where i_id = :id and c_text = :text;';
myDB.setParamValue('id', 2);
myDB.setParamValue('text', 'replacement');
myDB.execute();

startTransaction()

Begins a new user transaction against the database server.

Signature:

startTransaction( isolationLevel?: infinity.database.isolationLevel, readOnly?: boolean ): void

Parameters:

  • isolationLevel: infinity.database.isolationLevel, optional

    Specifies the transaction locking behavior. Default is infinity.database.isolationLevel.repeatableRead.

  • readOnly: boolean, optional

    Sets the transaction to read only. Default is false.

Example:

myDB.startTransaction();
try {
  myDB.execute('INSERT...');
  myDB.execute('UPDATE...');
  myDB.commit();
} catch (e) {
  myDB.rollback();
  throw e;
}

update()

Replaces a document in the specified document table by the given document. The document to replace is identified by the property id of the given document. Returns the number of affected rows (0 if id is missing or not greater than 0, or if no document with this ID exists).

Signature:

update( table: string, document: object ): number

Parameters:

  • table: string

    The name of the table to be updated.

  • document: object

    The new document, including the property id.

Return type: number

Example:

myDB.update('testTable', { id: 2, username: "aUserName", email: "yetanother@email.com", modified: Math.floor(Date.now() * 0.001) });

update()

Merges the given object into the document with the given ID in the specified document table (json_merge_patch): properties of the object are added to or replaced in the document, properties with the value null are removed; a property id is ignored. Returns the number of affected rows.

Signature:

update( table: string, id: number, update: object ): number

Parameters:

  • table: string

    The name of the table to be updated.

  • id: number

    The ID of the document to be updated.

  • update: object

    An object containing the properties to be changed.

Return type: number

Example:

myDB.update('testTable', 2, { username: "newUserName", email: "new@email.com" });

update()

Merges the given object into all documents matching the given query in the specified document table (json_merge_patch): properties of the object are added to or replaced in the documents, properties with the value null are removed; a property id is ignored. Returns the number of affected rows.

Signature:

update( table: string, query: infinity.database.queryArray, update: object ): number

Parameters:

  • table: string

    The name of the table to be updated.

  • query: infinity.database.queryArray

    The query selecting the documents to update. An empty array updates all documents.

  • update: object

    An object containing the properties to be changed.

Return type: number

Example:

myDB.update('testTable', [['username', '=', 'TheUserName1']], { email: "yetanother@email.com", modified: Math.floor(Date.now() * 0.001) });

Interfaces

findResultArray

Extends: Array<object|number>

The result of find(): an array of documents (output mode objects), of document IDs (output mode ids) or an array with the number of found documents as only element (output mode count).


getResultArray

Extends: Array<object>

An array of documents.


idsArray

Extends: Array<number>

An array of document IDs.


queryArray

Extends: Array<string|Array<string|number|boolean>>

A query for find(), update() and remove(), translated into an SQL WHERE clause.

A query is an array of conditions, separated by combine operators: [condition, operator, condition, ...]. An empty array matches all documents.

A condition is an array [key, compareOperator, value].

  • key: The column name: id or a column created with index(). Names that contain other characters than letters, digits, _, $ and . are quoted as identifier (never inserted as SQL).
  • compareOperator: = (or ==), <> (or !=), >, <, >=, <=, beginswith, endswith or contains (the last three translated into LIKE).
  • value: A string, a number or a boolean (true/false are compared as 1/0). null or the string 'null' with the operator = is translated into IS NULL, with <> into IS NOT NULL. Numbers are compared as strings by beginswith, endswith and contains; the wildcard characters % and _ are only escaped for these three operators.

Combine operators: and (or &, &&), or (or |, ||) and not (or !, !!, translated into AND NOT). They are inserted into the SQL WHERE clause in the given order. A condition can also be a nested query (an array of conditions), which is put in parentheses.

Example:

let query = [['username', 'beginswith', 'a'], 'and', ['modified', '>', 1613741246]];

resultArray

Extends: Array<Array<any>>

The result of result(): the first element contains the column names, each following element the values of one row.


rowArray

Extends: Array<any>

The values of one row of the result set.


stringArray

Extends: Array<string>

An array of strings.


Enums

infinity.database.columnType

Specifies the type of the generated column created by index().

Values:

  • virtual: 0

    The column value is computed from the JSON document when it is read.

  • persistent: 1

    The column value is stored in the table (generated column PERSISTENT, MariaDB syntax).

Example:

infinity.loadModule('infinity.database');
let columnType = infinity.database.columnType.virtual;

infinity.database.indexType

Specifies the SQL data type of the column created by index().

Values:

  • boolean: 0

    tinyint(1)

  • string: 1

    varchar(32)

  • int: 2

    int(10)

  • bigint: 3

    bigint(20)

  • float: 4

    float

  • double: 5

    double

Example:

infinity.loadModule('infinity.database');
let indexType = infinity.database.indexType.boolean;

infinity.database.isolationLevel

Specifies the transaction locking behavior for a connection.

Values:

  • readCommitted: 0

    Shared locks are held while the data is being read to avoid dirty reads, but the data can be changed before the end of the transaction, resulting in non-repeatable reads or phantom data.

  • readUncommitted: 1

    A dirty read is possible, meaning that no shared locks are issued and no exclusive locks are honored.

  • repeatableRead: 2

    Locks are placed on all data that is used in a query, preventing other users from updating the data. Prevents non-repeatable reads but phantom rows are still possible.

  • isolated: 3

    A range lock is placed on the dataset, preventing other users from updating or inserting rows into the dataset until the transaction is complete.

  • snapshot: 4

    Reduces blocking by storing a version of data that one application can read while another is modifying the same data. Indicates that from one transaction you cannot see changes made in other transactions, even if you requery.

Example:

infinity.loadModule('infinity.database');
let isolationLevel = infinity.database.isolationLevel.readCommitted;

infinity.database.orderDirection

Specifies the order direction of the returned result set.

Values:

  • none: 0

    Not sorted.

  • ascending: 1

    Ascending order.

  • descending: 2

    Descending order.

Example:

infinity.loadModule('infinity.database');
let orderDirection = infinity.database.orderDirection.ascending;

infinity.database.outputMode

Specifies how the result data has to be returned.

Values:

  • objects: 0

    As objects.

  • ids: 1

    As an array of document IDs.

  • count: 2

    As an array with the number of found documents as only element.

Example:

infinity.loadModule('infinity.database');
let outputMode = infinity.database.outputMode.objects;

infinity.database.provider

Specifies the database provider to be used. See also specificOptions for extended setup possibilities.

Values:

  • access: Access

    Microsoft Access (Windows only)

  • advantage: Advantage

    Advantage Database Server (Windows only)

  • ase: ASE

    SAP Sybase Adaptive Server Enterprise

  • db2: DB2

    DB2 (Windows only)

  • dbf: DBF

    DBF

  • interbase: InterBase

    InterBase/Firebird

  • mysql: MySQL

    MySQL/MariaDB

  • odbc: ODBC

    ODBC

  • oracle: Oracle

    Oracle

  • postgresql: PostgreSQL

    PostgreSQL

  • sqlserver: SQL Server

    SQL Server

  • sqlite: SQLite

    SQLite

  • mongodb: MongoDB

    MongoDB

  • redshift: Redshift

    Amazon Redshift

Example:

infinity.loadModule('infinity.database');
let provider = infinity.database.provider.access;