ModuleServerAPI Database
The ModuleServerAPI allows loading sqlite3 database into memory using it's own wrapper.
Database Specification
To load a database, execute the api.loadDatabase with the file location and a database specification. This specification tells the database handler which tables should exist with what columns. This specification is automatically parsed on load. New tables or columns will automatically be added and removed entries from the specification will also be removed from the database. The possible column types are NULL, TEXT, INTEGER, REAL, BLOB. For storing JSON objects use the TEXT type and for boolean use INTEGER. Below is an example of a database specification.
{
"tableName": {
"columnName": {
"type": "TEXT",
"primary": true
},
"anotherColumnName": {
"type": "INTEGER"
}
},
"anotherTable": {
"columnName": {
"type": "TEXT",
"primary": true
},
"blobColumn": {
"type": "BLOB"
},
"readColumn": {
"type": "REAL"
}
}
}
Database Instance
This is the class respresenting the entire database.
close
Close the database.
database.close();
getTable
Get a table within the database.
database.getTable(tableId);
| Argument | Type | Description |
|---|---|---|
| tableId | string | The ID of the table. |
Return DatabaseTable DatabaseTable instance
run
Run a raw sql query on the database.
database.run(query, amps?:string[]);
| Argument | Type | Description |
|---|---|---|
| query | string | The SQL query to run. |
| (Optional) amps | string[] | Safely include parameters to prevent SQL injections. |
Returns any[] Returns from the query
fetchColumnsForTable
Fetch the column ids of a table.
| Argument | Type | Description |
|---|---|---|
| table | string | The table to fetch the column from. |
DatabaseTable Instance
Class respresenting a table within the database.
getAllRows
Get all rows in the table.
table.getAllRows();
Returns Promise<{ [key:string]: any}[]> All rows in the table.
getPrimaryColumnValues
Get all primary column values.
table.getPrimaryColumnValues();
Returns Promise<string[]> All rows in the table.
getValue
Fetch the value of a specific cell.
table.getValue(primaryKeyValue, columnId);
| Argument | Type | Description |
|---|---|---|
| primaryKeyValue | string | The primary key value of the row. |
| columnId | string | The id of the column. |
Returns Promise<any> Value of the cell
getValueAsJSON
Fetch the value as JSON of a specific cell. JSON objects are saved as text so make sure the column type is TEXT.
table.getValue(primaryKeyValue, columnId);
| Argument | Type | Description |
|---|---|---|
| primaryKeyValue | string | The primary key value of the row. |
| columnId | string | The id of the column. |
Returns Promise<object|array> Value of the cell as JSON.
getValueAsBoolean
Fetch the value as boolean of a specific cell. Booleans are saved a binary so make sure the column type is INTEGER.
table.getValue(primaryKeyValue, columnId);
| Argument | Type | Description |
|---|---|---|
| primaryKeyValue | string | The primary key value of the row. |
| columnId | string | The id of the column. |
Returns Promise<boolean> Value of the cell as boolean.
updateRow
Update a row in the table.
table.updateRow(primaryKeyValue, values);
| Argument | Type | Description |
|---|---|---|
| primaryKeyValue | string | The primary key value of the row. |
| values | { [columnId:string]: any} | The values to set. |
Returns Promise<void> Row has been updated.
removeRow
Update a row in the table.
table.removeRow(primaryKeyValue);
| Argument | Type | Description |
|---|---|---|
| primaryKeyValue | string | The primary key value of the row. |
Returns Promise<void> Row has been removed.
removeAllRows
Remove all rows in the table.
table.removeAllRows();
Returns Promise<void> All rows have been removed.
getPrimaryKeyColumn
Get the primary key column of the table.
table.getPrimaryKeyColumn();
Returns string The primary column id.
Getting Started
Module Development
- Introduction
- V2 Module Structure
- V1 Module Structure
- Development environment/Building
- Module Config
- Module Debugging
- GetiyoModuleTool
- Bug/Feature Reporting
- Contact Details
ModuleServerAPI
ModuleServerAPI GameLib
ModuleClientAPI
ModuleApi Shared
© Vix Entertainment 2023 - © Mooren Productief 2023 - All rights reserved