Skip to content

cxUserspace

Auto-generated documentation from JSDoc comments

cxUserspace

Create, Read, Update & Delete from the Userspace Database

Example

const cxUserspace = require('cxUserspace');
async function main(data) {
  var result = await cxUserspace.read(data.routing.dest_number);
  // Do something with result
  return data
}

Kind: global class

cxUserspace.getPk(area) ⇒ Promise

Get Primary Key

Kind: static method of cxUserspace

Param Type Description
area string Datastore Name

Example

await cxUserspace.getPk('myTable')

cxUserspace.create(area, key, data) ⇒ Promise

Create Record (With Primary Key)

Kind: static method of cxUserspace

Param Type Description
area string Datastore Name
key string | number Row Id
data object Data Object / Row

Example

await cxUserspace.create('myDatabase', 1, {value: 'Hello World!'})

cxUserspace.insert(area, data) ⇒ Promise

Insert Record

Kind: static method of cxUserspace

Param Type Description
area string Datastore Name
data object Data Object / Row

Example

await cxUserspace.insert('myDatabase', {value: 'Hello World!'})

cxUserspace.get(area, key) ⇒ Promise

Get Row

Kind: static method of cxUserspace

Param Type Description
area string Datastore Name
key string | number Row Id

Example

await cxUserspace.get('myDatabase', 1)

cxUserspace.read(area, key) ⇒ Promise

Read Value from Record

Kind: static method of cxUserspace

Param Type Description
area string Datastore Name
key string | number Row Id

Example

await cxUserspace.read('myDatabase', 1)

cxUserspace.update(area, key, data) ⇒ Promise

Update Record

Kind: static method of cxUserspace

Param Type Description
area string Datastore Name
key string | number Row Id
data object Data Object / Row

Example

await cxUserspace.update('myDatabase', 1, {value: 'Hello World!'})

cxUserspace.delete(area, key) ⇒ Promise

Delete Record

Kind: static method of cxUserspace

Param Type Description
area string Datastore Name
key string | number Row Id

Example

await cxUserspace.delete('myDatabase', 1)

cxUserspace.deleteAll(area) ⇒ Promise

Delete Record All

Kind: static method of cxUserspace

Param Type Description
area string Datastore Name

Example

await cxUserspace.deleteAll('myDatabase')

cxUserspace.random(area, key) ⇒ Promise

Get Random Row

Kind: static method of cxUserspace

Param Type Description
area string Datastore Name
key string | number Row Id

Example

await cxUserspace.get('myDatabase', 1)

cxUserspace.knex(config, table) ⇒ Object

Get Knex Instance - Calling this function will return an instance of Knex (https://knexjs.org) The first parameter you specify the database name "default" should be your first param. Optionally the second parameter contains the table name

Kind: static method of cxUserspace

Param Type Description
config string | object Config
table string Table Name

Example

// Get Knex query pre-configured for a table (select)
const qry = await cxUserspace.knex({}, 'myTable')
Example
// Get a MySQL connection
const qry = await cxUserspace.knex({user: 'myUser', password: 'myPassword', host: 'myHost', database: 'myDatabase'})

cxUserspace.sql(sql, params) ⇒ Promise

Execute SQL Query with Parameters

Kind: static method of cxUserspace

Param Type Description
sql string SQL Query
params object Parameters

Example

await cxUserspace.sql('SELECT * from mytable WHERE id = ?', [1234])