cxUserspace

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
}

Methods

(static) create(area, key, data) → {Promise}

Description:
  • Create Record (With Primary Key)

Example
await cxUserspace.create('myDatabase', 1, {value: 'Hello World!'})
Parameters:
Name Type Description
area string

Datastore Name

key string | number

Row Id

data object

Data Object / Row

Returns:
Type
Promise

(static) delete(area, key) → {Promise}

Description:
  • Delete Record

Example
await cxUserspace.delete('myDatabase', 1)
Parameters:
Name Type Description
area string

Datastore Name

key string | number

Row Id

Returns:
Type
Promise

(static) deleteAll(area) → {Promise}

Description:
  • Delete Record All

Example
await cxUserspace.deleteAll('myDatabase')
Parameters:
Name Type Description
area string

Datastore Name

Returns:
Type
Promise

(static) get(area, key) → {Promise}

Description:
  • Get Row

Example
await cxUserspace.get('myDatabase', 1)
Parameters:
Name Type Description
area string

Datastore Name

key string | number

Row Id

Returns:
Type
Promise

(static) getPk(area) → {Promise}

Description:
  • Get Primary Key

Example
await cxUserspace.getPk('myTable')
Parameters:
Name Type Description
area string

Datastore Name

Returns:
Type
Promise

(static) insert(area, data) → {Promise}

Description:
  • Insert Record

Example
await cxUserspace.insert('myDatabase', {value: 'Hello World!'})
Parameters:
Name Type Description
area string

Datastore Name

data object

Data Object / Row

Returns:
Type
Promise

(static) knex(config, tablenullable) → {Object}

Description:
  • 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

Examples
// Get Knex query pre-configured for a table (select)
const qry = await cxUserspace.knex({}, 'myTable')
// Get a MySQL connection
const qry = await cxUserspace.knex({user: 'myUser', password: 'myPassword', host: 'myHost', database: 'myDatabase'})
Parameters:
Name Type Attributes Description
config string | object

Config

table string <nullable>

Table Name

Returns:
Type
Object

(static) random(area, key) → {Promise}

Description:
  • Get Random Row

Example
await cxUserspace.get('myDatabase', 1)
Parameters:
Name Type Description
area string

Datastore Name

key string | number

Row Id

Returns:
Type
Promise

(static) read(area, key) → {Promise}

Description:
  • Read Value from Record

Example
await cxUserspace.read('myDatabase', 1)
Parameters:
Name Type Description
area string

Datastore Name

key string | number

Row Id

Returns:
Type
Promise

(static) sql(sql, params) → {Promise}

Description:
  • Execute SQL Query with Parameters

Example
await cxUserspace.sql('SELECT * from mytable WHERE id = ?', [1234])
Parameters:
Name Type Description
sql string

SQL Query

params object

Parameters

Returns:
Type
Promise

(static) update(area, key, data) → {Promise}

Description:
  • Update Record

Example
await cxUserspace.update('myDatabase', 1, {value: 'Hello World!'})
Parameters:
Name Type Description
area string

Datastore Name

key string | number

Row Id

data object

Data Object / Row

Returns:
Type
Promise