Class: FromAdapter

FromAdapter

This is an adapter for the From class that provides the user with a convenient interface for selecting, deleting, and updating, all of which are queries that operate on a From instance.

Constructor

new FromAdapter()

Source:

Extends

Members

database

Properties:
Name Type Description
database Database A database instance.
escaper Escaper An instance of an Escaper class that can escape query parts.
queryExecuter QueryExecuter An instance of a QueryExecuter that can execute CRUD operations.
Inherited From:
Source:

paramList :ParameterList

A ParameterList instance that holds all of the query parameters.
Type:
Inherited From:
Source:

Methods

buildQuery() → {Query~QueryMeta}

Build the query.
Inherited From:
Source:
Returns:
The string-representation of the query to execute along with any query parameters.
Type
Query~QueryMeta

delete(tableAliasopt) → {Delete}

Delete from the table.
Parameters:
Name Type Attributes Description
tableAlias string <optional>
The unique alias of the table from which records will be deleted. Optional, defaults to the alias of the from table.
Source:
Returns:
A Delete instance that can be executed.
Type
Delete

(protected) getFromMeta() → {TableMetaList~TableMeta}

Helper method to get the meta data of the FROM table, which is the first table in the _tables map.
Inherited From:
Source:
Returns:
A meta object describing the table.
Type
TableMetaList~TableMeta

getFromString() → {string}

Get the FROM portion of the query as a string.
Inherited From:
Source:
Returns:
The FROM portion of the query (FROM <table> AS <alias>), escaped.
Type
string

(protected) getJoinMeta() → {Array.<TableMetaList~TableMeta>}

Helper method to get the meta data of the JOIN'd in tables.
Inherited From:
Source:
Returns:
A meta object describing the table.
Type
Array.<TableMetaList~TableMeta>

getJoinString() → {string}

Get the JOIN parts of the query string.
Inherited From:
Source:
Returns:
The JOIN parts of the query, escaped.
Type
string

getWhereString() → {string}

Get the WHERE portion of the query string.
Inherited From:
Source:
Returns:
The WHERE part of the query, or a blank string if there is no where clause.
Type
string

innerJoin(meta, params) → {this}

Inner join a table.
Parameters:
Name Type Description
meta TableMetaList~TableMeta | string See From#join
params Object See From#join
Inherited From:
Source:
Returns:
Type
this

join(meta, params) → {this}

Join a table.
Parameters:
Name Type Description
meta TableMetaList~TableMeta | string Either a TableMeta instance containing information about the table to join, or a string that can be parsed using the From#parseJoinString method.
params Object An object of key-value pairs that are used to replace parameters in the query.
Inherited From:
Source:
Returns:
Type
this

leftOuterJoin(meta, params) → {this}

Left outer join a table.
Parameters:
Name Type Description
meta TableMetaList~TableMeta | string See From#join
params Object See From#join
Inherited From:
Source:
Returns:
Type
this

parseFromString(fromStr) → {TableMetaList~TableMeta}

Parse the string fromStr and return a table meta object.
Parameters:
Name Type Description
fromStr string A from string, in the format <table-name>[ [as ]<table-alias>]. For example, any of these is valid: 'users'; 'users u'; 'users as u'; 'users AS u'.
Inherited From:
Source:
Returns:
A meta object that has "table" and "as" set.
Type
TableMetaList~TableMeta

parseJoinString(joinStr) → {TableMetaList~TableMeta}

Parse the string joinStr and return a table meta object. If a parent alias is provided, there must be exactly 1 relationship between the parent table and the child table, or an exception shall be raised. If the parent table owns the primary key, the relType will be single (e.g. it is a many-to-one relationship). If the child table owns the primary key, the relType will be many (it is a one-to-many relationship).
Parameters:
Name Type Description
joinStr string A join string, in the format [<parent-table-alias>.]<table-name>[ [as ]<table-alias>]. For example, any of these is valid (assuming 'u' is a valid parent table alias): 'u.phone_numbers'; 'u.phone_numbers pn'; 'u.phone_numbers as pn'; 'u.phone_numbers AS pn'; 'phone_numbers'; 'phone_numbers pn'; 'phone_numbers as pn'; 'phone_numbers AS pn'.
Inherited From:
Source:
Returns:
A meta object that has at least "table" and "as" set. "parent", "relType" and "cond" will also be set if a parent table alias is provided.
Type
TableMetaList~TableMeta

rightOuterJoin(meta, params) → {this}

Right outer join a table.
Parameters:
Name Type Description
meta TableMetaList~TableMeta | string See From#join
params Object See From#join
Inherited From:
Source:
Returns:
Type
this

select(…colsopt) → {Select}

Select from the table.
Parameters:
Name Type Attributes Description
cols object | string <optional>
<repeatable>
An optional set of columns to select.
Source:
See:
Returns:
A Select instance that can be executed.
Type
Select

toString() → {string}

Get the SQL that represents the query.
Inherited From:
Source:
Returns:
The actual SQL query (FROM, JOINS, and WHERE).
Type
string

update(model) → {Update}

Update a table.
Parameters:
Name Type Description
model Object The model describing what to update.
Source:
See:
Returns:
An Update instance that can be executed.
Type
Update

where(cond, params) → {this}

Add a where condition.
Parameters:
Name Type Description
cond Condition The condition object. For the format specs, reference ConditionCompiler.
params Object An object of key-value pairs that are used to replace parameters in the query.
Inherited From:
Source:
Returns:
Type
this