This tutorial demonstrates connecting to Node.js using the FairCom Edge Node.js module. For more about the FairCom support for Node.js, see FairCom API for Node.js in the on-line documentation.
This section explains the tutorial. The next subsections explain how to run it on Windows and Linux:
Node.js Tutorial for Windows
Node.js Tutorial for Linux
Usage
The module currently contains 5 methods:
createTable
deleteTable
createIndex
createRecord
query
Basic usage of the module starts with the following two lines:
fields: an array with objects containing the fields: name, type and length
callback: a callback function that will be called with two parameters once the table is created: err and res. If err is false, the table was created successfully.
Valid field types:
"BOOL"
"TINYINT"
"UTINYINT"
"SMALLINT"
"USMALLINT"
"INTEGER"
"UINTEGER"
"BIGINT"
"UBIGINT"
"MONEY"
"DATE"
"TIME"
"FLOAT"
"DOUBLE"
"TIMESTAMP"
"EFLOAT"
"BINARY"
"CHARS"
"FPSTRING"
"F2STRING"
"F4STRING"
"NUMBER"
"CURRENCY"
"PSTRING"
"VARBINARY"
"LVB"
"VARCHAR"
"LVC"
"NCHAR"
"NVARCHAR"
Example:
ctree.createTable("ctreeSQL", "books", [
{
"name": "id",
"type": "INTEGER",
"length": 4
},
{
"name": "name",
"type": "VARCHAR",
"length": 128
},
{
"name": "author",
"type": "VARCHAR",
"length": 128
},
{
"name": "country",
"type": "VARCHAR",
"length": 48
}
]
, function(err, res){
if (err) {
console.log('error:', err);
} else {
console.log("table created");
}
});
Delete Table
deleteTable(db, table, callback)
db: your existing database name
table: your existing table name
callback: a callback function that will be called with two parameters once the table is deleted: err and res. If err is false, the table was deleted successfully.
unique: true or false depending if you want the index to allow duplicate values
fields: an array with objects containing the fields: name and ascending
callback: a callback function that will be called with two parameters once the index is created: err and res. If err is false, the index was created successfully.
record: an object containing any or all the fields of your table
callback: a callback function that will be called with two parameters once the record is created: err and res. If err is false, the record was created successfully.
offset: the amount of records to skip (for paging)
query: for example: {name:{"operator":"=", "value":"Moby Dick"}}
with operator being one of “=”, “>=”, “<=”, “>” or “<”
callback: a callback function that will be called with two parameters once the query is executed: err and res. If err is false, the query was executed successfully and the res object contains the query search result.