Constructor
new From(database, escaper, queryExecuter, meta)
Initialize the From instance. WHERE and JOINs can be applied.
Parameters:
Name | Type | Description |
---|---|---|
database |
Database | A Database instance that will be queried. |
escaper |
Escaper | An instance of an Escaper matching the database type (i.e. MySQLEscaper or MSSQLEscaper). |
queryExecuter |
QueryExecuter | A QueryExecuter instance. |
meta |
TableMetaList~TableMeta | string | Either a TableMeta instance containing information about the table to query from, or a string that can be parsed using the From#parseFromString method. |
- Source:
Extends
Members
(static, constant) JOIN_TYPE :Object
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
INNER |
string | INNER JOIN. |
LEFT_OUTER |
string | LEFT OUTER JOIN. |
RIGHT_OUTER |
string | RIGHT OUTER JOIN. |
- Source:
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:
- 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
(protected) getFromMeta() → {TableMetaList~TableMeta}
Helper method to get the meta data of the FROM table, which is the first
table in the _tables map.
- Source:
Returns:
A meta object describing the table.
getFromString() → {string}
Get the FROM portion of the query as a string.
- 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.
- Source:
Returns:
A meta object describing the table.
- Type
- Array.<TableMetaList~TableMeta>
getJoinString() → {string}
Get the JOIN parts of the query string.
- Source:
Returns:
The JOIN parts of the query, escaped.
- Type
- string
getWhereString() → {string}
Get the WHERE portion of the query string.
- 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 |
- 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. |
- 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 |
- 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'. |
- Source:
Returns:
A meta object that has "table" and
"as" set.
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'. |
- 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.
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 |
- Source:
Returns:
- Type
- this
toString() → {string}
Get the SQL that represents the query.
- Source:
Returns:
The actual SQL query (FROM, JOINS, and WHERE).
- Type
- string
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. |
- Source:
Returns:
- Type
- this