BaseRepository Class
Base repository class of DDD pattern. Responsible for perpetuation of models. BaseRepository has a client, which access to data resource (RDB, NoSQL, memory, etc...)
the parent "Base" class just simply gives this.facade
property
Item Index
Methods
Methods
appendTimeStamp
-
data
-
isUpdate
add createdAt, updatedAt to given data
- createdAt will not be overriden if already set.
- updatedAt will be overriden for each time
Parameters:
-
data
Object -
isUpdate
Booleantrue when updating
Returns:
data
createFromQueryResults
-
params
-
objs
-
[options]
Create model instances from query results
Parameters:
-
params
Object -
objs
Array(Object) -
[options]
Object optional
Returns:
models
createFromResult
-
obj
-
[options]
Create model instance from result from client
Parameters:
-
obj
Object -
[options]
Object optional
Returns:
model
delete
-
entity
-
[options]
Destroy the given entity (which must have "id" value)
Parameters:
-
entity
Entity -
[options]
Object optional-
[client=@client]
ResourceClientInterface optional
-
Returns:
isDeleted
deprecated
-
methodName
-
message
Show indication message of deprecated method
Parameters:
-
methodName
String -
message
String
Returns:
error
-
reason
-
[message]
create instance of DomainError
Parameters:
-
reason
Stringreason of the error
-
[message]
String optional
Returns:
get
-
id
-
[options]
get entity by id.
Parameters:
-
id
String | Number -
[options]
Object optional-
[client=@client]
ResourceClientInterface optional
-
Returns:
entity
getAll
()
Array(Entity) | Promise(Array(Entity))
get all entities
Returns:
array of entities
getById
-
id
-
[options]
alias for get()
Parameters:
-
id
String | Number -
[options]
Object optional-
[client=@client]
ResourceClientInterface optional
-
Returns:
entity
getByIds
-
ids
-
[options]
get entities by id.
Parameters:
-
ids
Array | (String | Number) -
[options]
Object optional-
[client=@client]
ResourceClientInterface optional
-
Returns:
entities
getDiff
-
entity
-
[options]
get diff from perpetuation layer
Parameters:
-
entity
Entity -
[options]
Object optional-
[client=@client]
ResourceClientInterface optional
-
Returns:
diff
getModelClass
()
Class
get model class this factory handles
Returns:
getParent
()
Function
get parent class
Returns:
query
-
[params]
-
[options]
Find all model instances that match params
Parameters:
-
[params]
Object optionalquery parameters
-
[options]
Object optional-
[client=@client]
ResourceClientInterface optional
-
Returns:
array of entities
save
-
entity
-
[options]
Update or insert a model instance
Parameters:
-
entity
Entity | Object -
[options]
Object optional-
[client=@client]
ResourceClientInterface optional
-
Returns:
entity (the same instance from input, if entity given,)
setRoot
()
protected
singleQuery
-
[params]
-
[options]
Find one model instance that matches params, Same as query, but limited to one result
Parameters:
-
[params]
Object optionalquery parameters
-
[options]
Object optional-
[client=@client]
ResourceClientInterface optional
-
Returns:
entity
update
-
id
-
data
-
[options]
Update set of attributes.
Parameters:
-
id
String | Numberid of the entity to update
-
data
Objectkey-value pair to update (notice: this must not be instance of Entity)
-
[options]
Object optional-
[client=@client]
ResourceClientInterface optional
-
Returns:
updated entity
updateProps
-
entity
-
data
-
[options]
Update set of attributes and returns newly-updated props (other than props
)
Parameters:
-
entity
Entity -
data
Objectkey-value pair to update (notice: this must not be instance of Entity)
-
[options]
Object optional-
[client=@client]
ResourceClientInterface optional
-
Returns:
updated props
Properties
client
ResourceClientInterface
protected
client accessing to data resource (RDB, NoSQL, memory, etc...)
mock object is input by default. Extenders must set this property to achieve perpetuation
modelName
String
protected
static
model name to handle