API Docs for:
Show:

BaseRepository Class

Extends Base
Module: base-domain

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 a @getFacade() method.

Methods

appendTimeStamp

(
  • data
  • isUpdate
)
Object protected

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 Boolean

    true when updating

Returns:

Object:

data

delete

(
  • entity
  • [client=@client]
)
Promise(Boolean) public

Destroy the given entity (which must have "id" value)

Parameters:

Returns:

Promise(Boolean):

isDeleted

get

(
  • id
  • [client=@client]
)
Promise(Entity) public

get object by ID.

Parameters:

Returns:

Promise(Entity):

entity

getById

(
  • id
  • [client=@client]
)
Promise(Entity) public

alias for get()

Parameters:

Returns:

Promise(Entity):

entity

getFacade

() Facade

Inherited from Base: src/lib/base.coffee:32

get facade

the implementation is in Facade#requre()

Returns:

getModelClass

() Class

get model class this factory handles

Returns:

Class:

query

(
  • [params]
  • [client=@client]
)
Promise(Array(Entity)) public

Find all model instances that match params

Parameters:

Returns:

Promise(Array(Entity)):

array of entities

save

(
  • entity
  • [client=@client]
)
Promise(Entity) public

Update or insert a model instance

Parameters:

Returns:

Promise(Entity):

entity (the same instance from input, if entity given,)

singleQuery

(
  • [params]
  • [client=@client]
)
Promise(Entity) public

Find one model instance that matches params, Same as query, but limited to one result

Parameters:

Returns:

Promise(Entity):

entity

update

(
  • id
  • data
  • [client=@client]
)
Promise(Entity) public

Update set of attributes.

Parameters:

  • id Any

    id of the entity to update

  • data Object

    key-value pair to update (notice: this must not be instance of Entity)

  • [client=@client] ResourceClientInterface optional

Returns:

Promise(Entity):

updated entity

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