Primary key
Define what is the right property to relay on for "_ById" queries
For query and upsert data SugoiJS use primary key of the instance\query object.
The primary key is a property which decorated with @Primary()
Using the Primary key will be done by:
(Utility function)
getPrimaryKey(classToUse)
Return the primary key name from given class, if not found 'null' will be returned.
(Static method)
castIdToQuery(id:string,classToUse = this)
Will return an object with property name which is decorated with Primary as the key and the ID as the value
classToUse
- class to get the primary key from (default isthis
)(static method)
getIdFromQuery(query: any,classToUse = this, deleteProperty:boolean = true)
If query contains 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}
Returns a key value object of primary key and its' value for the current instance.
if no primary key set the function will throw an exception;
Full example:
All of the @sugoi/orm predefined methods which is mentioned before using the primary key value.
Last updated