Skip to main content

TableMapping

@webda/sql


Class: TableMapping

Defined in: packages/sql/src/relational/mapping.ts:108

Maps the JSON of the models of one table to its columns and junction rows, and back

Constructors​

Constructor​

new TableMapping(plan, table, isA?): TableMapping

Defined in: packages/sql/src/relational/mapping.ts:145

Create a new TableMapping instance

Parameters​

plan​

RelationalSchemaPlan

the plan

table​

TablePlan

the table of the models

isA?​

(type, model) => boolean

whether a model is a subclass of another (the plan does not keep the hierarchy): the projections are compared without it

Returns​

TableMapping

Properties​

extraColumn​

readonly extraColumn: string | undefined

Defined in: packages/sql/src/relational/mapping.ts:116

Extra column


plan​

readonly plan: RelationalSchemaPlan

Defined in: packages/sql/src/relational/mapping.ts:146

the plan


primaryKey​

readonly primaryKey: string[]

Defined in: packages/sql/src/relational/mapping.ts:120

Primary key


table​

readonly table: TablePlan

Defined in: packages/sql/src/relational/mapping.ts:147

the table of the models


typeColumn​

readonly typeColumn: string

Defined in: packages/sql/src/relational/mapping.ts:112

Type column

Methods​

appliesTo()​

appliesTo(model, type): boolean

Defined in: packages/sql/src/relational/mapping.ts:355

Whether what a model declares applies to objects of a type: the same model, or an ancestor (without the hierarchy: a model whose projection is included in the type's)

Parameters​

model​

string

the declaring model

type​

string

the model identifier of the object

Returns​

boolean

true when the type is the model or one of its subclasses


decode()​

decode(value, column, decodeJson): unknown

Defined in: packages/sql/src/relational/mapping.ts:325

Decode operation

Parameters​

value​

unknown

a column value

column​

ColumnPlan

its column

decodeJson​

(v) => unknown

decoder of the JSON columns of the engine

Returns​

unknown

the JSON value, undefined for NULL


encode()​

encode(value, column): unknown

Defined in: packages/sql/src/relational/mapping.ts:294

Encode operation

Parameters​

value​

unknown

a JSON value

column​

ColumnPlan

the column receiving it

Returns​

unknown

the value to bind


fromRow()​

fromRow(row, junctionRows, decodeJson): Record<string, unknown>

Defined in: packages/sql/src/relational/mapping.ts:533

The JSON of a row: the extra column under the typed columns, references joined, junction rows folded

Parameters​

row​

Record<string, unknown>

the row

junctionRows​

Map<string, Record<string, unknown>[]>

the junction rows by attribute

decodeJson​

(v) => unknown

decoder of the JSON columns of the engine

Returns​

Record<string, unknown>

the serialized object, __type included when stored


junctions()​

junctions(): object[]

Defined in: packages/sql/src/relational/mapping.ts:227

Return the junction tables of the models of the table

Returns​

object[]

the junction tables of the models of the table


mapped()​

mapped(): Map<string, MappedSource>

Defined in: packages/sql/src/relational/mapping.ts:236

The ModelsMapped attributes of the models of the table the store fills on read, computed once (the mapping of a mapped table is built lazily: two tables may map each other)

Returns​

Map<string, MappedSource>

the sources, by attribute


ownerColumns()​

ownerColumns(junction, keyValues): Record<string, unknown>

Defined in: packages/sql/src/relational/mapping.ts:464

Return the owner columns of its junction rows

Parameters​

junction​

TablePlan

a junction table

keyValues​

Record<string, unknown>

the owner object (its primary key fields)

Returns​

Record<string, unknown>

the owner columns of its junction rows


projection()​

projection(model): string[]

Defined in: packages/sql/src/relational/mapping.ts:207

Return the columns the model reads and writes, those of the table root for an unknown model

Parameters​

model​

string

a model identifier

Returns​

string[]

the columns the model reads and writes, those of the table root for an unknown model


readColumns()​

readColumns(): string[]

Defined in: packages/sql/src/relational/mapping.ts:219

Read columns

Returns​

string[]

every column of the table, in table order


resolve()​

resolve(path): AttributeTarget

Defined in: packages/sql/src/relational/mapping.ts:178

Resolve operation

Parameters​

path​

string[]

an attribute path

Returns​

AttributeTarget

where the attribute lives


toRow()​

toRow(json, model, partial): RowWrite

Defined in: packages/sql/src/relational/mapping.ts:373

The columns and junction rows of an object

Parameters​

json​

Record<string, unknown>

the serialized object

model​

string

the model identifier of the repository, used when the object declares no known __type

partial​

boolean

only the fields present in the object (a patch), everything of the projection otherwise

Returns​

RowWrite

the row