Module query/sqlgenerator

Provides an SqlGenerator constructor capable of converting a query AST into a raw SQL query suitable for the underlying database.


SqlGenerator (store, aliases)

Creates a new SqlGenerator instance

Parameters

Store store The store to operate on
Object aliases The entity aliases referenced in the "from" clause of the query, if any

Returns

A newly created SqlGenerator instance

SqlGenerator.createSqlFunction (store, ast)

Convenience method for creating the raw SQL query generator function

Parameters

Store store The store to operate on
Node ast The query AST

Returns

Function The SQL generator function

See


SqlGenerator.prototype.aliases

An object containing entity aliases as property names and the entity name as values


SqlGenerator.prototype.createSqlFunction (ast)

Creates a function suitable for generating a raw SQL query based on the AST passed as argument. This function is cached together with the AST it's based on in the store's query cache.

Parameters

Node ast The query AST as produced by the query parser

Returns

Function The SQL generator function

SqlGenerator.prototype.getEntityMapping (name)

Returns the mapping for the entity with the given name

Parameters

String name The entity name or it's alias

Returns

Mapping The mapping for the entity

SqlGenerator.prototype.getPropertyMapping (name, property)

Returns the mapping for the given property

Parameters

String name The entity name or it's alias
String property The property name

Returns

PrimitiveMapping|ObjectMapping|CollectionMapping The property mapping

SqlGenerator.prototype.isAliased (name)

Returns true if the name passed as argument is an alias for an entity

Parameters

String name The entity name

Returns

Boolean True if an alias for this entity has been defined in the query, false otherwise

SqlGenerator.prototype.params

An array containing the descriptors of values specified in the query.


SqlGenerator.prototype.store

The store this generatore operates on


SqlGenerator.prototype.visitAggregation (node)

Returns the SQL representation of the aggregation passed as argument

Parameters

Aggregation node The aggregation node

Returns

String The SQL representation

SqlGenerator.prototype.visitBetweenCondition (node)

Returns the SQL representation of the "between" condition passed as argument

Parameters

BetweenCondition node The "between" condition node

Returns

String The SQL representation

SqlGenerator.prototype.visitComparison (node)

Returns the SQL representation of the comparison passed as argument

Parameters

Comparison node The comparison node

Returns

String The SQL representation

SqlGenerator.prototype.visitCondition (node)

Returns the SQL representation of the condition passed as argument

Parameters

Condition node The condition node

Returns

String The SQL representation

SqlGenerator.prototype.visitConditionList (node)

Returns the SQL representation of the condition list passed as argument

Parameters

ConditionList node The condition list node

Returns

String The SQL representation

SqlGenerator.prototype.visitEntity (node)

Returns the SQL representation ([<SchemaName>.]<TableName>[ <alias>]) of the entity passed as argument.

Parameters

Entity node The entity node

Returns

String The SQL representation

SqlGenerator.prototype.visitExistCondition (node)

Returns the SQL representation of the "exists" condition passed as argument

Parameters

ExistsCondition node The "exists" condition node

Returns

String The SQL representation

SqlGenerator.prototype.visitExpression (node)

Returns the SQL representation of the expression passed as argument

Parameters

Expression node The expression node

Returns

String The SQL representation

SqlGenerator.prototype.visitFactor (node)

Returns the SQL representation of the factor passed as argument

Parameters

Factor node The factor node

Returns

String The SQL representation

SqlGenerator.prototype.visitFromClause (node)

Returns the SQL representation of the "from" clause passed as argument

Parameters

FromClause node The "from" clause node

Returns

String The SQL representation

SqlGenerator.prototype.visitGroupByClause (node)

Returns the SQL representation of the "group by" clause passed as argument

Parameters

GroupByClause node The "group by" clause node

Returns

String The SQL representation

SqlGenerator.prototype.visitHavingClause (node)

Returns the SQL representation of the "having" clause passed as argument

Parameters

HavingClause node The "having" clause node

Returns

String The SQL representation

SqlGenerator.prototype.visitIdent (node)

Returns the SQL representation (<TableName|alias>.<ColumnName>) of the ident passed as argument.

Parameters

Ident node The ident node

Returns

String The SQL representation

SqlGenerator.prototype.visitInCondition (node)

Returns the SQL representation of the "in" condition passed as argument

Parameters

InCondition node The "in" condition node

Returns

String The SQL representation

SqlGenerator.prototype.visitInnerJoin (node)

Returns the SQL representation of the "inner join" passed as argument

Parameters

InnerJoin node The "inner join" node

Returns

String The SQL representation

SqlGenerator.prototype.visitIsNullCondition (node)

Returns the SQL representation of the "(not) null" condition passed as argument

Parameters

NullCondition node The node

Returns

String The SQL representation

SqlGenerator.prototype.visitJoinClause (node)

Returns the SQL representation of the "join" clause passed as argument

Parameters

JoinClause node The "join clause" node

Returns

String The SQL representation

SqlGenerator.prototype.visitLikeCondition (node)

Returns the SQL representation of the "like" condition passed as argument

Parameters

LikeCondition node The "like" condition node

Returns

String The SQL representation

SqlGenerator.prototype.visitNotCondition (node)

Returns the SQL representation of the "not" condition passed as argument

Parameters

NotCondition node The "not" condition node

Returns

String The SQL representation

SqlGenerator.prototype.visitOrderBy (node)

Returns the SQL representation of the "order by" passed as argument

Parameters

OrderBy node The "order by" node

Returns

String The SQL representation

SqlGenerator.prototype.visitOrderByClause (node)

Returns the SQL representation of the "order by" clause passed as argument

Parameters

OrderByClause node The "order by" clause node

Returns

String The SQL representation

SqlGenerator.prototype.visitOuterJoin (node)

Returns the SQL representation of the "outer join" passed as argument

Parameters

OuterJoin node The "outer join" node

Returns

String The SQL representation

SqlGenerator.prototype.visitParameterValue (node)

Pushes the name of the named parameter referenced in the query (:<name>) into the internal params array and returns a question mark as placeholder for the parameter in the SQL query

Parameters

ParameterValue node The parameter value node

Returns

String A question mark

SqlGenerator.prototype.visitSelect (node)

Returns the SQL representation of the select statement passed as argument

Parameters

Select node The select node (i.e. the root node of the query AST)

Returns

String The SQL representation

SqlGenerator.prototype.visitSelectClause (node)

Returns the SQL representation of the "select" clause passed as argument

Parameters

SelectClause node The "select" clause node

Returns

String The SQL representation

SqlGenerator.prototype.visitSelectEntity (node)

Returns the SQL representation of the select entity passed as argument (i.e. an entity referenced in the select clause)

Parameters

SelectEntity node The select entity node

Returns

String The SQL representation

SqlGenerator.prototype.visitSelectExpression (node)

Returns the SQL representation of the select expression passed as argument

Parameters

SelectExpression node The select expression node

Returns

String The SQL representation

SqlGenerator.prototype.visitSummand (node)

Returns the SQL representation of the summand passed as argument

Parameters

Summand node The summand node

Returns

String The SQL representation

SqlGenerator.prototype.visitValue (node)

Pushes the value descriptor (an object containing the type of the value and the value itself) into the params array of this generator, and returns a question mark as placeholder for the parameter in the SQL query.

Parameters

Value node The value node

Returns

String A question mark

SqlGenerator.prototype.visitWhereClause (node)

Returns the SQL representation of the "where" clause passed as argument

Parameters

WhereClause node The "where clause" node

Returns

String The SQL representation