Module: Table

Table factory.
Mixes In:
Source:

Methods

(static) escapeIdentifier()

Internal utility function.
Source:

count() → {Promise.<number>}

Retrieve the total number of rows in the table.
Deprecated:
  • since version 8.0.12. Will be removed in future versions.
Source:
Returns:
Type
Promise.<number>

delete(expropt) → {module:TableDelete}

Create operation to delete rows from a table.
Parameters:
Name Type Attributes Description
expr SearchConditionStr <optional>
filtering criteria
Source:
Returns:
The operation instance.
Type
module:TableDelete
Example
// delete all rows from a table
table.delete('true')

// delete rows that match a given criteria
table.delete('`name` == "foobar"')

existsInDatabase() → {Promise.<boolean>}

Check if the table exists in the database.
Source:
Returns:
Type
Promise.<boolean>

getName() → {string}

Retrieve the table name.
Source:
Returns:
Type
string

getSchema() → {module:Schema}

Retrieve the schema associated to the table.
Source:
Returns:
Type
module:Schema

insert(fields) → {module:TableInsert}

Create operation to insert rows in the table.
Parameters:
Name Type Description
fields string | Array.<string> | Object column names or column-value object
Source:
Throws:
When the input type is invalid.
Type
Error
Returns:
The operation instance.
Type
module:TableInsert
Example
// arguments as column names
table.insert('foo', 'bar')

// array of column names
table.insert(['foo', 'bar'])

// object with column name and value
table.insert({ foo: 'baz', bar: 'qux' })

inspect() → {Object}

Retrieve the table metadata.
Source:
Returns:
An object containing the relevant metadata.
Type
Object

isView() → {Promise.<boolean>}

Check whether the table is a view.
Source:
Returns:
Type
Promise.<boolean>

select(expropt) → {module:TableSelect}

Create operation to select rows from the table.
Parameters:
Name Type Attributes Description
expr string | Array.<string> <optional>
columns to be projected
Source:
Throws:
When an expression is invalid.
Type
Error
Returns:
The operation instance.
Type
module:TableSelect
Example
// all columns should be projected
const selection = table.select()

// arguments as columns to be projected
const selection = table.select('foo', 'bar')

// array of columns to be projected
const selection = table.select(['foo', 'bar'])

update(expropt) → {module:TableUpdate}

Create operation to update rows in the table.
Parameters:
Name Type Attributes Description
expr string <optional>
filtering criteria
Source:
Returns:
The operation instance.
Type
module:TableUpdate
Example
// update all rows in a table
table.update('true').set('name', 'foo')
table.update().where('true').set('name', 'foo')

// update rows that match a given criteria
table.update().where('`name` == "foo"').set('name', 'bar')