Global

Members

columnAttributesKey

Symbol key that caches the model's non-virtual attribute definitions.

synchronizedKey

Symbol key that marks whether the model's table schema has been synchronized.

tableKey

Symbol key that stores the table name of the model.

Methods

BelongsTo()

design:type will be Function { [native code] } in following example

Example:
import type Foo from './foo';
class Bar extends Bone {
  

assertModelClassFields()

Assert that the instance has no own property shadowing a model attribute (emitted ES class fields). Throws LeoricClassFieldError when one is found, and marks the class as checked when the instance is clean.

collectLiteral(values, ast)

The ... IS NULL predicate is not parameterizable.

  • https://github.com/brianc/node-postgres/issues/1751
Parameters:
Name Type Description
values

the collected values

ast

the abstract syntax tree

compileModel()

Compile a declarative model class into a constructor that never runs its fields.

(async) disconnect(realm, callback)

Disconnect the realm from the database. Does nothing if the realm is not connected.

Parameters:
Name Type Description
realm

the realm to disconnect

callback

called once the connection is closed

Example:
await disconnect(realm);

executeValidator(ctx, name, attribute, setValue)

Execute a validator on a Bone instance

Parameters:
Name Type Description
ctx

context

name

validate name

attribute
setValue

findModel(spell, qualifiers)

Find model by qualifiers.

Parameters:
Name Type Description
spell
qualifiers
Example:
findModel(spell, ['comments'])
findModel(spell)

formatArgs(isInstance, fnName, args, target)

Parameters:
Name Type Description
isInstance

class or instance

fnName
args
target

class or instance }

formatConditions(conditions)

Format an array of conditions into an expression. Conditions will be joined with AND.

Parameters:
Name Type Description
conditions

An array of parsed where/having/on conditions

formatExpr(spell, ast)

Format the abstract syntax tree of an expression into escaped string.

Parameters:
Name Type Description
spell
ast

formatIdentifier(spell, ast)

Format identifiers into escaped string with qualifiers.

Parameters:
Name Type Description
spell
ast

formatOpExpr(spell, ast)

Format { type: 'op' } expressions into escaped string.

Parameters:
Name Type Description
spell
ast

hasCheckedModelClassFields()

Check whether the model class has been marked as checked for shadowing ES class fields.

instantiatable(spell)

Check if the query result of spell is instantiatable by examining the query structure.

  • https://www.yuque.com/leoric/blog/ciiard#XoI4O (zh-CN)
Parameters:
Name Type Description
spell

isAggregatorExpr()

Format the abstract syntax tree of an expression into escaped string.

isLogicalCondition(condition)

determine if query object is logical condition

Parameters:
Name Type Description
condition

query object

isLogicalOp()

Check if current token is logical operator or not, e.g. AND/NOT/OR.

isLogicalOperator(operator)

determin if operator is logical operator

Parameters:
Name Type Description
operator

lowercased operator

isModelClassReady()

Check whether the model class has been marked as ready.

isModelClassReadyOrInherited()

Check whether the model class is ready or inherits readiness from one of its ancestors. A class declaring its own attributes must be marked ready itself.

isOperatorCondition()

Check if object condition is an operator condition, such as { $gte: 100, $lt: 200 }.

markModelClassFieldsChecked()

Mark the model class as checked for ES class fields shadowing attribute accessors, so assertModelClassFields skips re-scanning its instances.

markModelClassReady()

Mark the model class as loaded and ready to be instantiated. Constructing a model class that is not ready throws LeoricModelDefinitionError.

parseLogicalOperator($op, value)

parse logical objects that is already in tree-like structure

Parameters:
Name Type Description
$op

logical operators, such as $or, $and, and $not.

value

logical operands

Example:
{ $or: { title: 'Leah', content: 'Diablo' } }
{ $or: [ { title: 'Leah' }, { content: 'Diablo' } ] }
{ $not: [ { title: 'Leah' }, { title: { $like: '%jjj' }} ] }

parseNamedLogicalOperator(name, condition)

parse logical objects that have column name lifted upper level

Parameters:
Name Type Description
name

column name

condition

logical query objects

Example:
{ foo: { $not: { $gt: '2021-01-01', $lte: '2021-12-31' } } }
{ foo: { $not: [ '2021-09-30', { $gte: '2021-10-07' } ] } }
{ foo: { $not: [ 'Leah', 'Nephalem' ] } }

parseObject()

Parse query objects, which is a complete madness because the operator orders vary. The result would be normalized spell ast. See module:src/query_object~OPERATOR_MAP and module:src/query_object~LOGICAL_OPERATOR_MAP for supported $ops.

Example:
{ foo: null }
{ foo: { $gt: new Date(2012, 4, 15) } }
{ foo: { $between: [1, 10] } }
{ foo: { $or: [ 'Leah', { $like: '%Leah%' } ] } }
{ foo: [ 1, 2, 3 ] }
{ foo: { $not: { $gt: '2021-01-01', $lte: '2021-12-31' } } }
{ foo: { $not: [ '2021-09-30', { $gte: '2021-10-07' } ] } }
{ foo: { $not: [ 'Leah', 'Nephalem' ] } }
{ $or: { title: 'Leah', content: 'Diablo' } }
{ $or: [ { title: 'Leah', content: 'Diablo' }, { title: 'Stranger' } ] }

parseOperator(name)

parse operator condition into expression ast

Parameters:
Name Type Description
name
Example:
parseOperator('id', { $gt: 0, $lt: 999999 });
// => { type: 'op', name: 'and', args: [ ... ]}

parseValue()

Parse object values as literal or subquery

(async) rawQuery()

raw query

setupSingleHook(target, hookName, func)

setup hook to class

Parameters:
Name Type Description
target

target class

hookName
func