Primary key
Define what is the right property to relay on for "_ById" queries
For query and upsert data @sugoi use primary key of the instance\query object.
This primary key is property which decorated with @Primary()
Using the Primary key will done by:
(Utility function)
getPrimaryKey(classToUse)
Return the primary key name from given class, if not found null will return.
(static method)
castIdToQuery(id:string,classToUse = this)
Will return an object with property name which decorate with Primary as key and the id as value
classToUse
- class to get the primary key from (default isthis
)(static method)
getIdFromQuery(query: any,classToUse = this, deleteProperty:boolean = true)
If query contain the primary key the function will return the query primary key value.
classToUse
- class to get the primary key from (default isthis
)deleteProperty
- delete primary key property from the query (default istrue
)(instance method)
getIdQuery():{[prop:string]:string}
Return key value object of primary key and its value of the current instance
if no primary key set the function will return null;
Full example:
All of the @sugoi/orm predefined interface methods which mentioned before use the primary key value.
Last updated