infinity.noSql¶
Provides non-relational in-memory database functionality.
Module: infinity.noSql
Example:
infinity.loadModule('infinity.noSql');
if (!infinity.noSql.exists('testCollection')) {
infinity.noSql.create('testCollection');
infinity.noSql.index('testCollection', 'username', true);
infinity.noSql.index('testCollection', 'modified');
}
infinity.noSql.insert('testCollection', { "username": "TheUserName1", "email": "theusername@email.com", "rights": ["read", "write", "create", "delete"] });
infinity.noSql.insert('testCollection', { "username": "AnotherUserName2", "email": "someother@email.net", "rights": ["read"] });
infinity.noSql.insert('testCollection', { username: "aUserName3", email: "yetanother@email.com" });
let ids = infinity.noSql.find('testCollection', [['username', 'beginswith', 'a']], '', infinity.noSql.orderDirection.ascending, 0, 0, infinity.noSql.outputMode.ids);
console.debug(ids);
infinity.noSql.update('testCollection', { id: 2, username: "aUserName", email: "yetanother@email.com", modified: Math.floor(Date.now() * 0.001) });
let secondRow = infinity.noSql.get('testCollection', 2);
console.debug(secondRow);
let firstTwoRows = infinity.noSql.get('testCollection', [1, 2]);
console.debug(firstTwoRows);
console.debug(infinity.noSql.has('testCollection', 2));
findResultArray¶
Extends: Array<object|number>
An array of objects or numbers.
getResultArray¶
Extends: Array<object>
An array of objects.
idArray¶
Extends: Array<number>
An array of numbers.
queryArray¶
Extends: Array<string|Array<string|number|boolean>>
An array of strings or of arrays containing strings, numbers or boolean values.
clear()¶
Clears all data from the specified collection.
Signature:
clear( collection: string ): void
Parameters:
- collection:
string
The collection to clear data from.
Example:
infinity.loadModule('infinity.noSql');
infinity.noSql.clear('testCollection');
count()¶
Returns the number of rows present inside the specified collection.
Signature:
count( collection: string ): number
Parameters:
- collection:
string
The collection to examine.
Return type: number
Example:
infinity.loadModule('infinity.noSql');
let rowsInCollection= myDB.count('testCollection');
create()¶
Creates a collection with the specified name in memory.
Signature:
create( collection: string, capped?: boolean, maxCount?: number ): void
Parameters:
-
collection:
string
The name of the collection to create.
-
capped:
boolean
, optionalWhether the row count of the collection should be limited.
-
maxCount:
number
, optionalThe maximum amount of rows the collection should contain.
Example:
infinity.loadModule('infinity.noSql');
infinity.noSql.create('testCollection');
drop()¶
Deletes the specified collection from memory.
Signature:
drop( collection: string ): void
Parameters:
- collection:
string
The name of the collection to delete.
Example:
infinity.loadModule('infinity.noSql');
infinity.noSql.drop('testCollection');
exists()¶
Checks whether a collection with the specified name exists in memory.
Signature:
exists( collection: string ): boolean
Parameters:
- collection:
string
The collection name to check for.
Return type: boolean
Example:
infinity.loadModule('infinity.noSql');
if ( infinity.noSql.exists('testCollection') ) {
//...
}
find()¶
Allows for querying collections for data in a structured way using a sql-like query language.
Signature:
find( collection: string, query: infinity.noSql.queryArray, orderBy?: string, orderDirection?: infinity.noSql.orderDirection, offset?: number, limit?: number, outputMode?: infinity.noSql.outputMode ): infinity.noSql.findResultArray
Parameters:
-
collection:
string
The name of the collection to be queried.
-
query:
infinity.noSql.queryArray
An array of options for the query, usable with the following operators: =, <>, !=, >, <, >=, <=, beginswith, endswith, contains.
-
orderBy:
string
, optionalSpecifies by which column the result has to be ordered.
-
orderDirection:
infinity.noSql.orderDirection
, optionalSpecifies the order direction.
-
offset:
number
, optionalSpecifies, how many records have to be skipped.
-
limit:
number
, optionalConstrains the number of rows to return.
-
outputMode:
infinity.noSql.outputMode
, optionalSpecifies how the data is returned.
Return type: infinity.noSql.findResultArray
Example:
infinity.loadModule('infinity.noSql');
let ids = infinity.noSql.find('testCollection', [['username', 'beginswith', 'a']], '', infinity.noSql.orderDirection.ascending, 0, 0, infinity.noSql.outputMode.ids);
get()¶
Returns a row with the given ID out of the specified collection.
Signature:
get( collection: string, id: number ): object
Parameters:
-
collection:
string
The name of the collection to be queried.
-
id:
number
The ID of the row to be returned.
Return type: object
Example:
infinity.loadModule('infinity.noSql');
let secondRow = infinity.noSql.get('testCollection', 2);
get()¶
Returns multiple rows with the given IDs out of the specified collection as an array of objects.
Signature:
get( collection: string, ids: infinity.noSql.idArray ): infinity.noSql.getResultArray
Parameters:
-
collection:
string
The name of the collection to be queried.
-
An array containing the IDs of the rows to be returned.
Return type: infinity.noSql.getResultArray
Example:
infinity.loadModule('infinity.noSql');
let someRows = infinity.noSql.get('testCollection', [2, 3]);
has()¶
Indicates whether the specified collection has a row with the given ID.
Signature:
has( collection: string, id: number ): boolean
Parameters:
-
collection:
string
The name of the collection to be checked.
-
id:
number
The row to be checked.
Return type: boolean
Example:
infinity.loadModule('infinity.noSql');
if ( infinity.noSql.has('testCollection', 2) ) {
//...
}
index()¶
Creates an index column inside the given collection and specifies the data type to be stored in. Can optionally specify the column to act as an index of the given type.
Signature:
index( collection: string, key: string, unique?: boolean ): void
Parameters:
-
collection:
string
The name of the collection to be altered.
-
key:
string
The column to act as an index.
-
unique:
boolean
, optionalSpecifies whether the index has to be unique.
Example:
infinity.loadModule('infinity.noSql');
infinity.noSql.index(collection, key);
insert()¶
Inserts the given data into the specified collection. The data has to be passed inside an object.
Signature:
insert( collection: string, document: object ): number
Parameters:
-
collection:
string
The name of the collection to be altered.
-
document:
object
An object containing the data to be inserted.
Return type: number
Example:
infinity.loadModule('infinity.noSql');
infinity.noSql.insert('testCollection', { "username": "TheUserName1", "email": "theusername@email.com", "rights": ["read", "write", "create", "delete"] });
lock()¶
Attempts to lock the specified collection for writing and or reading access.
Signature:
lock( collection: string, readOnly?: boolean ): boolean
Parameters:
-
collection:
string
The name of the collection to be locked.
-
readOnly:
boolean
, optionalSpecifies whether only reading access is required.
Return type: boolean
Example:
infinity.loadModule('infinity.noSql');
if ( infinity.noSql.lock('testCollection') ) {
//...
}
remove()¶
Removes rows from the specified collection corresponding to the provided query parameters. Takes query parameters inside an array. Returns the number of rows affected by the query.
Signature:
remove( collection: string, query: infinity.noSql.queryArray ): number
Parameters:
-
collection:
string
The name of the collection to be altered.
-
query:
infinity.noSql.queryArray
An array containing the query parameters.
Return type: number
Example:
infinity.loadModule('infinity.noSql');
let rowsAffected = infinity.noSql.remove('testCollection', [['id', '=', 2]]);
remove()¶
Removes a row from a specified collection based on a given row ID.
Signature:
remove( collection: string, id: number ): number
Parameters:
- collection:
string
The name of the collection to be altered.
- id:
number
The unique identifier of the row to be removed.
Return type: number
Example:
infinity.loadModule('infinity.noSql');
let rowsAffected = infinity.noSql.remove('testCollection', 2);
console.log(rowsAffected + ' row(s) removed.');
unlock()¶
Releases the access lock set previoously through lock().
Signature:
unlock( collection: string ): void
Parameters:
- collection:
string
The name of the collection to be unlocked.
Example:
infinity.loadModule('infinity.noSql');
infinity.noSql.unlock('testCollection');
update()¶
Updates a value in an existing row in the specified collection corresponding to the provided query parameters. Takes query parameters inside an array. The data for the update has to be passed inside an object. Returns the number of rows affected by the query.
Signature:
update( collection: string, query: infinity.noSql.queryArray, update: object ): number
Parameters:
-
collection:
string
The name of the collection to be updated.
-
query:
infinity.noSql.queryArray
An array containing the query parameters.
-
update:
object
An object containing the data to be written.
Return type: number
Example:
infinity.loadModule('infinity.noSql');
let rowsAffected = infinity.noSql.update('testCollection', query, update);
infinity.noSql.update('test', [['username', '=', 'TheUserName1']], {"email": "somerandom@email.com"});
update()¶
Updates a value in an existing row in the specified collection based on a given row id.
Signature:
update( collection: string, id: number, update: object ): number
Parameters:
-
collection:
string
The name of the collection to be updated.
-
id:
number
The unique identifier of the row to be updated.
-
update:
object
An object containing the data to be written.
Return type: number
Example:
infinity.loadModule('infinity.noSql');
let updateData = { username: "newUserName", email: "new@email.com", modified: Math.floor(Date.now() * 0.001) };
let rowsAffected = infinity.noSql.update('testCollection', 2, updateData);
console.log(rowsAffected + ' row(s) updated.');
update()¶
Updates a value in an existing row in the specified collection. The data for the update has to be passed inside an object. The row is being identified by the given row id inside the provided data object. Returns the number of rows affected by the query.
Signature:
update( collection: string, document: object ): number
Parameters:
-
collection:
string
The name of the collection to be updated.
-
document:
object
An object containing the data to be written.
Return type: number
Example:
infinity.loadModule('infinity.noSql');
let rowsAffected = infinity.noSql.update('testCollection', { id: 2, username: "aUserName", email: "yetanother@email.com", modified: Math.floor(Date.now() * 0.001) });
infinity.noSql.orderDirection¶
Specifies the order direction of the returned result set.
Values:
-
none:
0
-
ascending:
1
-
descending:
2
Example:
infinity.loadModule('infinity.noSql');
let orderDirection = infinity.noSql.orderDirection.ascending;
infinity.noSql.outputMode¶
Specifies how the result data has to be returned.
Values:
-
objects:
0
As objects.
-
ids:
1
As row IDs in a comma-separated string.
-
count:
2
As a total count number.
Example:
infinity.loadModule('infinity.noSql');
let outputMode = infinity.noSql.outputMode.objects;