RelationalRepository
Class: RelationalRepository<T>
Defined in: packages/sql/src/relational/repository.ts:75
Repository of a model stored in a typed table: one column per field, foreign keys for the links, junction tables for the link collections, the unknown properties in the extra JSON column
Every statement names its columns from the plan projection of the written model, so a database shared by several application versions keeps the columns a version does not know.
Extends
Type Parameters
T
T extends ModelClass
Constructors
Constructor
new RelationalRepository<
T>(model,pks,options):RelationalRepository<T>
Defined in: packages/sql/src/relational/repository.ts:91
Create a new RelationalRepository instance
Parameters
model
T
the model class
pks
string[]
primary key field names
options
the plan, the table and the connection
Returns
RelationalRepository<T>
Overrides
Properties
[WEBDA_TEST]
[WEBDA_TEST]:
object
Defined in: packages/models/lib/repositories/memory.d.ts:329
Test utilities - clears all stored data
clear
clear: () =>
Promise<void>
Returns
Promise<void>
Inherited from
aggregationOptions
protectedaggregationOptions:AggregationOptions
Defined in: packages/models/lib/repositories/abstract.d.ts:27
Aggregation fallback policy, set by the owning store through configureAggregation
Inherited from
SQLRepository.aggregationOptions
dialect
protectedreadonlydialect:SQLDialect
Defined in: packages/sql/src/repository.ts:39
the engine syntax
Inherited from
events
protectedevents:Map<keyofInstanceType<T>[typeofWEBDA_EVENTS],Set<(data) =>void>>
Defined in: packages/models/lib/repositories/abstract.d.ts:25
Registered event listeners keyed by event name
Inherited from
mapping
readonlymapping:TableMapping
Defined in: packages/sql/src/relational/repository.ts:79
Mapping
maxListeners
protectedmaxListeners:number
Defined in: packages/models/lib/repositories/abstract.d.ts:336
Max-listeners hint kept for Node EventEmitter API compatibility. Not
enforced — repositories use an unbounded Set per event.
Inherited from
model
protectedmodel:T
Defined in: packages/models/lib/repositories/abstract.d.ts:21
Inherited from
monitorOptions
protectedmonitorOptions:QueryMonitorOptions
Defined in: packages/models/lib/repositories/abstract.d.ts:29
Query monitoring options, set by the owning store through configureMonitoring
Inherited from
pks
protectedpks:string[]
Defined in: packages/models/lib/repositories/abstract.d.ts:22
Inherited from
prepare?
protectedreadonlyoptionalprepare?: () =>Promise<void>
Defined in: packages/sql/src/repository.ts:58
Awaited before every statement (e.g. to ensure the table exists)
Returns
Promise<void>
Inherited from
separator
protectedseparator:string
Defined in: packages/models/lib/repositories/abstract.d.ts:23
Inherited from
storage
protectedstorage:Map
Defined in: packages/models/lib/repositories/memory.d.ts:42
Storage
Inherited from
table
protectedreadonlytable:string
Defined in: packages/sql/src/repository.ts:35
the table name
Inherited from
tableModel?
protectedreadonlyoptionaltableModel?:string
Defined in: packages/sql/src/repository.ts:68
Identifier of the model the table was declared for: unstamped rows belong to it
Inherited from
tableRoot?
protectedoptionaltableRoot?:ModelClass<Storable<any,any>>
Defined in: packages/models/lib/repositories/abstract.d.ts:35
Model owning the untyped rows of the storage (the first model of the store), undefined when not known
Inherited from
transact
protectedreadonlytransact:Transact
Defined in: packages/sql/src/relational/repository.ts:83
Transact
transactionClient?
protectedreadonlyoptionaltransactionClient?: () =>SQLClient|undefined
Defined in: packages/sql/src/repository.ts:53
The client of the transaction active in the current async chain, undefined outside one
Returns
SQLClient | undefined
Inherited from
SQLRepository.transactionClient
warnedAggregations
protectedwarnedAggregations:Set<string>
Defined in: packages/models/lib/repositories/abstract.d.ts:31
Fallback shapes already warned about
Inherited from
SQLRepository.warnedAggregations
Accessors
client
Get Signature
get
protectedclient():SQLClient
Defined in: packages/sql/src/repository.ts:78
The client the statements run on
Resolved on every access: a repository handed out before its store connected (Store.computeStores asks every store for its repositories from the first store init) or kept across a stop()/init() cycle uses the current one.
Throws
when the store has no client, i.e. is not initialized or is stopped
Returns
the client
Inherited from
sql
Get Signature
get
protectedsql():RelationalDialect
Defined in: packages/sql/src/relational/repository.ts:110
Get the engine syntax
Returns
the engine syntax
Methods
__clean()
__clean():
Promise<void>
Defined in: packages/sql/src/relational/repository.ts:1405
Delete every row of the table and of its junctions (tests), in one transaction so the deferred foreign keys of a self reference are checked once every row is gone
Returns
Promise<void>
Overrides
acceptedTypes()
acceptedTypes():
string[]
Defined in: packages/models/lib/repositories/abstract.d.ts:71
Every stored __type value of this model and its transitive subclasses, for stores filtering in their query
language
Returns
string[]
the values, empty when the model carries no Metadata
Inherited from
aggregate()
aggregate<
G,M>(spec,params?):Promise<AggregationResult<AggregatedRow<InstanceType<T>,G,M>>>
Defined in: packages/models/lib/repositories/abstract.d.ts:271
Keep the full generic signature here (not spec: any): concrete repositories are used
directly in code and tests, and must expose the typed rows.
Type Parameters
G
G extends readonly _NonFunctionPropertyPaths<InstanceType<T>>[] = []
M
M extends Record<string, MetricSpec<InstanceType<T>>> = Record<string, MetricSpec<InstanceType<T>>>
Parameters
spec
AggregationSpec<InstanceType<T>, G, M>
params?
QueryParameters
Returns
Promise<AggregationResult<AggregatedRow<InstanceType<T>, G, M>>>
Inherited from
aggregateInMemory()
protectedaggregateInMemory(query):Promise<Record<string,unknown>[]>
Defined in: packages/models/lib/repositories/abstract.d.ts:316
Aggregate by streaming the filtered items
Parameters
query
AggregationQuery
the aggregation
Returns
Promise<Record<string, unknown>[]>
the rows
Inherited from
SQLRepository.aggregateInMemory
applyAssignments()
protectedapplyAssignments<O>(target,assignments):O
Defined in: packages/models/lib/repositories/abstract.d.ts:181
Set the assignments of an UPDATE on an object, creating the intermediate objects of dotted paths
Targets were checked by parseStatement: letters, digits and _ only, no __ segment, no
Object.prototype member name.
Type Parameters
O
O
Parameters
target
O
the object to change in place
assignments
Assignment[]
the SET assignments
Returns
O
the target
Inherited from
SQLRepository.applyAssignments
assignments()
protectedassignments(row,args):string[]
Defined in: packages/sql/src/relational/repository.ts:951
The SET assignments of a row write: the extra column merged, the type kept when the data declares none
Parameters
row
Pick<RowWrite, "columns" | "values">
the row
args
unknown[]
the statement parameters, extended
Returns
string[]
the assignments
attributeName()
protectedattributeName(attribute):string
Defined in: packages/sql/src/relational/repository.ts:142
Return the description of the attribute, for messages
Parameters
attribute
string[]
a WebdaQL attribute
Returns
string
the description of the attribute, for messages
backfillTypes()
backfillTypes():
Promise<number>
Defined in: packages/sql/src/relational/repository.ts:133
Typed rows are always stamped
Returns
Promise<number>
Overrides
belongsToModel()
belongsToModel(
stored?):boolean
Defined in: packages/models/lib/repositories/abstract.d.ts:77
Whether a stored row belongs to this model, for stores filtering in memory
Parameters
stored?
string
the stored __type, undefined for an untyped row
Returns
boolean
true when the row belongs to this model (always without Metadata)
Inherited from
buildAggregationSQL()
buildAggregationSQL(
query,where?):object
Defined in: packages/sql/src/repository.ts:682
Translate an aggregation to SQL
The query is validated again here and paths are checked once more, so they are safe to interpolate.
Columns get positional names (gN per group path, mN / nN / sN per metric index), mapped back to
the aliases by decode: alias length or shared prefixes never meet an identifier length limit.
MIN / MAX select a numeric and a text candidate, merged by decode.
Parameters
query
AggregationQuery
the aggregation
where?
string
extra WHERE condition (class condition), optional
Returns
object
the statement and the row decoder
decode
decode: (
row) =>any
Parameters
row
any
Returns
any
sql
sql:
string
Inherited from
SQLRepository.buildAggregationSQL
buildClassFilter()
protectedbuildClassFilter():string|undefined
Defined in: packages/models/lib/repositories/memory.d.ts:190
Build the WebdaQL class-filter clause __type IN ['A', 'B', ...] covering
this.model's identifier and every transitive descendant.
Returns undefined when the model carries no Metadata.
Returns
string | undefined
the class-filter WebdaQL clause, or undefined when no Metadata
Inherited from
SQLRepository.buildClassFilter
buildClassFilterIdentifiers()
protectedbuildClassFilterIdentifiers():string[] |undefined
Defined in: packages/models/lib/repositories/memory.d.ts:181
Collect the WebdaQL class-filter identifier list — this.model's
identifier and every transitive descendant.
Returns undefined when the model carries no Metadata (plain unit-test
classes that didn't go through Application.setModelMetadata). In that
case query() skips the prepend and returns everything in storage,
preserving the pre-fix behavior for those bare classes.
Returns
string[] | undefined
the list of identifiers to match, or undefined when no Metadata
Inherited from
SQLRepository.buildClassFilterIdentifiers
buildCountSQL()
buildCountSQL(
filter,max?):string
Defined in: packages/sql/src/repository.ts:811
Translate a count to SQL: one COUNT(*) over the filter, or over a sub-select stopped at max + 1 rows so a
capped count reads at most max + 1 rows
Parameters
filter
Expression
the WebdaQL filter
max?
number
stop after max rows, undefined for an exact count
Returns
string
the statement, its n column holds the count
Inherited from
buildItem()
protectedbuildItem(data):InstanceType<T>
Defined in: packages/models/lib/repositories/abstract.d.ts:101
Build the model instance to create from the incoming data
Primary key fields that are undefined or null are dropped from the data so a key generated by the model constructor (e.g. UuidModel) is not overwritten. Repositories must read the storage key from the returned instance.
Parameters
data
Helpers<InstanceType<T>>
the incoming data
Returns
InstanceType<T>
the model instance
Inherited from
checkAggregationFallback()
protectedcheckAggregationFallback(query,reason):Promise<void>
Defined in: packages/models/lib/repositories/abstract.d.ts:287
Apply the fallback policy before aggregating or counting in memory
Parameters
query
AggregationQuery | undefined
the aggregation, undefined for a count
reason
string
why it cannot run natively
Returns
Promise<void>
Throws
AggregationError AGGREGATION_NOT_NATIVE when the policy is deny
Inherited from
SQLRepository.checkAggregationFallback
checkCondition()
protectedcheckCondition<K>(item,conditionField?,condition?):void
Defined in: packages/models/lib/repositories/memory.d.ts:71
Verify an optimistic locking condition on an item
Type Parameters
K
K extends string
Parameters
item
InstanceType<T>
The item to check
conditionField?
K | null
Field to validate
condition?
any
Expected value
Returns
void
Throws
Error if the condition does not match
Inherited from
checkItemWriteCondition()
protectedcheckItemWriteCondition(item,index,itemWriteConditionField,itemWriteCondition):void
Defined in: packages/models/lib/repositories/memory.d.ts:321
Verify a write condition on a collection item
Parameters
item
any[]
The array to check
index
number
Index of the item in the array
itemWriteConditionField
string
Field name to check on the item
itemWriteCondition
any
Expected value for the field
Returns
void
Throws
Error if the condition does not match
Inherited from
SQLRepository.checkItemWriteCondition
checkPath()
protectedcheckPath(attribute):string[]
Defined in: packages/sql/src/repository.ts:172
Check the segments of a path written inside a SQL literal: letters, digits and _, like WebdaQL identifiers
Parameters
attribute
string[]
the attribute path
Returns
string[]
the validated segments
Throws
Error for any other character
Inherited from
collectionTarget()
protectedcollectionTarget(collection): {column:ColumnPlan;kind:"json";path:string[]; } | {kind:"junction";relation:RelationPlan;table:TablePlan; } | {column:ColumnPlan;kind:"extra";path:string[]; }
Defined in: packages/sql/src/relational/repository.ts:1183
Return its JSON column, or its junction when it is a simple link array
Parameters
collection
any
a collection attribute
Returns
{ column: ColumnPlan; kind: "json"; path: string[]; } | { kind: "junction"; relation: RelationPlan; table: TablePlan; } | { column: ColumnPlan; kind: "extra"; path: string[]; }
its JSON column, or its junction when it is a simple link array
Throws
WebdaError.BadRequest for any other attribute
collectStatementKeys()
protectedcollectStatementKeys(statement):Promise<PrimaryKeyType<InstanceType<T>>[]>
Defined in: packages/models/lib/repositories/abstract.d.ts:188
Keys of the objects matching the WHERE of a statement, collected before any change so an update changing a WHERE field cannot meet the same object twice; at most LIMIT keys
Parameters
statement
Query
the parsed statement
Returns
Promise<PrimaryKeyType<InstanceType<T>>[]>
the primary keys
Inherited from
SQLRepository.collectStatementKeys
columnComparison()
protectedcolumnComparison(column,type,expression):Expression
Defined in: packages/sql/src/relational/repository.ts:246
Return the comparison rendered for the column type, IN as = alternatives
Parameters
column
string
a quoted (qualified) column
type
ColumnType
its type
expression
ComparisonExpression
the comparison
Returns
Expression
the comparison rendered for the column type, IN as = alternatives
columnOfField()
protectedcolumnOfField(field):string
Defined in: packages/sql/src/relational/repository.ts:525
Return its column name
Parameters
field
string
a field of the model
Returns
string
its column name
configureAggregation()
configureAggregation(
options):void
Defined in: packages/models/lib/repositories/abstract.d.ts:243
Copy the known options (fallback, maxGroups, warn); undefined values keep the current ones
Parameters
options
Partial<AggregationOptions>
Returns
void
Throws
Error when maxGroups is not a positive integer or fallback is unknown
Inherited from
SQLRepository.configureAggregation
configureMonitoring()
configureMonitoring(
options):void
Defined in: packages/models/lib/repositories/abstract.d.ts:248
Configure the query monitoring policy, called by the owning store
Parameters
options
Partial<QueryMonitorOptions>
options to override
Returns
void
Inherited from
SQLRepository.configureMonitoring
count()
count(
filter?,params?,options?):Promise<CountResult>
Defined in: packages/models/lib/repositories/abstract.d.ts:293
Parse the filter, refuse statements, drop ORDER BY / LIMIT / OFFSET and run executeCount
Parameters
filter?
string
params?
QueryParameters
options?
CountOptions
Returns
Promise<CountResult>
Throws
Error when max is not a positive integer
Inherited from
countInMemory()
protectedcountInMemory(filter,max?):Promise<Omit<CountResult,"native">>
Defined in: packages/models/lib/repositories/abstract.d.ts:310
Count by streaming the filtered items, stopping at max + 1
Parameters
filter
Expression
the filter
max?
number
stop after max objects, undefined for an exact count
Returns
Promise<Omit<CountResult, "native">>
the value and its relation
Inherited from
create()
create(
data,_save?):Promise<any>
Defined in: packages/sql/src/relational/repository.ts:1006
Parameters
data
any
_save?
boolean = true
Returns
Promise<any>
Overrides
currentTypeOf()
protectedcurrentTypeOf(instance,stored?):string|undefined
Defined in: packages/models/lib/repositories/memory.d.ts:144
The __type to attach to a loaded instance: the current identifier of its class, the stored value when it is
unknown or ambiguous (never rewritten to a guess), the repository model identifier for an untyped row
Parameters
instance
any
the loaded instance
stored?
string
the stored __type
Returns
string | undefined
the value to attach
Inherited from
declaredType()
protecteddeclaredType(item):string|undefined
Defined in: packages/sql/src/repository.ts:308
The type an object written by the application declares: the __type its row was read with (non-enumerable,
set by fromJSON), else the identifier of its class. Plain data declares none, whatever its keys.
Parameters
item
any
the object
Returns
string | undefined
the model identifier, undefined for plain data
Inherited from
delete()
delete(
primaryKey,conditionField?,condition?):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:1063
Parameters
primaryKey
any
conditionField?
any
condition?
any
Returns
Promise<void>
Overrides
deleteItemFromCollection()
deleteItemFromCollection(
primaryKey,collection,index,itemWriteConditionField?,itemWriteCondition?):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:1304
Parameters
primaryKey
any
collection
any
index
number
itemWriteConditionField?
any
itemWriteCondition?
any
Returns
Promise<void>
Overrides
SQLRepository.deleteItemFromCollection
deleteMany()
deleteMany(
statement,params?):Promise<number>
Defined in: packages/sql/src/repository.ts:856
Delete in bulk with one DELETE ... WHERE: no per-object event (see Repository.deleteMany)
Parameters
statement
string | Query
params?
QueryParameters
Returns
Promise<number>
Inherited from
deleteManyByKey()
protecteddeleteManyByKey(statement,params?):Promise<number>
Defined in: packages/models/lib/repositories/abstract.d.ts:206
Generic deleteMany: collect the matching keys (up to LIMIT), then delete them one by one with this
repository's delete primitive
Used by stores without a native bulk delete. On a store repository the primitive emits no event.
Parameters
statement
string | Query
the DELETE statement or its parsed form
params?
QueryParameters
values for the placeholders
Returns
Promise<number>
the number of objects deleted
Inherited from
describeUnique()
protecteddescribeUnique(violation):string
Defined in: packages/sql/src/relational/repository.ts:727
Return the fields it covers when the plan knows it, what the engine said otherwise
Parameters
violation
a violated unique index, by name or by columns
Returns
string
the fields it covers when the plan knows it, what the engine said otherwise
deserialize()
deserialize(
item):InstanceType<T>
Defined in: packages/models/lib/repositories/memory.d.ts:125
Unserialize the object from a string
Beyond restoring the concrete type via @webda/serialize's
$serializer.type typeKey, this also surfaces the storage envelope's
__type stamp on the in-memory instance as a NON-ENUMERABLE property. The
non-enumerable bit keeps __type invisible to JSON.stringify and
Object.keys (so API responses and re-serialize cycles are byte-identical
for the model's own fields), while still being readable via direct
property access — which is exactly how WebdaQL's filter eval reads it
(ComparisonExpression.getAttributeValue walks obj[name]).
Backward-compat: legacy rows written before the envelope-stamping was
introduced won't carry __type. In that case we backfill from the
repository's own model.Metadata.Identifier so they look like records of
the parent class — which is exactly what query()'s prepended class
filter expects (parent + descendants). Plain unit-test classes without
Metadata get no stamp at all; their repos opt out of class filtering on
the query side too (see query).
Parameters
item
string
the serialized string
Returns
InstanceType<T>
the deserialized model instance
Inherited from
deserializeEnvelope()
protecteddeserializeEnvelope(item,raw,stored?):any
Defined in: packages/models/lib/repositories/memory.d.ts:136
Deserialize a serializer envelope
A row written under a model's former identifier (renamed, see @WebdaAlias) names a serializer that no longer
exists: it is deserialized with the serializer of the class its __type resolves to.
Parameters
item
string
the stored string
raw
any
the parsed envelope
stored?
string
the stored __type
Returns
any
the instance
Inherited from
SQLRepository.deserializeEnvelope
duplicateExpression()
duplicateExpression(
expression):Expression
Defined in: packages/sql/src/relational/repository.ts:221
A comparison on a typed column renders for its type, on a link collection as a sub-query on its junction, on a composite reference on its key parts; everything else is the JSON translation
Parameters
expression
Expression
Returns
Expression
Overrides
SQLRepository.duplicateExpression
emit()
emit<
K>(event,data):Promise<void>
Defined in: packages/models/lib/repositories/abstract.d.ts:361
Emit an event to all registered listeners and await their completion.
Type Parameters
K
K extends string | number | symbol
Parameters
event
K
The event name to emit
data
InstanceType<T>[typeof WEBDA_EVENTS][K]
The event payload
Returns
Promise<void>
Inherited from
excludePrimaryKey()
excludePrimaryKey(
object):any
Defined in: packages/models/lib/repositories/abstract.d.ts:125
Parameters
object
any
Returns
any
Inherited from
SQLRepository.excludePrimaryKey
execute()
protectedexecute(q,values?):Promise<{rowCount:number;rows:any[]; }>
Defined in: packages/sql/src/relational/repository.ts:691
Foreign key violations become Webda errors: a conflict when deleting a referenced row, a bad request otherwise; a unique index collision is a conflict
Parameters
q
string
values?
any[]
Returns
Promise<{ rowCount: number; rows: any[]; }>
Overrides
executeAggregation()
protectedexecuteAggregation(query):Promise<AggregationResult<any>>
Defined in: packages/sql/src/repository.ts:780
GROUP BY over the data JSON column
Parameters
query
AggregationQuery
Returns
Promise<AggregationResult<any>>
Inherited from
SQLRepository.executeAggregation
executeCount()
protectedexecuteCount(filter,max?):Promise<CountResult>
Defined in: packages/sql/src/repository.ts:823
COUNT(*) over the data JSON column
Parameters
filter
Expression
max?
number
Returns
Promise<CountResult>
Inherited from
exists()
exists(
primaryKey):Promise<boolean>
Defined in: packages/sql/src/relational/repository.ts:764
Parameters
primaryKey
any
Returns
Promise<boolean>
Overrides
fieldOf()
protectedfieldOf(column):string
Defined in: packages/sql/src/relational/repository.ts:479
Return the field the column holds
Parameters
column
string
a column name of the table
Returns
string
the field the column holds
fieldText()
protectedfieldText(field):string
Defined in: packages/sql/src/relational/repository.ts:178
Parameters
field
string
Returns
string
Overrides
findModelClass()
protectedfindModelClass(identifier):any
Defined in: packages/models/lib/repositories/memory.d.ts:161
Find the class to hydrate a row typed identifier (a Webda 3 legacy form included): the resolved model when it
is the repository model or one of its transitive subclasses, the repository model for an ancestor type or an
unknown or ambiguous type
Parameters
identifier
string
stored __type
Returns
any
the class, this.model when it carries no Metadata, or undefined for an unrelated model
Inherited from
fromJSON()
protectedfromJSON(stored):InstanceType<T>
Defined in: packages/sql/src/repository.ts:374
Deserialize a raw JSON object from the database into a model instance.
Parameters
stored
any
the decoded JSON object of the data column; its __type stamp becomes a non-enumerable property
Returns
InstanceType<T>
the model instance
Inherited from
fromUID()
fromUID(
uid):ModelRefWithCreate<InstanceType<T>>
Defined in: packages/models/lib/repositories/abstract.d.ts:107
Return a ref from the uuid
Parameters
uid
string
the serialized primary key
Returns
ModelRefWithCreate<InstanceType<T>>
a model reference with create capability
Inherited from
get()
get(
primaryKey):Promise<any>
Defined in: packages/sql/src/relational/repository.ts:753
Parameters
primaryKey
any
Returns
Promise<any>
Overrides
getAllowedFields()
getAllowedFields():
string[] |undefined
Defined in: packages/models/lib/repositories/abstract.d.ts:153
Field paths of the model, from its metadata (Reflection and the stored, input and output schemas)
Used to validate UPDATE SET targets.
Returns
string[] | undefined
the field names, undefined when the model carries no field metadata (no validation then)
Inherited from
SQLRepository.getAllowedFields
getClassCondition()
protectedgetClassCondition():string|undefined
Defined in: packages/sql/src/repository.ts:210
SQL condition restricting rows to this model and its subclasses, whatever form their __type has (Webda 3 short,
lower-case and aliased types included); rows without a stamp (written before stamping) and rows typed as a
strict ancestor of the table model belong to the table model and its ancestors
Returns
string | undefined
the condition, undefined for a model without metadata
Inherited from
SQLRepository.getClassCondition
getCompletionFields()
getCompletionFields():
CompletionField[]
Defined in: packages/models/lib/repositories/abstract.d.ts:158
Completion fields of the model, flattened from its schemas
Returns
CompletionField[]
array of completion fields
Inherited from
SQLRepository.getCompletionFields
getFilterCondition()
protectedgetFilterCondition(filter):string
Defined in: packages/sql/src/repository.ts:798
SQL condition selecting the rows of this model matching a filter: the filter and the class condition
Parameters
filter
Expression
the WebdaQL filter
Returns
string
the condition
Inherited from
SQLRepository.getFilterCondition
getMaxListeners()
getMaxListeners():
number
Defined in: packages/models/lib/repositories/abstract.d.ts:349
EventEmitter-compatibility shim. Returns the max-listeners hint.
Returns
number
the current max-listeners hint
Inherited from
getPrimaryKey()
Call Signature
getPrimaryKey(
object,forceObject?):PrimaryKeyType<InstanceType<T>>
Defined in: packages/models/lib/repositories/abstract.d.ts:127
Get the primary key value for an object as a scalar or string.
Parameters
object
any
forceObject?
false
Returns
PrimaryKeyType<InstanceType<T>>
Inherited from
Call Signature
getPrimaryKey(
object,forceObject):PrimaryKey<InstanceType<T>>
Defined in: packages/models/lib/repositories/abstract.d.ts:129
Get the primary key value for an object as a structured key object.
Parameters
object
any
forceObject
true
Returns
PrimaryKey<InstanceType<T>>
Inherited from
getQueryCondition()
getQueryCondition(
writeCondition,writeConditionField,params):string
Defined in: packages/sql/src/repository.ts:347
Build a SQL WHERE sub-expression from a write-condition.
An undefined or null expected value means the field is absent: it is matched with IS NULL, as = NULL is
never true in SQL (a missing key and a JSON null both read as NULL)
Parameters
writeCondition
any
the expected value
writeConditionField
string
the field to check
params
any[]
the existing params array (will be extended in place)
Returns
string
the SQL AND clause
Inherited from
SQLRepository.getQueryCondition
getRootModel()
getRootModel():
T
Defined in: packages/models/lib/repositories/abstract.d.ts:48
Returns
T
Inherited from
getStatementCondition()
protectedgetStatementCondition(statement):string
Defined in: packages/sql/src/repository.ts:838
SQL condition selecting the rows a statement targets: its WHERE, restricted to the first LIMIT rows when the statement has a LIMIT (DELETE and UPDATE have none on every engine)
Parameters
statement
Query
the parsed statement
Returns
string
the condition
Inherited from
SQLRepository.getStatementCondition
getSync()
protectedgetSync(primaryKey):InstanceType<T>
Defined in: packages/models/lib/repositories/memory.d.ts:59
Synchronous read used by conditional writes to keep check-and-set atomic
Parameters
primaryKey
string | PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
key of the item
Returns
InstanceType<T>
the deserialized item
Inherited from
getTable()
getTable():
string
Defined in: packages/sql/src/repository.ts:122
Internal
The backing table name for this repository's model.
Returns
string
the table name Not part of the @webda/models Repository interface.
Inherited from
getTableRoot()
getTableRoot():
ModelClass<Storable<any,any>> |undefined
Defined in: packages/models/lib/repositories/abstract.d.ts:59
Get the model owning the untyped rows of the storage
Returns
ModelClass<Storable<any, any>> | undefined
the model owning the untyped rows of the storage
Inherited from
getUID()
getUID(
object):string
Defined in: packages/models/lib/repositories/abstract.d.ts:131
Parameters
object
any
Returns
string
Inherited from
hydratePlainRow()
protectedhydratePlainRow(raw):InstanceType<T>
Defined in: packages/models/lib/repositories/memory.d.ts:169
Hydrate a plain JSON row as an instance of the repository model (or of the transitive subclass named by its
__type; an ancestor type hydrates as the repository model), the same way document stores hydrate their rows;
a row typed as an unrelated model is refused
Parameters
raw
any
the parsed row
Returns
InstanceType<T>
the model instance
Inherited from
incrementAttribute()
incrementAttribute<
K,L>(primaryKey,info,_conditionField?,_condition?):Promise<void>
Defined in: packages/models/lib/repositories/abstract.d.ts:139
Type Parameters
K
K extends string
L
L extends string
Parameters
primaryKey
PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
info
L | { property: L; value?: number; }
_conditionField?
K | null
_condition?
any
Returns
Promise<void>
Inherited from
SQLRepository.incrementAttribute
incrementAttributes()
incrementAttributes(
primaryKey,info,_conditionField?,_condition?):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:1150
Parameters
primaryKey
any
info
any
_conditionField?
any
_condition?
any
Returns
Promise<void>
Overrides
SQLRepository.incrementAttributes
isNumeric()
protectedisNumeric(column):boolean
Defined in: packages/sql/src/relational/repository.ts:805
Check whether numeric
Parameters
column
ColumnPlan
a column
Returns
boolean
whether it holds a number
isPlainRow()
protectedisPlainRow(raw):boolean
Defined in: packages/models/lib/repositories/memory.d.ts:153
Whether a stored row is a plain JSON object without a serializer envelope
Rows written by earlier versions (e.g. a v3 FileStore folder or MemoryStore persistence file) store the
object itself, its type in a top-level __type.
Parameters
raw
any
the parsed row
Returns
boolean
true for a plain object row
Inherited from
itemComparison()
protecteditemComparison(table,path,expression,name):Expression
Defined in: packages/sql/src/relational/repository.ts:387
Return the comparison on a target key part, a link field or the link attributes
Parameters
table
TablePlan
a junction table
path
string[]
the attribute path inside an item
expression
ComparisonExpression
the comparison
name
string
the attribute, for messages
Returns
Expression
the comparison on a target key part, a link field or the link attributes
Throws
WebdaError.BadRequest for a path the items do not have
iterate()
iterate(
queryStr):AsyncGenerator<InstanceType<T>,any,any>
Defined in: packages/sql/src/repository.ts:879
— iterate via paginated SQL queries
Parameters
queryStr
string
Returns
AsyncGenerator<InstanceType<T>, any, any>
Inherited from
jsonComparison()
protectedjsonComparison(column,path,expression):Expression
Defined in: packages/sql/src/relational/repository.ts:266
Return the JSON comparison, IN as = alternatives
Parameters
column
string
a JSON column
path
string[]
the path inside it
expression
ComparisonExpression
the comparison
Returns
Expression
the JSON comparison, IN as = alternatives
jsonPath()
protectedjsonPath(path):string
Defined in: packages/sql/src/relational/repository.ts:209
Parameters
path
string
Returns
string
Overrides
junctionColumn()
protectedjunctionColumn(table,column):string
Defined in: packages/sql/src/relational/repository.ts:339
Return the column qualified by its table
Parameters
table
TablePlan
a junction table
column
string
one of its columns
Returns
string
the column qualified by its table
junctionComparison()
protectedjunctionComparison(path,target,expression):Expression
Defined in: packages/sql/src/relational/repository.ts:294
A comparison on a link collection, as an EXISTS sub-query on its junction table:
tags CONTAINS 't1': the collection links to the key (a composite key is split);contributors.role = 'editor': one item of the collection matches (a target key part, a link field or a path in the link attributes);- on a map, the second segment is the key of the item:
reviewers.lead.since > 2020,reviewers.lead IS NULL; IS NULLon the collection itself isFALSE: a link collection reads as an empty array or map, never null.
Parameters
path
string[]
the attribute path
target
the junction
kind
"junction"
relation
RelationPlan
table
TablePlan
expression
ComparisonExpression
the comparison
Returns
Expression
the condition
Throws
WebdaError.BadRequest for a comparison the junction cannot answer
junctionCount()
protectedjunctionCount(tx,table,owner):Promise<number>
Defined in: packages/sql/src/relational/repository.ts:1204
Return the number of junction rows of the owner
Parameters
tx
the transaction client
table
TablePlan
a junction table
owner
Record<string, unknown>
the owner object (its primary key fields)
Returns
Promise<number>
the number of junction rows of the owner
junctionExists()
protectedjunctionExists(table,conditions,negate?):Expression
Defined in: packages/sql/src/relational/repository.ts:350
Return the sub-query on the junction rows of the current row
Parameters
table
TablePlan
a junction table
conditions
string[]
conditions on its rows
negate?
boolean = false
NOT EXISTS
Returns
Expression
the sub-query on the junction rows of the current row
keptTypeExpression()
protectedkeptTypeExpression(mapParam):string
Defined in: packages/sql/src/repository.ts:298
SQL expression of the __type a written row keeps: its stored type, rewritten to the current identifier when it
is a legacy form of this model family
Parameters
mapParam
number
position of the bound legacyTypeMap parameter
Returns
string
the SQL expression
Inherited from
SQLRepository.keptTypeExpression
keyColumns()
protectedkeyColumns():string[]
Defined in: packages/sql/src/relational/repository.ts:188
Returns
string[]
Overrides
lastUpdateSet()
protectedlastUpdateSet(args):string[]
Defined in: packages/sql/src/relational/repository.ts:1140
Return the _lastUpdate assignment when the table has that column, empty otherwise
Parameters
args
unknown[]
the statement parameters, extended
Returns
string[]
the _lastUpdate assignment when the table has that column, empty otherwise
legacyTypeMap()
protectedlegacyTypeMap():Record<string,string>
Defined in: packages/sql/src/repository.ts:274
Stored types to rewrite when a row of this model family is written: each legacy form (short, lower-case, alias) to its current identifier, and the ancestor types of the table model to the table model
Returns
Record<string, string>
the current identifier by lower-cased stored type
Inherited from
legacyTypeRewrites()
protectedlegacyTypeRewrites():Record<string,string>
Defined in: packages/models/lib/repositories/abstract.d.ts:90
Stored types a write of this model family rewrites, for stores updating rows in place: each form of a model (current, short, lower-case, alias) to its current identifier, and the ancestor types of the table root to the table root identifier
Returns
Record<string, string>
the current identifier by lower-cased stored type, empty when the model carries no Metadata
Inherited from
SQLRepository.legacyTypeRewrites
listKeysOfModel()
protectedlistKeysOfModel(ids?):string[]
Defined in: packages/models/lib/repositories/memory.d.ts:234
List the storage keys that may belong to this model
A storage shared by several models holds foreign entries whose key shape can be invalid for this
repository: they are skipped from the stored __type before any parsing. Entries are kept when their stored
__type belongs to the model (legacy forms included). Untyped entries, and entries typed as a strict ancestor
of the table root, belong to the table root and its ancestors. Unreadable entries are kept so their error
surfaces.
A TypeIndexedMap storage answers from its type index: only the keys of the model are visited. Any other Map-like storage is scanned, parsing every entry.
Parameters
ids?
string[]
class identifiers (model and subclasses), undefined to keep everything
Returns
string[]
the keys to evaluate
Inherited from
loadJunctions()
protectedloadJunctions(rows):Promise<Map<string,Map<string,Record<string,unknown>[]>>>
Defined in: packages/sql/src/relational/repository.ts:534
Read the junction rows of a page of rows: one statement per junction table
Parameters
rows
Record<string, unknown>[]
the rows
Returns
Promise<Map<string, Map<string, Record<string, unknown>[]>>>
the junction rows by attribute, then by owner key
loadMapped()
protectedloadMapped(rows,source):Promise<Map<string,Record<string,unknown>[]>>
Defined in: packages/sql/src/relational/repository.ts:589
Read the items of a filled ModelsMapped for a page of rows: the rows of the mapped model linking to them,
through their reference columns or the junction of their link collection, in primary key order
Parameters
rows
Record<string, unknown>[]
the rows
source
the mapped attribute
Returns
Promise<Map<string, Record<string, unknown>[]>>
the items (the mapped attributes and the uuid of the mapped row) by owner key
mapError()
mapError(
q,err):unknown
Defined in: packages/sql/src/relational/repository.ts:706
Map error
Parameters
q
string
the statement that failed (or its kind: a deferred foreign key fails at COMMIT)
err
unknown
the error
Returns
unknown
the Webda error of a foreign key violation or of a unique index collision (a primary key violation is left to the caller: it tells a duplicate row from a duplicate junction key), the error itself otherwise
mapExpressionAttribute()
mapExpressionAttribute(
attribute):string
Defined in: packages/sql/src/relational/repository.ts:193
Parameters
attribute
string[]
Returns
string
Overrides
SQLRepository.mapExpressionAttribute
mapJsonAttribute()
mapJsonAttribute(
attribute):string
Defined in: packages/sql/src/relational/repository.ts:201
Parameters
attribute
string[]
Returns
string
Overrides
SQLRepository.mapJsonAttribute
mappedKeys()
protectedmappedKeys(source):object
Defined in: packages/sql/src/relational/repository.ts:572
Return the columns of the mapped rows (or of their junction rows) holding the owner key, and the owner columns
Parameters
source
a filled ModelsMapped
Returns
object
the columns of the mapped rows (or of their junction rows) holding the owner key, and the owner columns they match, in the same order
links
links:
ColumnPlan[]
owner
owner:
string[]
matchStorage()
protectedmatchStorage(statement):object[]
Defined in: packages/models/lib/repositories/memory.d.ts:273
Keys of the stored objects of this model matching a statement's WHERE, at most LIMIT
Synchronous: the statement then runs without yielding, so no other write interleaves and an object is never met twice.
Parameters
statement
Query
the parsed statement
Returns
object[]
the storage keys and their objects
Inherited from
maybeTransact()
protectedmaybeTransact<R>(needed,kind,fn):Promise<R>
Defined in: packages/sql/src/relational/repository.ts:838
Run statements in one transaction when they are several, directly otherwise. Deferred foreign keys fail at COMMIT: that error is mapped like the statement's
Type Parameters
R
R
Parameters
needed
boolean
whether several statements are involved
kind
"INSERT" | "UPDATE" | "DELETE"
the statement kind, for the error mapping
fn
(tx) => Promise<R>
the statements
Returns
Promise<R>
the function result
modelIdentifier()
protectedmodelIdentifier():string
Defined in: packages/sql/src/relational/repository.ts:867
Return the identifier of the repository model
Returns
string
the identifier of the repository model
monitor()
protectedmonitor<R>(operation,query,fn,details):Promise<R>
Defined in: packages/models/lib/repositories/abstract.d.ts:262
Helper that times a query operation, catches and rethrows errors, and calls onQuery safely
Type Parameters
R
R
Parameters
operation
QueryOperation
the query operation
query
string
the query string
fn
() => Promise<R>
the async function to execute and time
details
((r) => object) | ((r) => number)
optional callback to extract result count or pagination details
Returns
Promise<R>
the result of fn
Inherited from
off()
off<
K>(event,listener):void
Defined in: packages/models/lib/repositories/abstract.d.ts:331
Type Parameters
K
K extends string | number | symbol
Parameters
event
K
listener
(data) => void
Returns
void
Inherited from
on()
on<
K>(event,listener):void
Defined in: packages/models/lib/repositories/abstract.d.ts:327
Type Parameters
K
K extends string | number | symbol
Parameters
event
K
listener
(data) => void
Returns
void
Inherited from
once()
once<
K>(event,listener):void
Defined in: packages/models/lib/repositories/abstract.d.ts:329
Type Parameters
K
K extends string | number | symbol
Parameters
event
K
listener
(data) => void
Returns
void
Inherited from
ownerCondition()
protectedownerCondition(table,owner,args):string
Defined in: packages/sql/src/relational/repository.ts:936
Return the condition selecting the junction rows of the owner
Parameters
table
TablePlan
a junction table
owner
Record<string, unknown>
the owner object (its primary key fields)
args
unknown[]
the statement parameters, extended
Returns
string
the condition selecting the junction rows of the owner
ownerValues()
protectedownerValues(row,junction):unknown[]
Defined in: packages/sql/src/relational/repository.ts:516
Return the owner key values of its junction rows, in owner column order
Parameters
row
Record<string, unknown>
a row of the table
junction
TablePlan
a junction table
Returns
unknown[]
the owner key values of its junction rows, in owner column order
parseLegacyUID()
protectedparseLegacyUID(uid):PrimaryKey<InstanceType<T>> |undefined
Defined in: packages/models/lib/repositories/abstract.d.ts:123
Parse a uid through the model's parseLegacyUID hook
Parameters
uid
string
the raw storage key
Returns
PrimaryKey<InstanceType<T>> | undefined
a key whose string form is the raw uid, or undefined when the model does not recognise it
Inherited from
parseStatement()
protectedparseStatement(type,statement,params?):Promise<Query>
Defined in: packages/models/lib/repositories/abstract.d.ts:171
Parse a bulk statement and check it is of the expected type
For an UPDATE, every SET target is checked: no primary key field, no private (__) segment, no
constructor/prototype segment, and a field of the model when its metadata lists them.
Parameters
type
"UPDATE" | "DELETE"
the expected statement type
statement
string | Query
the statement string or its parsed form
params?
QueryParameters
values for the placeholders of a statement string
Returns
Promise<Query>
the parsed statement
Throws
WebdaQLError when the statement has another type or a SET target is refused
Throws
SyntaxError when the statement does not parse, or a SET target is not a field of the model
Inherited from
parseUID()
parseUID(
uid,forceObject?):PrimaryKeyType<InstanceType<T>> |PrimaryKey<InstanceType<T>>
Defined in: packages/models/lib/repositories/abstract.d.ts:117
Parse a serialized primary key
A composite key that does not split into the primary key fields is offered to the model's optional
static parseLegacyUID(uid) hook (see WEBDA_LEGACY_UID): the returned key keeps the raw uid as its
string form so it addresses the legacy storage entry. Without a hook, or when the hook declines, the
uid is rejected.
Parameters
uid
string
forceObject?
boolean
Returns
PrimaryKeyType<InstanceType<T>> | PrimaryKey<InstanceType<T>>
Inherited from
patch()
patch(
primaryKey,data,conditionField?,condition?):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:1042
Parameters
primaryKey
any
data
any
conditionField?
any
condition?
any
Returns
Promise<void>
Overrides
pkCondition()
protectedpkCondition(primaryKey,args):string
Defined in: packages/sql/src/relational/repository.ts:489
Return the condition selecting the row
Parameters
primaryKey
any
a primary key, an object or the model instance
args
unknown[]
the statement parameters, extended with the key values
Returns
string
the condition selecting the row
q()
protectedq(name):string
Defined in: packages/sql/src/relational/repository.ts:119
Return the quoted identifier
Parameters
name
string
a column or table name
Returns
string
the quoted identifier
query()
query(
queryStr):Promise<{continuationToken?:string;results:InstanceType<T>[]; }>
Defined in: packages/sql/src/relational/repository.ts:772
Parameters
queryStr
any
Returns
Promise<{ continuationToken?: string; results: InstanceType<T>[]; }>
Overrides
ref()
ref(
key):ModelRefWithCreate<InstanceType<T>>
Defined in: packages/models/lib/repositories/abstract.d.ts:137
Parameters
key
PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
Returns
ModelRefWithCreate<InstanceType<T>>
Inherited from
referenceComparison()
protectedreferenceComparison(path,target,expression):Expression
Defined in: packages/sql/src/relational/repository.ts:423
A comparison on a reference to a composite key, on its key parts: the value is split on the key separator for
=, != and IN (a value that does not split matches nothing, or everything for !=); LIKE and the
ordering operators compare the joined text; IS NULL holds when every part is NULL
Parameters
path
string[]
the attribute path
target
the reference
columns
ColumnPlan[]
kind
"reference"
relation
RelationPlan
expression
ComparisonExpression
the comparison
Returns
Expression
the condition
Throws
WebdaError.BadRequest for CONTAINS or a path inside the reference
relationOfConstraint()
protectedrelationOfConstraint(constraint):RelationPlan|undefined
Defined in: packages/sql/src/relational/repository.ts:747
Return the relation it enforces, undefined for a junction key or an unknown constraint
Parameters
constraint
string | undefined
a foreign key constraint name
Returns
RelationPlan | undefined
the relation it enforces, undefined for a junction key or an unknown constraint
removeAttribute()
removeAttribute(
primaryKey,attribute,conditionField?,condition?):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:1089
Parameters
primaryKey
any
attribute
any
conditionField?
any
condition?
any
Returns
Promise<void>
Overrides
removeListener()
removeListener<
K>(event,listener):void
Defined in: packages/models/lib/repositories/abstract.d.ts:344
EventEmitter-compatibility alias for off. Consumers that treat a
repository as a Node EventEmitter (e.g. @webda/runtime EventIterator)
call removeListener.
Type Parameters
K
K extends string | number | symbol
Parameters
event
K
the event name
listener
(data) => void
the listener to remove
Returns
void
Inherited from
requireRow()
protectedrequireRow(tx,primaryKey,key):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:1220
Make sure the owner row exists (with its write condition when given)
Parameters
tx
the transaction client
primaryKey
any
the owner key
key
string
the key text
Returns
Promise<void>
resolvePath()
protectedresolvePath(item,path):object
Defined in: packages/models/lib/repositories/memory.d.ts:300
Resolve the parent object and last key of a dotted path, creating intermediate objects
Parameters
item
any
root object
path
string
dotted path
Returns
object
the holder and the last key
holder
holder:
any
key
key:
string
Inherited from
rootAncestorTypes()
protectedrootAncestorTypes():Record<string,string>
Defined in: packages/sql/src/repository.ts:248
Stored types naming a strict ancestor of the table model (e.g. CoreModel in a table of an application model):
such rows belong to the table model, like unstamped rows
Returns
Record<string, string>
the current identifier of the table model by lower-cased stored type, empty when this model does not own the table
Inherited from
SQLRepository.rootAncestorTypes
run()
protectedrun(tx,q,values?):Promise<{rowCount:number;rows:any[]; }>
Defined in: packages/sql/src/relational/repository.ts:815
Run a statement on a transaction client or on the store client, with the same error mapping
Parameters
tx
SQLClient | undefined
the transaction client, undefined for the store client
q
string
the statement
values?
unknown[]
its parameters
Returns
Promise<{ rowCount: number; rows: any[]; }>
the result
safeOnQuery()
protectedsafeOnQuery(info):void
Defined in: packages/models/lib/repositories/abstract.d.ts:253
Safely invoke the onQuery callback without throwing into the caller
Parameters
info
QueryExecutionInfo
query execution info
Returns
void
Inherited from
selectList()
protectedselectList():string
Defined in: packages/sql/src/relational/repository.ts:503
Return the quoted columns a read selects: every column of the table
Returns
string
the quoted columns a read selects: every column of the table
serialize()
serialize(
item):string
Defined in: packages/models/lib/repositories/memory.d.ts:101
Serialize the object to a string
This method is used to allow switching between different serialization methods
The serialized payload is also stamped with a top-level __type field
carrying the concrete model identifier when available
(item.constructor.Metadata?.Identifier). This lets query() and external
storage backends filter results by class without re-instantiating every
item — important when a single underlying storage map is shared across a
model and its subclasses (the common case in production where each
registered model owns its own MemoryRepository pointing at the same Map).
The stamp lives on the serializer envelope (sibling of value /
$serializer), not inside value. deserialize() re-surfaces it on the
reconstructed instance as a non-enumerable __type property so WebdaQL's
filter eval can read it without it ever leaking into JSON.stringify or
Object.keys output — keeping API responses and re-serialize cycles
byte-identical for the model's own fields.
Models that don't carry Metadata (plain unit-test classes that don't go through Application.setModelMetadata) simply skip the stamp; the resulting payload is byte-identical to the previous implementation.
Parameters
item
InstanceType<T>
to serialize
Returns
string
serialized object
Inherited from
setAttribute()
setAttribute<
K,L>(primaryKey,attribute,value,conditionField?,condition?):Promise<void>
Defined in: packages/models/lib/repositories/abstract.d.ts:135
Type Parameters
K
K extends string
L
L extends string
Parameters
primaryKey
string | PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
attribute
K
value
_PropertyPathType<InstanceType<T>, K>
conditionField?
L | null
condition?
_PropertyPathType<InstanceType<T>, L> | JSONed<_PropertyPathType<InstanceType<T>, L>>
Returns
Promise<void>
Inherited from
setMaxListeners()
setMaxListeners(
n):this
Defined in: packages/models/lib/repositories/abstract.d.ts:355
EventEmitter-compatibility shim. Records the max-listeners hint (no enforcement).
Parameters
n
number
the new hint value
Returns
this
this for chaining
Inherited from
setTableRoot()
setTableRoot(
root?):this
Defined in: packages/models/lib/repositories/abstract.d.ts:54
Set the model owning the untyped rows of the storage
Parameters
root?
ModelClass<Storable<any, any>>
the first model of the store, undefined when not known
Returns
this
this
Inherited from
setupTable()
setupTable():
Promise<void>
Defined in: packages/sql/src/relational/repository.ts:127
The store owns the DDL
Returns
Promise<void>
Overrides
sqlQuery()
protectedsqlQuery(q,values?):Promise<{rowCount:number;rows:any[]; }>
Defined in: packages/sql/src/repository.ts:362
Run a raw SQL query and return typed results.
Parameters
q
string
the SQL query (WHERE clause or full query)
values?
any[] = []
the query parameters
Returns
Promise<{ rowCount: number; rows: any[]; }>
the raw query result
Inherited from
tableModelClass()
protectedtableModelClass():any
Defined in: packages/sql/src/repository.ts:233
The class of the table model, when it is this model or one of its subclasses
Returns
any
the class, undefined when the table model is unknown or outside the model family
Inherited from
tableRootAncestorTypes()
protectedtableRootAncestorTypes():string[]
Defined in: packages/models/lib/repositories/abstract.d.ts:83
Stored types naming a strict ancestor of the table root (e.g. UuidModel in a table of an application model),
for stores filtering in their query language: such rows belong to the table root, like untyped rows
Returns
string[]
the types, empty when the table root is unknown or this model does not own the untyped rows
Inherited from
SQLRepository.tableRootAncestorTypes
target()
protectedtarget(path): {column:ColumnPlan;kind:"column"; } | {column:ColumnPlan;kind:"json";path:string[]; } | {column:ColumnPlan;kind:"extra";path:string[]; }
Defined in: packages/sql/src/relational/repository.ts:153
Where an attribute lives, refusing what no statement can reach
Parameters
path
string[]
the validated attribute path
Returns
{ column: ColumnPlan; kind: "column"; } | { column: ColumnPlan; kind: "json"; path: string[]; } | { column: ColumnPlan; kind: "extra"; path: string[]; }
the target: a column, a JSON path or the extra column path
Throws
WebdaError.BadRequest for a junction attribute, a composite reference, a filled ModelsMapped or an
unknown attribute
targetKeyCondition()
protectedtargetKeyCondition(table,relation,value):string
Defined in: packages/sql/src/relational/repository.ts:368
Return the condition on the target columns, FALSE when the key does not split into its parts
Parameters
table
TablePlan
a junction table
relation
RelationPlan
its relation
value
unknown
a target key, joined for a composite key
Returns
string
the condition on the target columns, FALSE when the key does not split into its parts
toInstances()
protectedtoInstances(rows):Promise<InstanceType<T>[]>
Defined in: packages/sql/src/relational/repository.ts:654
Convert to instances
Parameters
rows
Record<string, unknown>[]
rows of the table
Returns
Promise<InstanceType<T>[]>
the model instances, their junction and filled ModelsMapped attributes set
toJSONRecord()
protectedtoJSONRecord(item,fallbackType?):Record<string,unknown>
Defined in: packages/sql/src/relational/repository.ts:859
Convert to JSON record
Parameters
item
any
an object or plain data
fallbackType?
string
the type stamped when the object declares none
Returns
Record<string, unknown>
its serialized JSON, __type set when known
toStoredJSON()
protectedtoStoredJSON(item,fallbackType?):string
Defined in: packages/sql/src/repository.ts:326
The JSON stored for an object: its fields, and its declared type in __type (see declaredType)
Parameters
item
any
the object
fallbackType?
string
the type to stamp when the object declares none
Returns
string
the JSON text
Inherited from
typeResolver()
protectedtypeResolver():ModelTypeResolver
Defined in: packages/models/lib/repositories/abstract.d.ts:65
Resolver of the stored __type: the installed application one when it knows the model, else the model's own
hierarchy with exact identifiers only
Returns
ModelTypeResolver
the resolver
Inherited from
typeText()
protectedtypeText():string
Defined in: packages/sql/src/relational/repository.ts:183
Returns
string
Overrides
update()
update(
data,conditionField?,condition?):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:1036
Parameters
data
any
conditionField?
any
condition?
any
Returns
Promise<void>
Overrides
updateMany()
updateMany(
statement,params?):Promise<number>
Defined in: packages/sql/src/relational/repository.ts:1362
Update in bulk: a column assignment binds the encoded value, a path into a JSON column (or an unknown field into the extra column) is set in place; one assignment per JSON column
Parameters
statement
string | Query
params?
QueryParameters
Returns
Promise<number>
Overrides
updateManyByKey()
protectedupdateManyByKey(statement,params?):Promise<number>
Defined in: packages/models/lib/repositories/abstract.d.ts:216
Generic updateMany: collect the matching keys (up to LIMIT), then patch them one by one with this
repository's patch primitive. A dotted target reads the object to rewrite its top-level field.
Used by stores without a native bulk update. On a store repository the primitive emits no event.
Parameters
statement
string | Query
the UPDATE statement or its parsed form
params?
QueryParameters
values for the placeholders
Returns
Promise<number>
the number of objects updated
Inherited from
upsert()
upsert(
data):Promise<InstanceType<T>>
Defined in: packages/models/lib/repositories/abstract.d.ts:133
Parameters
data
Helpers<InstanceType<T>>
Returns
Promise<InstanceType<T>>
Inherited from
upsertItemToCollection()
upsertItemToCollection(
primaryKey,collection,item,index?,itemWriteConditionField?,itemWriteCondition?):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:1233
Parameters
primaryKey
any
collection
any
item
any
index?
number
itemWriteConditionField?
any
itemWriteCondition?
any
Returns
Promise<void>
Overrides
SQLRepository.upsertItemToCollection
writeIfPresent()
protectedwriteIfPresent(key,write):Promise<boolean>
Defined in: packages/models/lib/repositories/abstract.d.ts:196
Run one write of the generic fallback; an object deleted since the keys were collected is skipped
Parameters
key
PrimaryKeyType<InstanceType<T>>
the primary key
write
() => Promise<void>
the write
Returns
Promise<boolean>
true when written, false when the object is gone
Throws
the write error when the object still exists
Inherited from
writeJunction()
protectedwriteJunction(tx,owner,junction,replace):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:878
Replace (or create) the junction rows of one owner
Parameters
tx
SQLClient | undefined
the transaction client
owner
Record<string, unknown>
the owner object (its primary key fields)
junction
the rows
replace
boolean
delete the current rows first
Returns
Promise<void>
writeJunctions()
protectedwriteJunctions(tx,owner,junctions,replace):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:912
Write the junction rows of an object: a key listed twice in a link collection is a bad request
Parameters
tx
SQLClient | undefined
the transaction client
owner
Record<string, unknown>
the owner object (its primary key fields)
junctions
the rows by junction
replace
boolean
delete the current rows first
Returns
Promise<void>
writeRow()
protectedwriteRow(primaryKey,row,conditionField?,condition?):Promise<void>
Defined in: packages/sql/src/relational/repository.ts:987
Write a row and its junctions: the UPDATE must hit one row, the junctions are replaced in the same transaction
Parameters
primaryKey
any
the row key
row
the row
conditionField?
any
write condition field
condition?
any
write condition value
Returns
Promise<void>
rootIdentifier()
staticrootIdentifier(model):string|undefined
Defined in: packages/sql/src/repository.ts:91
Return the identifier of its topmost ancestor (itself included) carrying metadata
Parameters
model
any
a model class
Returns
string | undefined
the identifier of its topmost ancestor (itself included) carrying metadata
Inherited from
simulateFind()
staticsimulateFind<T>(query,uuids,repository):Promise<{continuationToken?:string;results:InstanceType<T>[]; }>
Defined in: packages/models/lib/repositories/memory.d.ts:243
Allow to simulate a find on a list of uuids It is static to be reusable by other repository like FileRepository
Type Parameters
T
T extends ModelClass<Storable<any, any>>
Parameters
query
Query
the parsed query
uuids
any[]
the list of UIDs to search
repository
Repository<T>
the repository to fetch objects from
Returns
Promise<{ continuationToken?: string; results: InstanceType<T>[]; }>
the query results with optional continuation token