EventRepository
Class: EventRepository<T>
Defined in: packages/models/src/repositories/event.ts:26
Repository decorator that wraps another repository with event emission.
Emits "before" events (Create, Update, Patch, Delete, PartialUpdate, Query) before delegating to the underlying repository, then emits "after" events (Created, Updated, Patched, Deleted, PartialUpdated, Queried) on success.
Extends
Type Parameters
T
T extends ModelClass = any
The ModelClass this repository manages
Constructors
Constructor
new EventRepository<
T>(model,pks,repository,separator?):EventRepository<T>
Defined in: packages/models/src/repositories/event.ts:33
Parameters
model
T
The model class constructor
pks
string[]
Array of primary key field names
repository
The underlying repository to delegate storage operations to
separator?
string
Separator used when joining composite key fields (default: "_")
Returns
EventRepository<T>
Overrides
AbstractRepository.constructor
Properties
[WEBDA_TEST]
[WEBDA_TEST]:
object
Defined in: packages/models/src/repositories/event.ts:461
Test utilities - clears events and delegates to underlying repository
clear
clear: (
excludeListeners?) =>Promise<void>
Parameters
excludeListeners?
boolean
Returns
Promise<void>
aggregationOptions
protectedaggregationOptions:AggregationOptions
Defined in: packages/models/src/repositories/abstract.ts:42
Aggregation fallback policy, set by the owning store through configureAggregation
Inherited from
AbstractRepository.aggregationOptions
events
protectedevents:Map<keyofInstanceType<T>[typeofWEBDA_EVENTS],Set<(data) =>void>>
Defined in: packages/models/src/repositories/abstract.ts:39
Registered event listeners keyed by event name
Inherited from
maxListeners
protectedmaxListeners:number=100
Defined in: packages/models/src/repositories/abstract.ts:891
Max-listeners hint kept for Node EventEmitter API compatibility. Not
enforced — repositories use an unbounded Set per event.
Inherited from
AbstractRepository.maxListeners
model
protectedmodel:T
Defined in: packages/models/src/repositories/abstract.ts:62
The model class constructor
Inherited from
monitorOptions
protectedmonitorOptions:QueryMonitorOptions={}
Defined in: packages/models/src/repositories/abstract.ts:44
Query monitoring options, set by the owning store through configureMonitoring
Inherited from
AbstractRepository.monitorOptions
pks
protectedpks:string[]
Defined in: packages/models/src/repositories/abstract.ts:63
Array of primary key field names
Inherited from
repository
protectedrepository:AbstractRepository<T>
Defined in: packages/models/src/repositories/event.ts:36
The underlying repository to delegate storage operations to
separator
protectedseparator:string="_"
Defined in: packages/models/src/repositories/abstract.ts:64
Separator used when joining composite key fields into a string (default: "_")
Inherited from
tableRoot?
protectedoptionaltableRoot?:ModelClass<Storable<any,any>>
Defined in: packages/models/src/repositories/abstract.ts:50
Model owning the untyped rows of the storage (the first model of the store), undefined when not known
Inherited from
warnedAggregations
protectedwarnedAggregations:Set<string>
Defined in: packages/models/src/repositories/abstract.ts:46
Fallback shapes already warned about
Inherited from
AbstractRepository.warnedAggregations
Methods
acceptedTypes()
acceptedTypes():
string[]
Defined in: packages/models/src/repositories/abstract.ts:109
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
AbstractRepository.acceptedTypes
aggregate()
aggregate<
G,M>(spec,params?):Promise<AggregationResult<AggregatedRow<InstanceType<T>,G,M>>>
Defined in: packages/models/src/repositories/event.ts:161
Aggregate with event emission
Parameters are bound here, so the events carry the bound filter and the underlying repository receives a plain spec and keeps its native implementation.
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>
the aggregation spec
params?
QueryParameters
values for the placeholders of spec.filter
Returns
Promise<AggregationResult<AggregatedRow<InstanceType<T>, G, M>>>
the aggregated rows
Overrides
aggregateInMemory()
protectedaggregateInMemory(query):Promise<Record<string,unknown>[]>
Defined in: packages/models/src/repositories/abstract.ts:799
Aggregate by streaming the filtered items
Parameters
query
AggregationQuery
the aggregation
Returns
Promise<Record<string, unknown>[]>
the rows
Inherited from
AbstractRepository.aggregateInMemory
applyAssignments()
protectedapplyAssignments<O>(target,assignments):O
Defined in: packages/models/src/repositories/abstract.ts:466
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
AbstractRepository.applyAssignments
belongsToModel()
belongsToModel(
stored?):boolean
Defined in: packages/models/src/repositories/abstract.ts:121
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
AbstractRepository.belongsToModel
buildItem()
protectedbuildItem(data):InstanceType<T>
Defined in: packages/models/src/repositories/abstract.ts:138
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/src/repositories/abstract.ts:730
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
AbstractRepository.checkAggregationFallback
collectStatementKeys()
protectedcollectStatementKeys(statement):Promise<PrimaryKeyType<InstanceType<T>>[]>
Defined in: packages/models/src/repositories/abstract.ts:488
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
AbstractRepository.collectStatementKeys
configureAggregation()
configureAggregation(
options):void
Defined in: packages/models/src/repositories/event.ts:209
Configure both this wrapper and the underlying repository
Parameters
options
Partial<AggregationOptions>
Returns
void
Overrides
AbstractRepository.configureAggregation
configureMonitoring()
configureMonitoring(
options):void
Defined in: packages/models/src/repositories/event.ts:218
Configure monitoring on the event wrapper only (not on the inner repository)
Parameters
options
Partial<QueryMonitorOptions>
Returns
void
Overrides
AbstractRepository.configureMonitoring
count()
count(
filter?,params?,options?):Promise<CountResult>
Defined in: packages/models/src/repositories/event.ts:193
Count through the underlying repository, monitored as a "count" operation
Parameters are bound here, so the monitor sees the bound filter and the underlying repository keeps its native implementation. A count emits no repository event.
Parameters
filter?
string
the WebdaQL filter
params?
QueryParameters
values for the placeholders of the filter
options?
max stops counting after max objects
Returns
Promise<CountResult>
the count
Overrides
countInMemory()
protectedcountInMemory(filter,max?):Promise<Omit<CountResult,"native">>
Defined in: packages/models/src/repositories/abstract.ts:785
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
AbstractRepository.countInMemory
create()
create(
data,save?):Promise<InstanceType<T>>
Defined in: packages/models/src/repositories/event.ts:404
Create with event emission (emits Create before and Created after)
Parameters
data
Helpers<InstanceType<T>>
save?
boolean
Returns
Promise<InstanceType<T>>
Overrides
delete()
delete<
K>(uuid,conditionField?,condition?):Promise<void>
Defined in: packages/models/src/repositories/event.ts:445
Delete with event emission (emits Delete before and Deleted after)
Type Parameters
K
K extends string
Parameters
uuid
PrimaryKeyType<InstanceType<T>>
conditionField?
K | null
condition?
PropertyPathType<InstanceType<T>, K> | JSONed<PropertyPathType<InstanceType<T>, K>>
Returns
Promise<void>
Overrides
deleteItemFromCollection()
deleteItemFromCollection<
K,L>(uuid,collection,index,itemWriteConditionField?,itemWriteCondition?):Promise<void>
Defined in: packages/models/src/repositories/event.ts:272
Delete an item from a collection
Type Parameters
K
K extends string
L
L extends string | number | symbol
Parameters
uuid
PrimaryKeyType<InstanceType<T>>
The UUID of the item
collection
K
The collection to delete from
index
number
The index of the item to delete
itemWriteConditionField?
L
The field to use for the write condition
itemWriteCondition?
ArrayElement<InstanceType<T>[K]>[L]
The value to use for the write condition
Returns
Promise<void>
Overrides
AbstractRepository.deleteItemFromCollection
deleteMany()
deleteMany(
statement,params?):Promise<number>
Defined in: packages/models/src/repositories/event.ts:230
Delete in bulk through the underlying repository
Bulk operations emit no per-object event: see Repository.deleteMany.
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
Overrides
deleteManyByKey()
protecteddeleteManyByKey(statement,params?):Promise<number>
Defined in: packages/models/src/repositories/abstract.ts:530
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
AbstractRepository.deleteManyByKey
emit()
emit<
K>(event,data):Promise<void>
Defined in: packages/models/src/repositories/abstract.ts:930
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/src/repositories/abstract.ts:222
Parameters
object
any
Returns
any
Inherited from
AbstractRepository.excludePrimaryKey
executeAggregation()
protectedexecuteAggregation(query):Promise<AggregationResult<any>>
Defined in: packages/models/src/repositories/abstract.ts:719
Run a validated aggregation
Backends override it to aggregate natively, and call super for the shapes they cannot translate. The default streams iterate() into the in-memory Aggregator, under the fallback policy.
Parameters
query
AggregationQuery
the validated aggregation
Returns
Promise<AggregationResult<any>>
the rows
Inherited from
AbstractRepository.executeAggregation
executeCount()
protectedexecuteCount(filter,max?):Promise<CountResult>
Defined in: packages/models/src/repositories/abstract.ts:774
Count the objects matching a validated filter
Backends override it to count natively. The default scans iterate() in memory, under the fallback policy. It does not go through executeAggregation: an aggregation has no cap.
Parameters
filter
Expression
the filter, without ORDER BY, LIMIT or OFFSET
max?
number
stop after max objects, undefined for an exact count
Returns
Promise<CountResult>
the count
Inherited from
AbstractRepository.executeCount
exists()
exists(
uuid):Promise<boolean>
Defined in: packages/models/src/repositories/event.ts:455
Parameters
uuid
PrimaryKeyType<InstanceType<T>>
Returns
Promise<boolean>
Overrides
fromUID()
fromUID(
uid):ModelRefWithCreate<InstanceType<T>>
Defined in: packages/models/src/repositories/abstract.ts:171
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<HelperProperties<InstanceType<T>>>
Defined in: packages/models/src/repositories/event.ts:396
Parameters
primaryKey
PrimaryKeyType<InstanceType<T>>
Returns
Promise<HelperProperties<InstanceType<T>>>
Overrides
getAllowedFields()
getAllowedFields():
string[] |undefined
Defined in: packages/models/src/repositories/abstract.ts:365
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
AbstractRepository.getAllowedFields
getCompletionFields()
getCompletionFields():
CompletionField[]
Defined in: packages/models/src/repositories/abstract.ts:382
Completion fields of the model, flattened from its schemas
Returns
CompletionField[]
array of completion fields
Inherited from
AbstractRepository.getCompletionFields
getMaxListeners()
getMaxListeners():
number
Defined in: packages/models/src/repositories/abstract.ts:911
EventEmitter-compatibility shim. Returns the max-listeners hint.
Returns
number
the current max-listeners hint
Inherited from
AbstractRepository.getMaxListeners
getPrimaryKey()
Call Signature
getPrimaryKey(
object,forceObject?):PrimaryKeyType<InstanceType<T>>
Defined in: packages/models/src/repositories/abstract.ts:232
Get the primary key value for an object as a scalar or string.
Parameters
object
any
forceObject?
false
Returns
PrimaryKeyType<InstanceType<T>>
Inherited from
AbstractRepository.getPrimaryKey
Call Signature
getPrimaryKey(
object,forceObject):PrimaryKey<InstanceType<T>>
Defined in: packages/models/src/repositories/abstract.ts:234
Get the primary key value for an object as a structured key object.
Parameters
object
any
forceObject
true
Returns
PrimaryKey<InstanceType<T>>
Inherited from
AbstractRepository.getPrimaryKey
getRootModel()
getRootModel():
T
Defined in: packages/models/src/repositories/abstract.ts:67
Returns
T
Inherited from
AbstractRepository.getRootModel
getTableRoot()
getTableRoot():
ModelClass<Storable<any,any>> |undefined
Defined in: packages/models/src/repositories/abstract.ts:84
Returns
ModelClass<Storable<any, any>> | undefined
the model owning the untyped rows of the storage
Inherited from
AbstractRepository.getTableRoot
getUID()
getUID(
object):string
Defined in: packages/models/src/repositories/abstract.ts:307
Parameters
object
any
Returns
string
Inherited from
incrementAttribute()
incrementAttribute<
K,L>(primaryKey,info,_conditionField?,_condition?):Promise<void>
Defined in: packages/models/src/repositories/abstract.ts:340
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
AbstractRepository.incrementAttribute
incrementAttributes()
incrementAttributes<
K,L>(primaryKey,info,_conditionField?,_condition?):Promise<void|Record<string,number>>
Defined in: packages/models/src/repositories/event.ts:57
Increment numeric attributes with event emission
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; })[] | Record<L, number>
_conditionField?
K | null
_condition?
any
Returns
Promise<void | Record<string, number>>
Overrides
AbstractRepository.incrementAttributes
iterate()
iterate(
query,params?):AsyncGenerator<InstanceType<T>,any,any>
Defined in: packages/models/src/repositories/event.ts:112
Iterate through all objects
Parameters
query
string
the query filter
params?
QueryParameters
values for the ? or :name placeholders, bound before reaching the underlying repository
Returns
AsyncGenerator<InstanceType<T>, any, any>
an async generator of objects
Overrides
monitor()
protectedmonitor<R>(operation,query,fn,details):Promise<R>
Defined in: packages/models/src/repositories/abstract.ts:652
Helper that times a query operation, catches and rethrows errors, and calls onQuery safely
Type Parameters
R
R
Parameters
operation
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/src/repositories/abstract.ts:880
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/src/repositories/abstract.ts:857
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/src/repositories/abstract.ts:868
Type Parameters
K
K extends string | number | symbol
Parameters
event
K
listener
(data) => void
Returns
void
Inherited from
parseLegacyUID()
protectedparseLegacyUID(uid):PrimaryKey<InstanceType<T>> |undefined
Defined in: packages/models/src/repositories/abstract.ts:210
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
AbstractRepository.parseLegacyUID
parseStatement()
protectedparseStatement(type,statement,params?):Promise<Query>
Defined in: packages/models/src/repositories/abstract.ts:403
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
"DELETE" | "UPDATE"
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
AbstractRepository.parseStatement
parseUID()
parseUID(
uid,forceObject?):PrimaryKeyType<InstanceType<T>> |PrimaryKey<InstanceType<T>>
Defined in: packages/models/src/repositories/abstract.ts:184
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<
K>(primaryKey,data,_conditionField?,_condition?):Promise<void>
Defined in: packages/models/src/repositories/event.ts:418
Patch with event emission (emits Patch before and Patched after)
Type Parameters
K
K extends string
Parameters
primaryKey
PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
data
Partial<InstanceType<T>>
_conditionField?
K | null
_condition?
any
Returns
Promise<void>
Overrides
query()
query(
query,params?):Promise<{continuationToken?:string;results:InstanceType<T>[]; }>
Defined in: packages/models/src/repositories/event.ts:88
Query with event emission
Parameters are bound here, so the events carry the bound query and the underlying repository (often a store one) only ever receives a plain query.
Parameters
query
string
the query to execute
params?
QueryParameters
values for the ? or :name placeholders
Returns
Promise<{ continuationToken?: string; results: InstanceType<T>[]; }>
the query results with optional continuation token
Overrides
ref()
ref(
key):ModelRefWithCreate<InstanceType<T>>
Defined in: packages/models/src/repositories/abstract.ts:333
Parameters
key
PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
Returns
ModelRefWithCreate<InstanceType<T>>
Inherited from
removeAttribute()
removeAttribute<
L,K>(uuid,attribute,conditionField?,condition?):Promise<void>
Defined in: packages/models/src/repositories/event.ts:367
Remove attribute with event emission
Type Parameters
L
L extends string
K
K extends string
Parameters
uuid
PrimaryKeyType<InstanceType<T>>
attribute
K
conditionField?
L | null
condition?
PropertyPathType<InstanceType<T>, L> | JSONed<PropertyPathType<InstanceType<T>, L>>
Returns
Promise<void>
Overrides
AbstractRepository.removeAttribute
removeListener()
removeListener<
K>(event,listener):void
Defined in: packages/models/src/repositories/abstract.ts:900
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
AbstractRepository.removeListener
safeOnQuery()
protectedsafeOnQuery(info):void
Defined in: packages/models/src/repositories/abstract.ts:636
Safely invoke the onQuery callback without throwing into the caller
Parameters
info
query execution info
Returns
void
Inherited from
AbstractRepository.safeOnQuery
setAttribute()
setAttribute<
K,L>(primaryKey,attribute,value,conditionField?,condition?):Promise<void>
Defined in: packages/models/src/repositories/abstract.ts:322
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
AbstractRepository.setAttribute
setMaxListeners()
setMaxListeners(
n):this
Defined in: packages/models/src/repositories/abstract.ts:920
EventEmitter-compatibility shim. Records the max-listeners hint (no enforcement).
Parameters
n
number
the new hint value
Returns
this
this for chaining
Inherited from
AbstractRepository.setMaxListeners
setTableRoot()
setTableRoot(
root?):this
Defined in: packages/models/src/repositories/event.ts:47
Set the table root on the wrapped repository too: it filters the untyped rows
Parameters
root?
ModelClass<Storable<any, any>>
the model owning the untyped rows of the storage
Returns
this
this
Overrides
AbstractRepository.setTableRoot
typeResolver()
protectedtypeResolver():ModelTypeResolver
Defined in: packages/models/src/repositories/abstract.ts:93
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
the resolver
Inherited from
AbstractRepository.typeResolver
update()
update<
K>(data,conditionField?,condition?):Promise<void>
Defined in: packages/models/src/repositories/event.ts:432
Update with event emission (emits Update before and Updated after)
Type Parameters
K
K extends string
Parameters
data
Helpers<InstanceType<T>>
conditionField?
K | null
condition?
PropertyPathType<InstanceType<T>, K>
Returns
Promise<void>
Overrides
updateMany()
updateMany(
statement,params?):Promise<number>
Defined in: packages/models/src/repositories/event.ts:251
Update in bulk through the underlying repository
Bulk operations emit no per-object event: see Repository.updateMany.
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
Overrides
updateManyByKey()
protectedupdateManyByKey(statement,params?):Promise<number>
Defined in: packages/models/src/repositories/abstract.ts:549
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
AbstractRepository.updateManyByKey
upsert()
upsert(
data):Promise<InstanceType<T>>
Defined in: packages/models/src/repositories/abstract.ts:312
Parameters
data
Helpers<InstanceType<T>>
Returns
Promise<InstanceType<T>>
Inherited from
upsertItemToCollection()
upsertItemToCollection<
K,L>(uuid,collection,item,index?,itemWriteConditionField?,itemWriteCondition?):Promise<void>
Defined in: packages/models/src/repositories/event.ts:317
Upsert item to collection with event emission
Type Parameters
K
K extends string
L
L extends string | number | symbol
Parameters
uuid
PrimaryKeyType<InstanceType<T>>
collection
K
item
ArrayElement<InstanceType<T>[K]> | JSONed<ArrayElement<InstanceType<T>[K]>>
index?
number
itemWriteConditionField?
ArrayElement<InstanceType<T>[K]> extends object ? L : never
itemWriteCondition?
ArrayElement<InstanceType<T>[K]> extends object ? object & ArrayElement[L] : ArrayElement<InstanceType<T>[K]>
Returns
Promise<void>
Overrides
AbstractRepository.upsertItemToCollection
writeIfPresent()
protectedwriteIfPresent(key,write):Promise<boolean>
Defined in: packages/models/src/repositories/abstract.ts:509
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