Skip to content

routier-collection


routier-collection / core/src / SqlTranslator

Class: SqlTranslator<TRoot, TShape>

Defined in: core/src/plugins/translators/SqlTranslator.ts:48

Extends

Type Parameters

TRoot

TRoot extends object

TShape

TShape

Constructors

Constructor

new SqlTranslator<TRoot, TShape>(query, pushedDown): SqlTranslator<TRoot, TShape>

Defined in: core/src/plugins/translators/SqlTranslator.ts:52

Parameters

query

IQuery<TRoot, TShape>

pushedDown

SqlPushdown = {}

Returns

SqlTranslator<TRoot, TShape>

Overrides

DataTranslator.constructor

Methods

translate()

translate(data): ITranslatedValue<TShape>

Defined in: core/src/plugins/translators/DataTranslator.ts:75

Parameters

data

unknown

Returns

ITranslatedValue<TShape>

Inherited from

DataTranslator.translate


count()

count<TResult>(data, _): TResult

Defined in: core/src/plugins/translators/SqlTranslator.ts:57

Type Parameters

TResult

TResult extends number

Parameters

data

unknown

_

QueryOption<TShape, "count">

Returns

TResult

Overrides

DataTranslator.count


min()

min<TResult>(data, _): TResult

Defined in: core/src/plugins/translators/SqlTranslator.ts:72

Type Parameters

TResult

TResult extends string | number | Date

Parameters

data

unknown

_

QueryOption<TShape, "min">

Returns

TResult

Overrides

DataTranslator.min


max()

max<TResult>(data, _): TResult

Defined in: core/src/plugins/translators/SqlTranslator.ts:76

Type Parameters

TResult

TResult extends string | number | Date

Parameters

data

unknown

_

QueryOption<TShape, "max">

Returns

TResult

Overrides

DataTranslator.max


sum()

sum<TResult>(data, _): TResult

Defined in: core/src/plugins/translators/SqlTranslator.ts:80

Type Parameters

TResult

TResult extends number

Parameters

data

unknown

_

QueryOption<TShape, "sum">

Returns

TResult

Overrides

DataTranslator.sum


distinct()

distinct<TResult>(data, _): TResult

Defined in: core/src/plugins/translators/SqlTranslator.ts:93

Type Parameters

TResult

TResult

Parameters

data

unknown

_

QueryOption<TShape, "distinct">

Returns

TResult

Overrides

DataTranslator.distinct


filter()

filter<TResult>(data, _): TResult

Defined in: core/src/plugins/translators/SqlTranslator.ts:97

Type Parameters

TResult

TResult

Parameters

data

unknown

_

QueryOption<TShape, "filter">

Returns

TResult

Overrides

DataTranslator.filter


skip()

skip(data, _): TShape

Defined in: core/src/plugins/translators/SqlTranslator.ts:101

Parameters

data

unknown

_

QueryOption<TShape, "skip">

Returns

TShape

Overrides

DataTranslator.skip


take()

take(data, _): TShape

Defined in: core/src/plugins/translators/SqlTranslator.ts:105

Parameters

data

unknown

_

QueryOption<TShape, "take">

Returns

TShape

Overrides

DataTranslator.take


sort()

sort(data, _): TShape

Defined in: core/src/plugins/translators/SqlTranslator.ts:109

Parameters

data

unknown

_

QueryOption<TShape, "sort">

Returns

TShape

Overrides

DataTranslator.sort


nearest()

nearest(data, option): TShape

Defined in: core/src/plugins/translators/SqlTranslator.ts:128

Scores in memory, unlike every other shaper here.

The pass-throughs above are safe because the SQL that produced these rows contained the corresponding clause. No sql-core statement contains a similarity ordering — engines that can express one are the exception, not the rule — so passing the data through would return whatever order the engine happened to produce.

A plugin whose engine DID push the search down overrides this with a pass-through, gated on option.target. Postgres is the only one today.

Rows arrive keyed by storage column name and are read that way rather than through the option's selector, because the selector is written against the entity shape and these rows have not been deserialized into it yet.

Parameters

data

unknown

option

QueryOption<TShape, "nearest">

Returns

TShape

Overrides

DataTranslator.nearest


join()

join(data, option): TShape

Defined in: core/src/plugins/translators/SqlTranslator.ts:153

Passes through only when the statement really did contain the JOIN, and refuses otherwise.

The pass-throughs above are safe unconditionally because the SQL that produced these rows contained the corresponding clause. A join is not like that: if the plugin did not emit one, these rows are the outer side alone, and passing them through hands the caller entities where the contract says tuples — every ([outer, inner]) => ... lambda downstream then destructures the wrong object, and nothing errors.

So the plugin has to say, and the default is to refuse. A plugin that DID emit the join has already split each flat row into its two deserialized halves (splitJoinRows in @routier/sql-plugin-core), so by the time the option is walked the work is done.

Parameters

data

unknown

option

QueryOption<TShape, "join">

Returns

TShape

Overrides

DataTranslator.join


group()

group<T>(data, option): T

Defined in: core/src/plugins/translators/SqlTranslator.ts:165

Type Parameters

T

T

Parameters

data

unknown

option

QueryOption<T, "group">

Returns

T

Overrides

DataTranslator.group


map()

map(data, option): TShape

Defined in: core/src/plugins/translators/SqlTranslator.ts:201

Parameters

data

unknown

option

QueryOption<TShape, "map">

Returns

TShape

Overrides

DataTranslator.map

Released under the MIT License.