API Docs for:
Show:

LoopbackRepository Class

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

count

(
  • [where]
)
Promise(Number) public

Return the number of models that match the optional "where" filter.

Parameters:

  • [where] Object optional

Returns:

Promise(Number):

createFromQueryResults

(
  • params
  • objs
  • [options]
)
Array(BaseModel) protected

Create model instances from query results

Parameters:

  • params Object
  • objs Array(Object)
  • [options] Object optional

Returns:

Array(BaseModel):

models

createFromResult

(
  • obj
  • [options]
)
BaseModel protected

Create model instance from result from client

Parameters:

  • obj Object
  • [options] Object optional

Returns:

BaseModel:

model

delete

(
  • entity
  • [options]
)
Promise(Boolean) public

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

Parameters:

  • entity Entity
  • [options] Object optional

Returns:

Promise(Boolean):

isDeleted

deprecated

(
  • methodName
  • message
)
Error protected

Show indication message of deprecated method

Parameters:

  • methodName String
  • message String

Returns:

Error:

error

(
  • reason
  • [message]
)
Error

create instance of DomainError

Parameters:

  • reason String

    reason of the error

  • [message] String optional

Returns:

Error:

get

(
  • id
  • [options]
)
Promise(Entity) public

get entity by id.

Parameters:

  • id String | Number
  • [options] Object optional
    • [foreignKey] String optional

Returns:

Promise(Entity):

entity

getAll

() Promise(Array(Entity))

get all entities

Returns:

Promise(Array(Entity)):

array of entities

getById

(
  • id
  • [options]
)
Promise(Entity) public

alias for get()

Parameters:

  • id String | Number
  • [options] Object optional
    • [client=@client] ResourceClientInterface optional

Returns:

Promise(Entity):

entity

getByIds

(
  • ids
  • [options]
)
Promise(Array(Entity)) public

get entities by id.

Parameters:

  • ids Array | (String | Number)
  • [options] Object optional

Returns:

Promise(Array(Entity)):

entities

getClientByEntity

(
  • entity
)
LoopbackClient protected

get client by entity. By default it returns @client

Parameters:

Returns:

LoopbackClient:

client

getClientByForeignKey

(
  • foreignKey
)
LoopbackClient protected

get client by foreign key. By default it returns @client

Parameters:

  • foreignKey String

Returns:

LoopbackClient:

client

getClientByQuery

(
  • query
)
LoopbackClient protected

get client by query value. By default it returns @client

Parameters:

  • query Object

Returns:

LoopbackClient:

client

getDiff

(
  • entity
  • [options]
)
Promise(Object) public

get diff from perpetuation layer

Parameters:

  • entity Entity
  • [options] Object optional
    • [client=@client] ResourceClientInterface optional

Returns:

Promise(Object):

diff

getFacade

() Facade deprecated

Get facade

Returns:

getLbModelName

() String static

get model name used in LoopBack

Returns:

String:

getModelClass

() Class

get model class this factory handles

Returns:

Class:

getModule

() BaseModule

Get module which this class belongs to

Returns:

getParent

() Function

get parent class

Returns:

Function:

getRelatedClient

(
  • params
)
LoopbackRelatedClient protected

Get loopback-related-client

Parameters:

  • params Object
    • modelName String

      foreign model name

    • id String

      foreign id

    • [relation] String optional

      relation name

    • [foreignKey] String optional

      foreign key prop.

    • [through] String optional
    • [keyThrough] String optional

Returns:

LoopbackRelatedClient:

modifyDate

(
  • data
)
private

convert 'date' type property for loopback format

Parameters:

parseSessionId

(
  • sessionId
)
Array(String) protected

get accessToken and userId by sessionId

Parameters:

  • sessionId String

Returns:

Array(String):

[accessToken, userId]

query

(
  • [params]
  • [options]
)
Promise(Array(Entity)) public

Find all model instances that match params

Parameters:

  • [params] Object optional

    query parameters

  • [options] Object optional

Returns:

Promise(Array(Entity)):

array of entities

save

(
  • entity
  • [options]
)
Promise(Entity) public

Update or insert a model instance

Parameters:

  • entity Entity | Object
  • [options] Object optional

Returns:

Promise(Entity):

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

singleQuery

(
  • [params]
  • [options]
)
Promise(Entity) public

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

Parameters:

  • [params] Object optional

    query parameters

  • [options] Object optional

Returns:

Promise(Entity):

entity

update

(
  • id
  • data
  • [options]
)
Promise(Entity) public

Update set of attributes.

Parameters:

  • id Any

    id of the entity to update

  • data Object

    key-value pair to update

  • [options] Object optional

Returns:

Promise(Entity):

updated entity

updateProps

(
  • entity
  • data
  • [options]
)
Object public

Update set of attributes and returns newly-updated props (other than props)

Parameters:

  • entity Entity
  • data Object

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

  • [options] Object optional
    • [client=@client] ResourceClientInterface optional

Returns:

Object:

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

lbModelName

String static

model name used in Loopback it will be the same value as @modelName if not set

props

Object static

Map to convert loopback's object prop into model prop

key: loopback's prop value: model prop

if value is null or undefined, the property only exists in loopback and is removed from the created model.