Interface: AnyObject

Objects with open properties

Interface: Class

Interface for classes with new operator and static properties/methods

constructor(args: any[]) : T

Parameters
Name Type Default Value Flags Description
args any[] rest

Interface for classes with new operator and static properties/methods

Interface: ConstructorFunction

Interface for constructor functions without new operator, for example,

function Foo(x) {
  if (!(this instanceof Foo)) { return new Foo(x); }
  this.x = x;
}

Type alias: Callback(err: Error | string | null | undefined, result: T): void

Type alias for Node.js callback functions

Arguments
Name Type Description
err Error | string | null | undefined
result T

Type alias: NamedParameters = AnyObject

Type alias: PositionalParameters = any[]

Interface: Connector

Common properties/operations for connectors

Properties
Name Type Default Value Flags Description
configModel Model exported optional

Common properties/operations for connectors

interfaces string[] exported optional

Common properties/operations for connectors

name string exported

Common properties/operations for connectors

connect() : Promise<void>

disconnect() : Promise<void>

execute(command: Command, parameters: NamedParameters | PositionalParameters, options: Options) : Promise<AnyObject>

Parameters
Name Type Default Value Flags Description
command Command

Common properties/operations for connectors

parameters NamedParameters | PositionalParameters

Common properties/operations for connectors

options Options optional

Common properties/operations for connectors

ping() : Promise<void>

Interface: CrudConnector

CRUD operations for connector implementations

count(modelClass: Class<Entity>, where: Where, options: Options) : Promise<number>

Count matching entities

Returns:

A promise of number of matching entities

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

where Where optional

The matching criteria

options Options optional

Options for the operation

create(modelClass: Class<Entity>, entity: EntityData, options: Options) : Promise<EntityData>

Create a new entity

Returns:

A promise of the entity created

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

entity EntityData

The entity instance or data

options Options optional

Options for the operation

createAll(modelClass: Class<Entity>, entities: EntityData[], options: Options) : Promise<EntityData[]>

Create multiple entities

Returns:

A promise of an array of entities created

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

entities EntityData[]

An array of entity instances or data

options Options optional

Options for the operation

delete(modelClass: Class<Entity>, entity: EntityData, options: Options) : Promise<boolean>

Delete an entity

Returns:

Promise if an entity is deleted, otherwise Promise

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

entity EntityData

The entity instance or data

options Options optional

Options for the operation

deleteAll(modelClass: Class<Entity>, where: Where, options: Options) : Promise<number>

Delete matching entities

Returns:

A promise of number of matching entities deleted

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

where Where optional

The matching criteria

options Options optional

Options for the operation

deleteById(modelClass: Class<Entity>, id: IdType, options: Options) : Promise<boolean>

Delete an entity by id

Returns:

Promise if an entity is deleted for the id, otherwise Promise

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

id IdType

The entity id value

options Options optional

Options for the operation

exists(modelClass: Class<Entity>, id: IdType, options: Options) : Promise<boolean>

Check if an entity exists for the id

Returns:

Promise if an entity exists for the id, otherwise Promise

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

id IdType

The entity id value

options Options optional

Options for the operation

find(modelClass: Class<Entity>, filter: Filter, options: Options) : Promise<EntityData[]>

Find matching entities by the filter

Returns:

A promise of an array of entities found for the filter

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

filter Filter optional

The query filter

options Options optional

Options for the operation

findById(modelClass: Class<Entity>, id: IdType, options: Options) : Promise<EntityData>

Find an entity by id

Returns:

A promise of the entity found for the id

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

id IdType

The entity id value

options Options optional

Options for the operation

replaceById(modelClass: Class<Entity>, id: IdType, data: EntityData, options: Options) : Promise<boolean>

Replace an entity by id

Returns:

Promise if an entity is replaced for the id, otherwise Promise

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

id IdType

The entity id value

data EntityData

The data attributes to be updated

options Options optional

Options for the operation

save(modelClass: Class<Entity>, entity: EntityData, options: Options) : Promise<EntityData>

Save an entity

Returns:

A promise of the entity saved

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

entity EntityData

The entity instance or data

options Options optional

Options for the operation

update(modelClass: Class<Entity>, entity: EntityData, options: Options) : Promise<boolean>

Update an entity

Returns:

Promise if an entity is updated, otherwise Promise

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

entity EntityData

The entity instance or data

options Options optional

Options for the operation

updateAll(modelClass: Class<Entity>, data: EntityData, where: Where, options: Options) : Promise<number>

Update matching entities

Returns:

A promise of number of matching entities deleted

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

data EntityData

The data attributes to be updated

where Where optional

The matching criteria

options Options optional

Options for the operation

updateById(modelClass: Class<Entity>, id: IdType, data: EntityData, options: Options) : Promise<boolean>

Update an entity by id

Returns:

Promise if an entity is updated for the id, otherwise Promise

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

The model class

id IdType

The entity id value

data EntityData

The data attributes to be updated

options Options optional

Options for the operation

Interface: KVConnector

Key/Value operations for connector implementations

delete(modelClass: Class<Entity>, key: string, options: Options) : Promise<boolean>

Delete an entry by key

Returns:

Promise if an entry is deleted for the id, otherwise Promise

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

Model class

key string

Key for the entry

options Options optional

Options for the operation

deleteAll(modelClass: Class<Entity>, options: Options) : Promise<number>

Delete all entries

Returns:

A promise of the number of entries deleted

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

Model class

options Options optional

Options for the operation

expire(modelClass: Class<Entity>, key: string, ttl: number, options: Options) : Promise<boolean>

Set up ttl for an entry by key

Returns:

Promise if an entry is configured for the key, otherwise Promise

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

Model class

key string

Key for the entry

ttl number

Key/Value operations for connector implementations

options Options optional

Options for the operation

get(modelClass: Class<Entity>, key: string, options: Options) : Promise<T>

Get an entry by key

Returns:

A promise of the entry found for the key

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

Model class

key string

Key for the entry

options Options optional

Options for the operation

iterateKeys(modelClass: Class<Entity>, filter: Filter, options: Options) : Promise<Iterator<T>>

Get an Iterator for matching keys

Returns:

A promise of an iterator of entries

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

Model class

filter Filter optional

Matching filter

options Options optional

Options for the operation

keys(modelClass: Class<Entity>, options: Options) : Promise<string[]>

Fetch all keys

Returns:

A promise of an array of keys for all entries

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

Model class

options Options optional

Options for the operation

set(modelClass: Class<Entity>, key: string, value: EntityData, options: Options) : Promise<boolean>

Set an entry with key/value

Returns:

Promise if an entry is set for the key, otherwise Promise

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

Model class

key string

Key for the entry

value EntityData

Value for the entry

options Options optional

Options for the operation

ttl(modelClass: Class<Entity>, key: string, ttl: number, options: Options) : Promise<number>

Get ttl for an entry by key

Returns:

A promise of the TTL value

Parameters
Name Type Default Value Flags Description
modelClass Class<Entity>

Model class

key string

Key for the entry

ttl number

Time to live in millisenconds

options Options optional

Options for the operation

Interface: DataSource

DataSource denotes a configured connector

Properties
Name Type Default Value Flags Description
connector Connector exported optional

DataSource denotes a configured connector

name string exported

DataSource denotes a configured connector

settings AnyObject exported

DataSource denotes a configured connector

Class: modelmetadatahelper = new ModelMetadataHelper()

getModelMetadata(target: Function, options: InspectionOptions) : ModelDefinition | __type

A utility function to simplify retrieving metadata from a target model and its properties.

Parameters
Name Type Default Value Flags Description
target Function

The class from which to retrieve metadata.

options InspectionOptions optional

An options object for the MetadataInspector to customize the output of the metadata retrieval functions.

Namespace: property

const property.ERR_NO_ARGS = "decorator received less than two parameters"

const property.ERR_PROP_NOT_ARRAY = "@property.array can only decorate array properties!"

Function: property.array

property.array(itemType: Function, definition: Partial<PropertyDefinition>) : (Anonymous function)

Parameters
Name Type Default Value Flags Description
itemType Function

The class of the array to decorate

definition Partial<PropertyDefinition> optional

Optional PropertyDefinition object for additional metadata

Type alias: PropertyMap = MetadataMap

const MODEL_KEY = MetadataAccessor.create< Partial, ClassDecorator >('loopback:model')

const MODEL_PROPERTIES_KEY = MetadataAccessor.create< PropertyDefinition, PropertyDecorator >('loopback:model-properties')

const MODEL_WITH_PROPERTIES_KEY = MetadataAccessor.create< ModelDefinition, ClassDecorator >('loopback:model-and-properties')

Function: model

model(definition: Partial<ModelDefinitionSyntax>) : (Anonymous function)

Decorator for model definitions

Parameters
Name Type Default Value Flags Description
definition Partial<ModelDefinitionSyntax> optional

Enumeration: RelationType

Members
Name Default Value Flags Description
belongsTo exported
embedsMany exported
embedsOne exported
hasMany exported
hasOne exported
referencesMany exported
referencesOne exported

Class: relationmetadata = new RelationMetadata()

Properties
Name Type Default Value Flags Description
as string exported
target string | Class<Entity> exported
type RelationType exported

const RELATIONS_KEY = "loopback:relations"

Function: belongsTo

belongsTo(definition: Object) : anonymous

Decorator for belongsTo

Parameters
Name Type Default Value Flags Description
definition Object optional

Function: embedsMany

embedsMany(definition: Object) : anonymous

Decorator for embedsMany

Parameters
Name Type Default Value Flags Description
definition Object optional

Function: embedsOne

embedsOne(definition: Object) : anonymous

Decorator for embedsOne

Parameters
Name Type Default Value Flags Description
definition Object optional

Function: hasMany

hasMany(definition: Object) : anonymous

Decorator for hasMany

Parameters
Name Type Default Value Flags Description
definition Object optional

Function: hasOne

hasOne(definition: Object) : anonymous

Decorator for hasOne

Parameters
Name Type Default Value Flags Description
definition Object optional

Function: referencesMany

referencesMany(definition: Object) : anonymous

Decorator for referencesMany

Parameters
Name Type Default Value Flags Description
definition Object optional

Function: referencesOne

referencesOne(definition: Object) : anonymous

Decorator for referencesOne

Parameters
Name Type Default Value Flags Description
definition Object optional

Function: relation

relation(definition: Object) : anonymous

Decorator for relations

Parameters
Name Type Default Value Flags Description
definition Object optional

Class: repositorymetadata = new RepositoryMetadata()

Metadata for a repository

Properties
Name Type Default Value Flags Description
dataSource DataSource | DataSource exported optional

Instance of the data source

dataSourceName undefined | string exported optional

Name of the data source

modelClass undefined | Entity exported optional

Class of the model

modelName undefined | string exported optional

Name of the model

name undefined | string exported optional

Name of the predefined repository

constructor(modelOrRepo: string | Entity, dataSource: string | DataSource | DataSource) : RepositoryMetadata

Constructor for RepositoryMetadata

Parameters
Name Type Default Value Flags Description
modelOrRepo string | Entity

Name or class of the model. If the value is a string and dataSource is not present, it will treated as the name of a predefined repository

dataSource string | DataSource | DataSource optional

Name or instance of the data source

For example:

  • new RepositoryMetadata(repoName);
  • new RepositoryMetadata(modelName, dataSourceName);
  • new RepositoryMetadata(modelClass, dataSourceInstance);
  • new RepositoryMetadata(modelName, dataSourceInstance);
  • new RepositoryMetadata(modelClass, dataSourceName);

Type alias: RepositoryDecorator(target: Object, key: string | symbol, descriptorOrIndex: TypedPropertyDescriptor<any> | number): void

Type definition for decorators returned by @repository decorator factory

Arguments
Name Type Description
target Object
key string | symbol
descriptorOrIndex TypedPropertyDescriptor<any> | number

Function: repository

repository(repositoryName: string | Class<Repository<Model>>) : RepositoryDecorator

Decorator for repository injections on properties or method arguments

class CustomerController {
  @repository(CustomerRepository) public custRepo: CustomerRepository;

  constructor(
    @repository(ProductRepository) public prodRepo: ProductRepository,
  ) {}
  // ...
}

Parameters
Name Type Default Value Flags Description
repositoryName string | Class<Repository<Model>>

Name of the repo

repository(model: string | Entity, dataSource: string | DataSource) : RepositoryDecorator

Decorator for DefaultCrudRepository generation and injection on properties or method arguments based on the given model and dataSource (or their names)

class CustomerController {
  @repository('Customer', 'mySqlDataSource')
  public custRepo: DefaultCrudRepository<
    Customer,
    typeof Customer.prototype.id
  >;

  constructor(
    @repository(Product, mySqlDataSource)
    public prodRepo: DefaultCrudRepository<
      Product,
      typeof Product.prototype.id
    >,
  ) {}
  // ...
}

Parameters
Name Type Default Value Flags Description
model string | Entity

Name/class of the model

dataSource string | DataSource

Name/instance of the dataSource

Namespace: juggler

Enumeration: juggler.Operators

Operators for where clauses

Members
Name Default Value Flags Description
and exported

Operators for where clauses

between exported

Operators for where clauses

eq exported

Operators for where clauses

exists exported

Operators for where clauses

gt exported

Operators for where clauses

gte exported

Operators for where clauses

inq exported

Operators for where clauses

lt exported

Operators for where clauses

lte exported

Operators for where clauses

neq exported

Operators for where clauses

or exported

Operators for where clauses

Class: juggler.datasource = new juggler.DataSource()

DataSource instance properties/operations

Properties
Name Type Default Value Flags Description
connected undefined | true | false exported optional

DataSource instance properties/operations

connecting undefined | true | false exported optional

DataSource instance properties/operations

name string exported

DataSource instance properties/operations

settings AnyObject exported

DataSource instance properties/operations

constructor(name: undefined | string, settings: AnyObject, modelBuilder: ModelBuilder) : DataSource

Parameters
Name Type Default Value Flags Description
name undefined | string optional

DataSource instance properties/operations

settings AnyObject optional

DataSource instance properties/operations

modelBuilder ModelBuilder optional

DataSource instance properties/operations

constructor(settings: AnyObject, modelBuilder: ModelBuilder) : DataSource

Parameters
Name Type Default Value Flags Description
settings AnyObject optional

DataSource instance properties/operations

modelBuilder ModelBuilder optional

DataSource instance properties/operations

createModel(name: string, properties: AnyObject, options: Options) : T

Create a model class

Parameters
Name Type Default Value Flags Description
name string

Name of the model

properties AnyObject optional

An object of property definitions

options Options optional

Options for model settings

Class: juggler.keyvaluemodel = new juggler.KeyValueModel()

Properties
Name Type Default Value Flags Description
dataSource DataSource static exported optional
definition ModelDefinition static exported
modelName string static exported

constructor(args: any[]) : KeyValueModel

Parameters
Name Type Default Value Flags Description
args any[] rest

expire(key: string, ttl: number, options: Options, callback: Callback<number>) : PromiseOrVoid<number>

Set the TTL (time to live) in ms (milliseconds) for a given key. TTL is the remaining time before a key-value pair is discarded from the database.

Parameters
Name Type Default Value Flags Description
key string

Key to use when searching the database.

ttl number

TTL in ms to set for the key.

options Options optional
callback Callback<number> optional

get(key: string, options: Options, callback: Callback<KVData>) : PromiseOrVoid<KVData>

Return the value associated with a given key.

Parameters
Name Type Default Value Flags Description
key string

Key to use when searching the database.

options Options optional
callback Callback<KVData> optional

iterateKeys(filter: Filter, options: Options) : Iterator<Promise<string>>

Asynchronously iterate all keys in the database. Similar to .keys() but instead allows for iteration over large data sets without having to load everything into memory at once.

Callback example:

// Given a model named `Color` with two keys `red` and `blue`
var iterator = Color.iterateKeys();
it.next(function(err, key) {
  // key contains `red`
  it.next(function(err, key) {
    // key contains `blue`
  });
});

Promise example:

// Given a model named `Color` with two keys `red` and `blue`
var iterator = Color.iterateKeys();
Promise.resolve().then(function() {
  return it.next();
})
.then(function(key) {
  // key contains `red`
  return it.next();
});
.then(function(key) {
  // key contains `blue`
});

Returns:

An Object implementing next(cb) -> Promise function that can be used to iterate all keys.

Parameters
Name Type Default Value Flags Description
filter Filter optional

An optional filter object with the following

options Options optional

keys(filter: Filter, options: Options, callback: Callback<string[]>) : PromiseOrVoid<string[]>

Return all keys in the database.

WARNING: This method is not suitable for large data sets as all key-values pairs are loaded into memory at once. For large data sets, use iterateKeys() instead.

Parameters
Name Type Default Value Flags Description
filter Filter optional

An optional filter object with the following

options Options optional

callback Callback<string[]> optional

set(key: string, value: KVData, options: Options, callback: Callback<boolean>) : PromiseOrVoid<boolean>

Persist a value and associate it with the given key.

Parameters
Name Type Default Value Flags Description
key string

Key to associate with the given value.

value KVData

Value to persist.

options Options optional
callback Callback<boolean> optional

toJSON() : Object

toObject(options: Options) : Object

Parameters
Name Type Default Value Flags Description
options Options optional

ttl(key: string, options: Options, callback: Callback<number>) : PromiseOrVoid<number>

Return the TTL (time to live) for a given key. TTL is the remaining time before a key-value pair is discarded from the database.

Parameters
Name Type Default Value Flags Description
key string

Key to use when searching the database.

options Options optional
callback Callback<number> optional

attachTo(ds: DataSource) : void

Parameters
Name Type Default Value Flags Description
ds DataSource

Class: juggler.modelbase = new juggler.ModelBase()

Base model class

Properties
Name Type Default Value Flags Description
dataSource DataSource static exported optional

Base model class

definition ModelDefinition static exported

Base model class

modelName string static exported

Base model class

constructor(args: any[]) : ModelBase

Parameters
Name Type Default Value Flags Description
args any[] rest

Base model class

toJSON() : Object

toObject(options: Options) : Object

Parameters
Name Type Default Value Flags Description
options Options optional

Base model class

attachTo(ds: DataSource) : void

Parameters
Name Type Default Value Flags Description
ds DataSource

Base model class

Class: juggler.modelbuilder = new juggler.ModelBuilder()

Properties
Name Type Default Value Flags Description
definitions anonymous exported
models anonymous exported
settings AnyObject exported
defaultInstance ModelBuilder static exported
defaultMaxListeners number static exported

addListener(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol
listener anonymous

buildModelFromInstance(name: string, json: AnyObject, options: Options) : ModelBase

Parameters
Name Type Default Value Flags Description
name string
json AnyObject
options Options

buildModels(schemas: AnyObject, createModel: Function) : anonymous

Parameters
Name Type Default Value Flags Description
schemas AnyObject
createModel Function optional

define(className: string, properties: AnyObject, settings: AnyObject, parent: undefined | ModelBase) : ModelBase

Parameters
Name Type Default Value Flags Description
className string
properties AnyObject optional
settings AnyObject optional
parent undefined | ModelBase optional

defineProperty(modelName: string, propertyName: string, propertyDefinition: AnyObject) : void

Parameters
Name Type Default Value Flags Description
modelName string
propertyName string
propertyDefinition AnyObject

defineValueType(type: string, aliases: string[]) : void

Parameters
Name Type Default Value Flags Description
type string
aliases string[] optional

emit(event: string | symbol, args: any[]) : boolean

Parameters
Name Type Default Value Flags Description
event string | symbol
args any[] rest

eventNames() : Array<string | symbol>

extendModel(modelName: string, properties: AnyObject) : void

Parameters
Name Type Default Value Flags Description
modelName string
properties AnyObject

getMaxListeners() : number

getModel(name: string, forceCreate: undefined | true | false) : ModelBase

Parameters
Name Type Default Value Flags Description
name string
forceCreate undefined | true | false optional

getModelDefinition(name: string) : ModelDefinition | undefined

Parameters
Name Type Default Value Flags Description
name string

getSchemaName(name: undefined | string) : string

Parameters
Name Type Default Value Flags Description
name undefined | string optional

listenerCount(type: string | symbol) : number

Parameters
Name Type Default Value Flags Description
type string | symbol

listeners(event: string | symbol) : Function[]

Parameters
Name Type Default Value Flags Description
event string | symbol

on(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol
listener anonymous

once(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol
listener anonymous

prependListener(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol
listener anonymous

prependOnceListener(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol
listener anonymous

removeAllListeners(event: string | symbol) : this

Parameters
Name Type Default Value Flags Description
event string | symbol optional

removeListener(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol
listener anonymous

resolveType(type: any) : any

Parameters
Name Type Default Value Flags Description
type any

setMaxListeners(n: number) : this

Parameters
Name Type Default Value Flags Description
n number

listenerCount(emitter: EventEmitter, event: string | symbol) : number

Parameters
Name Type Default Value Flags Description
emitter EventEmitter
event string | symbol

Class: juggler.modeldefinition = new juggler.ModelDefinition()

Model definition

Properties
Name Type Default Value Flags Description
name string exported

Model definition

properties AnyObject exported

Model definition

rawProperties AnyObject exported

Model definition

relations AnyObject[] exported optional

Model definition

settings AnyObject exported optional

Model definition

defaultMaxListeners number static exported

Model definition

constructor(modelBuilder: ModelBuilder | null | undefined, name: string, properties: undefined | anonymous, settings: AnyObject) : ModelDefinition

Parameters
Name Type Default Value Flags Description
modelBuilder ModelBuilder | null | undefined

Model definition

name string

Model definition

properties undefined | anonymous optional

Model definition

settings AnyObject optional

Model definition

constructor(modelBuilder: ModelBuilder | null | undefined, schema: Schema) : ModelDefinition

Parameters
Name Type Default Value Flags Description
modelBuilder ModelBuilder | null | undefined

Model definition

schema Schema

Model definition

addListener(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol

Model definition

listener anonymous

Model definition

build(forceRebuild: undefined | true | false) : AnyObject

Parameters
Name Type Default Value Flags Description
forceRebuild undefined | true | false optional

Model definition

columnMetadata(connectorType: string, propertyName: string) : ColumnMetadata

Parameters
Name Type Default Value Flags Description
connectorType string

Model definition

propertyName string

Model definition

columnName(connectorType: string, propertyName: string) : string

Parameters
Name Type Default Value Flags Description
connectorType string

Model definition

propertyName string

Model definition

columnNames(connectorType: string) : string[]

Parameters
Name Type Default Value Flags Description
connectorType string

Model definition

defineProperty(propertyName: string, propertyDefinition: PropertyDefinition) : void

Parameters
Name Type Default Value Flags Description
propertyName string

Model definition

propertyDefinition PropertyDefinition

Model definition

emit(event: string | symbol, args: any[]) : boolean

Parameters
Name Type Default Value Flags Description
event string | symbol

Model definition

args any[] rest

Model definition

eventNames() : Array<string | symbol>

getMaxListeners() : number

idName() : string

idNames() : string[]

ids() : IdDefinition[]

indexes() : anonymous

listenerCount(type: string | symbol) : number

Parameters
Name Type Default Value Flags Description
type string | symbol

Model definition

listeners(event: string | symbol) : Function[]

Parameters
Name Type Default Value Flags Description
event string | symbol

Model definition

on(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol

Model definition

listener anonymous

Model definition

once(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol

Model definition

listener anonymous

Model definition

prependListener(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol

Model definition

listener anonymous

Model definition

prependOnceListener(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol

Model definition

listener anonymous

Model definition

removeAllListeners(event: string | symbol) : this

Parameters
Name Type Default Value Flags Description
event string | symbol optional

Model definition

removeListener(event: string | symbol, listener: (args: any[]) => void) : this

Parameters
Name Type Default Value Flags Description
event string | symbol

Model definition

listener anonymous

Model definition

setMaxListeners(n: number) : this

Parameters
Name Type Default Value Flags Description
n number

Model definition

tableName(connectorType: string) : string

Parameters
Name Type Default Value Flags Description
connectorType string

Model definition

toJSON(forceRebuild: undefined | true | false) : AnyObject

Parameters
Name Type Default Value Flags Description
forceRebuild undefined | true | false optional

Model definition

listenerCount(emitter: EventEmitter, event: string | symbol) : number

Parameters
Name Type Default Value Flags Description
emitter EventEmitter

Model definition

event string | symbol

Model definition

Class: juggler.persistedmodel = new juggler.PersistedModel()

Properties
Name Type Default Value Flags Description
dataSource DataSource static exported optional
definition ModelDefinition static exported
modelName string static exported

constructor(args: any[]) : PersistedModel

Parameters
Name Type Default Value Flags Description
args any[] rest

delete(options: Options, callback: Callback<boolean>) : PromiseOrVoid<boolean>

Parameters
Name Type Default Value Flags Description
options Options optional
callback Callback<boolean> optional

destroy(options: Options, callback: Callback<boolean>) : PromiseOrVoid<boolean>

Deletes the model from persistence. Triggers destroy hook (async) before and after destroying object.

Parameters
Name Type Default Value Flags Description
options Options optional
callback Callback<boolean> optional

Callback function.

getId() : any

Get the id value for the PersistedModel.

Returns:

The id value

getIdName() : string

Get the id property name of the constructor.

Returns:

The id property name

isNewRecord() : boolean

Determine if the data model is new.

Returns:

Returns true if the data model is new; false otherwise.

reload(options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Reload object from persistence. Requires id member of object to be able to call find.

Parameters
Name Type Default Value Flags Description
options Options optional
callback Callback<PersistedData> optional

remove(options: Options, callback: Callback<boolean>) : PromiseOrVoid<boolean>

Parameters
Name Type Default Value Flags Description
options Options optional
callback Callback<boolean> optional

replaceAttributes(data: PersistedData, options: Options, callback: Callback<boolean>) : PromiseOrVoid<boolean>

Replace attributes for a model instance and persist it into the datasource. Performs validation before replacing.

Parameters
Name Type Default Value Flags Description
data PersistedData

Data to replace.

options Options optional
callback Callback<boolean> optional

save(options: Options, callback: Callback<boolean>) : PromiseOrVoid<boolean>

Save model instance. If the instance doesn't have an ID, then calls create instead. Triggers: validate, save, update, or create.

Parameters
Name Type Default Value Flags Description
options Options optional
callback Callback<boolean> optional

setId(val: any) : void

Set the correct id property for the PersistedModel. Uses the setId method if the model is attached to connector that defines it. Otherwise, uses the default lookup. Override this method to handle complex IDs.

Parameters
Name Type Default Value Flags Description
val any

The id value. Will be converted to the type that the id property specifies.

toJSON() : Object

toObject(options: Options) : Object

Parameters
Name Type Default Value Flags Description
options Options optional

updateAttribute(name: string, value: any, options: Options, callback: Callback<boolean>) : PromiseOrVoid<boolean>

Update a single attribute. Equivalent to updateAttributes({name: 'value'}, cb)

Parameters
Name Type Default Value Flags Description
name string

Name of property.

value any

Value of property.

options Options optional
callback Callback<boolean> optional

updateAttributes(data: PersistedData, options: Options, callback: Callback<boolean>) : PromiseOrVoid<boolean>

Update set of attributes. Performs validation before updating.

Triggers: validation, save and update hooks

Parameters
Name Type Default Value Flags Description
data PersistedData

Data to update.

options Options optional
callback Callback<boolean> optional

attachTo(ds: DataSource) : void

Parameters
Name Type Default Value Flags Description
ds DataSource

count(where: Where, options: Options, callback: Callback<number>) : PromiseOrVoid<number>

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

Parameters
Name Type Default Value Flags Description
where Where optional
options Options optional
callback Callback<number> optional

create(data: PersistedData, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Create new instance of Model, and save to database.

Parameters
Name Type Default Value Flags Description
data PersistedData
options Options optional
callback Callback<PersistedData> optional

deleteAll(where: Where, options: Options, callback: Callback<Count>) : PromiseOrVoid<Count>

Parameters
Name Type Default Value Flags Description
where Where optional
options Options optional
callback Callback<Count> optional

deleteById(id: any, options: Options, callback: Callback<Count>) : PromiseOrVoid<Count>

Parameters
Name Type Default Value Flags Description
id any
options Options optional
callback Callback<Count> optional

destroyAll(where: Where, options: Options, callback: Callback<Count>) : PromiseOrVoid<Count>

Destroy all model instances that match the optional where specification.

Parameters
Name Type Default Value Flags Description
where Where optional
options Options optional
callback Callback<Count> optional

destroyById(id: any, options: Options, callback: Callback<Count>) : PromiseOrVoid<Count>

Destroy model instance with the specified ID.

Parameters
Name Type Default Value Flags Description
id any

The ID value of model instance to delete.

options Options optional
callback Callback<Count> optional

exists(id: any, options: Options, callback: Callback<boolean>) : PromiseOrVoid<boolean>

Check whether a model instance exists in database.

Parameters
Name Type Default Value Flags Description
id any

Identifier of object (primary key value).

options Options optional
callback Callback<boolean> optional

find(filter: Filter, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData[]>

Find all model instances that match filter specification. See Querying models.

Parameters
Name Type Default Value Flags Description
filter Filter optional
options Options optional
callback Callback<PersistedData> optional

findById(id: any, filter: Filter, options: Options, callback: Callback<boolean>) : PromiseOrVoid<PersistedData>

Find object by ID with an optional filter for include/fields.

Parameters
Name Type Default Value Flags Description
id any

Primary key value

filter Filter optional
options Options optional
callback Callback<boolean> optional

findOne(filter: Filter, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Find one model instance that matches filter specification. Same as find, but limited to one result; Returns object, not collection.

Parameters
Name Type Default Value Flags Description
filter Filter optional
options Options optional
callback Callback<PersistedData> optional

findOrCreate(filter: Filter, data: PersistedData, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Finds one record matching the optional filter object. If not found, creates the object using the data provided as second argument. In this sense it is the same as find, but limited to one object. Returns an object, not collection. If you don't provide the filter object argument, it tries to locate an existing object that matches the data argument.

Parameters
Name Type Default Value Flags Description
filter Filter
data PersistedData

Data to insert if object matching the where filter is not found.

options Options optional
callback Callback<PersistedData> optional

getIdName() : string

Get the id property name of the constructor.

Returns:

The id property name

patchOrCreate(data: PersistedData, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Parameters
Name Type Default Value Flags Description
data PersistedData
options Options optional
callback Callback<PersistedData> optional

patchOrCreateWithWhere(where: Where, data: PersistedData, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Parameters
Name Type Default Value Flags Description
where Where
data PersistedData
options Options optional
callback Callback<PersistedData> optional

remove(where: Where, options: Options, callback: Callback<Count>) : PromiseOrVoid<Count>

Parameters
Name Type Default Value Flags Description
where Where optional
options Options optional
callback Callback<Count> optional

removeById(id: any, options: Options, callback: Callback<Count>) : PromiseOrVoid<Count>

Parameters
Name Type Default Value Flags Description
id any
options Options optional
callback Callback<Count> optional

replaceById(id: any, data: PersistedData, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Replace attributes for a model instance whose id is the first input argument and persist it into the datasource. Performs validation before replacing.

Parameters
Name Type Default Value Flags Description
id any

The ID value of model instance to replace.

data PersistedData

Data to replace.

options Options optional
callback Callback<PersistedData> optional

replaceOrCreate(data: PersistedData, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Replace or insert a model instance; replace existing record if one is found, such that parameter data.id matches id of model instance; otherwise, insert a new record.

Parameters
Name Type Default Value Flags Description
data PersistedData

The model instance data.

options Options optional
callback Callback<PersistedData> optional

update(where: Where, data: PersistedData, options: Options, callback: Callback<Count>) : PromiseOrVoid<Count>

Parameters
Name Type Default Value Flags Description
where Where optional
data PersistedData optional
options Options optional
callback Callback<Count> optional

updateAll(where: Where, data: PersistedData, options: Options, callback: Callback<Count>) : PromiseOrVoid<Count>

Update multiple instances that match the where clause.

Example:

Employee.updateAll({managerId: 'x001'}, {managerId: 'x002'}, function(err, info) {
    ...
});

Parameters
Name Type Default Value Flags Description
where Where optional
data PersistedData optional

Object containing data to replace matching instances, if AnyType.

options Options optional
callback Callback<Count> optional

updateOrCreate(data: PersistedData, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Parameters
Name Type Default Value Flags Description
data PersistedData
options Options optional
callback Callback<PersistedData> optional

upsert(data: PersistedData, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Update or insert a model instance

Parameters
Name Type Default Value Flags Description
data PersistedData

The model instance data to insert.

options Options optional
callback Callback<PersistedData> optional

upsertWithWhere(where: Where, data: PersistedData, options: Options, callback: Callback<PersistedData>) : PromiseOrVoid<PersistedData>

Update or insert a model instance based on the search criteria. If there is a single instance retrieved, update the retrieved model. Creates a new model if no model instances were found. Returns an error if multiple instances are found.

Parameters
Name Type Default Value Flags Description
where Where
data PersistedData

The model instance data to insert.

options Options optional
callback Callback<PersistedData> optional

Interface: juggler.ColumnMetadata

Column metadata

Properties
Name Type Default Value Flags Description
name string exported

Column metadata

Interface: juggler.Condition

Properties
Name Type Default Value Flags Description
and Where[] exported optional
between any[] exported optional
eq any exported optional
exists undefined | true | false exported optional
gt any exported optional
gte any exported optional
inq any[] exported optional
lt any exported optional
lte any exported optional
neq any exported optional
or Where[] exported optional

Interface: juggler.Count

Properties
Name Type Default Value Flags Description
count number exported

Interface: juggler.Fields

Selection of fields

Interface: juggler.Filter

Query filter object

Properties
Name Type Default Value Flags Description
fields Fields exported optional

Query filter object

include Inclusion[] exported optional

Query filter object

limit undefined | number exported optional

Query filter object

offset undefined | number exported optional

Query filter object

order string[] exported optional

Query filter object

skip undefined | number exported optional

Query filter object

where Where exported optional

Query filter object

Interface: juggler.IdDefinition

ID definition

Properties
Name Type Default Value Flags Description
id number exported

ID definition

name string exported

ID definition

property AnyObject exported

ID definition

Interface: juggler.Inclusion

Inclusion of related items

Properties
Name Type Default Value Flags Description
relation string exported

Inclusion of related items

scope Filter exported optional

Inclusion of related items

Interface: juggler.IndexDefinition

Index definition

Interface: juggler.PropertyDefinition

Property definition

Properties
Name Type Default Value Flags Description
name string exported

Property definition

type any exported

Property definition

Interface: juggler.RelationDefinition

Relation definition

Properties
Name Type Default Value Flags Description
name string exported

Relation definition

type string exported

Relation definition

Interface: juggler.Schema

Schema definition

Properties
Name Type Default Value Flags Description
name string exported

Schema definition

properties AnyObject exported

Schema definition

settings AnyObject exported optional

Schema definition

Interface: juggler.Where

Where object

Properties
Name Type Default Value Flags Description
and Where[] exported optional

Where object

or Where[] exported optional

Where object

Type alias: juggler.KVData = ModelData

Type alias: juggler.PersistedData = ModelData

Class: mixinbuilder = new MixinBuilder()

A builder to compose mixins

Properties
Name Type Default Value Flags Description
baseClass Class<any> constructorProperty exported public

The base class

constructor(baseClass: Class<any>) : MixinBuilder

Constructor for MixinBuilder

Parameters
Name Type Default Value Flags Description
baseClass Class<any>

The base class

with(mixins: MixinFunc[]) : Class<any>

Apply one or more mixin functions

Parameters
Name Type Default Value Flags Description
mixins MixinFunc[] rest

An array of mixin functions

mix(baseClass: Class<any>) : MixinBuilder

Create an instance of MixinBuilder with the base class

Parameters
Name Type Default Value Flags Description
baseClass Class<any>

The base class

Interface: MixinFunc

Interface for functions that can mix properties/methods into a base class

For example,

var calculatorMixin = Base => class extends Base {
  calc() { }
};

function timestampMixin(Base) {
  return class extends Base {
    created: Date = new Date();
    modified: Date = new Date();
  }
}

See http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/.

Interface: AppWithRepository

Interface for an Application mixed in with RepositoryMixin

Properties
Name Type Default Value Flags Description
options ApplicationConfig exported public optional

Interface for an Application mixed in with RepositoryMixin

component(component: Class<__type>) : void

Parameters
Name Type Default Value Flags Description
component Class<__type>

Interface for an Application mixed in with RepositoryMixin

dataSource(dataSource: DataSource, name: undefined | string) : void

Parameters
Name Type Default Value Flags Description
dataSource DataSource

Interface for an Application mixed in with RepositoryMixin

name undefined | string optional

Interface for an Application mixed in with RepositoryMixin

getRepository(repo: Class<R>) : Promise<R>

Parameters
Name Type Default Value Flags Description
repo Class<R>

Interface for an Application mixed in with RepositoryMixin

mountComponentRepository(component: Class<__type>) : void

Parameters
Name Type Default Value Flags Description
component Class<__type>

Interface for an Application mixed in with RepositoryMixin

repository(repo: Class<any>) : void

Parameters
Name Type Default Value Flags Description
repo Class<any>

Interface for an Application mixed in with RepositoryMixin

Function: RepositoryMixin

RepositoryMixin(superClass: T) :

A mixin class for Application that creates a .repository() function to register a repository automatically. Also overrides component function to allow it to register repositories automatically.


class MyApplication extends RepositoryMixin(Application) {}

Parameters
Name Type Default Value Flags Description
superClass T

Class: entity = new Entity()

Base class for entities which have unique ids

getId() : any

Get the identity value. If the identity is a composite key, returns an object.

getIdObject() : Object

Get the identity as an object, such as {id: 1} or {schoolId: 1, studentId: 2}

buildWhereForId(id: any) : any

Build the where object for the given id

Parameters
Name Type Default Value Flags Description
id any

The id value

Class: event = new Event()

Domain events

Properties
Name Type Default Value Flags Description
source any exported

Domain events

type string exported

Domain events

Class: model = new Model()

Base class for models

Properties
Name Type Default Value Flags Description
definition ModelDefinition static exported

Base class for models

modelName string static exported

Base class for models

constructor(data: Partial<Model>) : Model

Parameters
Name Type Default Value Flags Description
data Partial<Model> optional

Base class for models

toJSON() : Object

Serialize into a plain JSON object

toObject(options: Options) : Object

Convert to a plain object as DTO

Parameters
Name Type Default Value Flags Description
options Options optional

Base class for models

Class: modeldefinition = new ModelDefinition()

Definition for a model

Properties
Name Type Default Value Flags Description
name string exported

Definition for a model

properties anonymous exported

Definition for a model

settings anonymous exported

Definition for a model

constructor(nameOrDef: string | ModelDefinitionSyntax) : ModelDefinition

Parameters
Name Type Default Value Flags Description
nameOrDef string | ModelDefinitionSyntax

Definition for a model

addProperty(name: string, definitionOrType: PropertyDefinition | PropertyType) : this

Add a property

Parameters
Name Type Default Value Flags Description
name string

Definition for a model

definitionOrType PropertyDefinition | PropertyType

Definition for a model

addSetting(name: string, value: any) : this

Add a setting

Parameters
Name Type Default Value Flags Description
name string

Setting name

value any

Setting value

idProperties() : string[]

Get an array of names of ID properties, which are specified in the model settings or properties with id attribute. For example,

{
  settings: {
    id: ['id']
  }
  properties: {
    id: {
      type: 'string',
      id: true
    }
  }
}

Class: valueobject = new ValueObject()

Base class for value objects - An object that contains attributes but has no conceptual identity. They should be treated as immutable.

Interface: ModelDefinitionSyntax

DSL for building a model definition.

Properties
Name Type Default Value Flags Description
name string exported

DSL for building a model definition.

properties undefined | anonymous exported optional

DSL for building a model definition.

settings undefined | anonymous exported optional

DSL for building a model definition.

Interface: Persistable

Interface: PropertyDefinition

Property definition for a model

Properties
Name Type Default Value Flags Description
id undefined | true | false exported optional

Property definition for a model

json PropertyForm exported optional

Property definition for a model

store PropertyForm exported optional

Property definition for a model

type PropertyType exported

Property definition for a model

Interface: PropertyDefinitionMap

Interface: PropertyForm

Properties
Name Type Default Value Flags Description
in undefined | true | false exported optional
name undefined | string exported optional
out undefined | true | false exported optional

Type alias: EntityData = DataObject

Enumeration: Operators

Operators for where clauses

Members
Name Default Value Flags Description
and exported

Operators for where clauses

between exported

Operators for where clauses

eq exported

Operators for where clauses

exists exported

Operators for where clauses

gt exported

Operators for where clauses

gte exported

Operators for where clauses

inq exported

Operators for where clauses

lt exported

Operators for where clauses

lte exported

Operators for where clauses

neq exported

Operators for where clauses

or exported

Operators for where clauses

Class: filterbuilder = new FilterBuilder()

A builder for Filter. It provides fleunt APIs to add clauses such as fields, order, where, limit, offset, and include.

Properties
Name Type Default Value Flags Description
filter Filter exported

A builder for Filter. It provides fleunt APIs to add clauses such as fields, order, where, limit, offset, and include.

constructor(f: Filter) : FilterBuilder

Parameters
Name Type Default Value Flags Description
f Filter optional

A builder for Filter. It provides fleunt APIs to add clauses such as fields, order, where, limit, offset, and include.

build() : Filter

Return the filter object

fields(f: (string | string[] | Fields)[]) : this

Describe what fields to be included/excluded

Parameters
Name Type Default Value Flags Description
f (string | string[] | Fields)[] rest

A field name to be included, an array of field names to be included, or an Fields object for the inclusion/exclusion

include(i: (string | string[] | Inclusion)[]) : this

Declare include

Parameters
Name Type Default Value Flags Description
i (string | string[] | Inclusion)[] rest

A relation name, an array of relation names, or an Inclusion object for the relation/scope definitions

limit(limit: number) : this

Set limit

Parameters
Name Type Default Value Flags Description
limit number

Maximum number of records to be returned

offset(offset: number) : this

Set offset

Parameters
Name Type Default Value Flags Description
offset number

Offset of the number of records to be returned

order(o: (string | string[] | Order)[]) : this

Describe the sorting order

Parameters
Name Type Default Value Flags Description
o (string | string[] | Order)[] rest

A builder for Filter. It provides fleunt APIs to add clauses such as fields, order, where, limit, offset, and include.

skip(skip: number) : this

Alias to offset

Parameters
Name Type Default Value Flags Description
skip number

where(w: Where) : this

Declare a where clause

Parameters
Name Type Default Value Flags Description
w Where

Where object

Class: wherebuilder = new WhereBuilder()

A builder for Where object. It provides fleunt APIs to add clauses such as and, or, and other operators.

Properties
Name Type Default Value Flags Description
where Where exported

A builder for Where object. It provides fleunt APIs to add clauses such as and, or, and other operators.

constructor(w: Where) : WhereBuilder

Parameters
Name Type Default Value Flags Description
w Where optional

A builder for Where object. It provides fleunt APIs to add clauses such as and, or, and other operators.

and(w: (Where | Where[])[]) : this

Add an and clause.

Parameters
Name Type Default Value Flags Description
w (Where | Where[])[] rest

One or more where objects

between(key: string, val1: any, val2: any) : this

Add a between condition

Parameters
Name Type Default Value Flags Description
key string

Property name

val1 any

Property value lower bound

val2 any

Property value upper bound

build() : Where

Get the where object

eq(key: string, val: any) : this

Add an = condition

Parameters
Name Type Default Value Flags Description
key string

Property name

val any

Property value

exists(key: string, val: undefined | true | false) : this

Add a exists condition

Parameters
Name Type Default Value Flags Description
key string

Property name

val undefined | true | false optional

Exists or not

gt(key: string, val: any) : this

Add a > condition

Parameters
Name Type Default Value Flags Description
key string

Property name

val any

Property value

gte(key: string, val: any) : this

Add a >= condition

Parameters
Name Type Default Value Flags Description
key string

Property name

val any

Property value

inq(key: string, val: any[]) : this

Add a inq condition

Parameters
Name Type Default Value Flags Description
key string

Property name

val any[]

An array of property values

lt(key: string, val: any) : this

Add a < condition

Parameters
Name Type Default Value Flags Description
key string

Property name

val any

Property value

lte(key: string, val: any) : this

Add a <= condition

Parameters
Name Type Default Value Flags Description
key string

Property name

val any

Property value

neq(key: string, val: any) : this

Add a != condition

Parameters
Name Type Default Value Flags Description
key string

Property name

val any

Property value

or(w: (Where | Where[])[]) : this

Add an or clause.

Parameters
Name Type Default Value Flags Description
w (Where | Where[])[] rest

One or more where objects

Interface: Condition

Matching condition

Properties
Name Type Default Value Flags Description
and Where[] exported optional

Matching condition

between any[] exported optional

Matching condition

eq any exported optional

Matching condition

exists undefined | true | false exported optional

Matching condition

gt any exported optional

Matching condition

gte any exported optional

Matching condition

inq any[] exported optional

Matching condition

lt any exported optional

Matching condition

lte any exported optional

Matching condition

neq any exported optional

Matching condition

or Where[] exported optional

Matching condition

Interface: Fields

Selection of fields

Example: {afieldname: true}

Interface: Filter

Query filter object

Properties
Name Type Default Value Flags Description
fields Fields exported optional

To include/exclude fields

include Inclusion[] exported optional

To include related objects

limit undefined | number exported optional

Maximum number of entities

offset undefined | number exported optional

Offset N number of entities. An alias for skip

order string[] exported optional

Sorting order for matched entities. Each item should be formatted as fieldName ASC or fieldName DESC. For example: ['f1 ASC', 'f2 DESC', 'f3 ASC'].

We might want to use Order in the future. Keep it as string[] for now for compatibility with LoopBack 3.x.

skip undefined | number exported optional

Skip N number of entities

where Where exported optional

The matching criteria

Interface: Inclusion

Inclusion of related items

Note: scope means filter on related items

Example: {relation: 'aRelationName', scope: {<AFilterObject>}}

Properties
Name Type Default Value Flags Description
relation string exported

Inclusion of related items

Note: scope means filter on related items

Example: {relation: 'aRelationName', scope: {<AFilterObject>}}

scope Filter exported optional

Inclusion of related items

Note: scope means filter on related items

Example: {relation: 'aRelationName', scope: {<AFilterObject>}}

Interface: Order

Order by

Example: {afieldname: 'ASC'}

Interface: Where

Where object

Examples: {afieldname: 'aName'} {and: [{fieldone: 'one'}, {fieldtwo: 'two'}]} {or: [{fieldone: 'one'}, {fieldtwo: 'two'}]}

Properties
Name Type Default Value Flags Description
and Where[] exported optional

Where object

Examples: {afieldname: 'aName'} {and: [{fieldone: 'one'}, {fieldtwo: 'two'}]} {or: [{fieldone: 'one'}, {fieldtwo: 'two'}]}

or Where[] exported optional

Where object

Examples: {afieldname: 'aName'} {and: [{fieldone: 'one'}, {fieldtwo: 'two'}]} {or: [{fieldone: 'one'}, {fieldtwo: 'two'}]}

Function: filterTemplate

filterTemplate(strings: TemplateStringsArray, keys: any[]) : filter

Parameters
Name Type Default Value Flags Description
strings TemplateStringsArray
keys any[] rest

Interface: KVRepository

Key/Value operations for connector implementations

delete(key: string, options: Options) : Promise<boolean>

Delete an entry by key

Returns:

Promise if an entry is deleted for the key, otherwise Promise

Parameters
Name Type Default Value Flags Description
key string

Key for the entry

options Options optional

Options for the operation

deleteAll(options: Options) : Promise<number>

Delete all entries

Returns:

A promise of the number of entries deleted

Parameters
Name Type Default Value Flags Description
options Options optional

Options for the operation

expire(key: string, ttl: number, options: Options) : Promise<boolean>

Set up ttl for an entry by key

Returns:

Promise if an entry is set for the key, otherwise Promise

Parameters
Name Type Default Value Flags Description
key string

Key for the entry

ttl number

Key/Value operations for connector implementations

options Options optional

Options for the operation

get(key: string, options: Options) : Promise<T>

Get an entry by key

Returns:

A promise of the entry

Parameters
Name Type Default Value Flags Description
key string

Key for the entry

options Options optional

Options for the operation

iterateKeys(filter: Filter, options: Options) : Promise<Iterator<T>>

Get an Iterator for matching keys

Returns:

A promise of an iterator of entries

Parameters
Name Type Default Value Flags Description
filter Filter optional

Filter for keys

options Options optional

Options for the operation

keys(options: Options) : Promise<string[]>

Fetch all keys

Returns:

A promise of an array of keys for all entries

Parameters
Name Type Default Value Flags Description
options Options optional

Options for the operation

set(key: string, value: DataObject<T>, options: Options) : Promise<boolean>

Set an entry with key/value

Returns:

Promise if an entry is set for the key, otherwise Promise

Parameters
Name Type Default Value Flags Description
key string

Key for the entry

value DataObject<T>

Value for the entry

options Options optional

Options for the operation

ttl(key: string, ttl: number, options: Options) : Promise<number>

Get ttl for an entry by key

Returns:

A promise of the TTL value

Parameters
Name Type Default Value Flags Description
key string

Key for the entry

ttl number

Key/Value operations for connector implementations

options Options optional

Options for the operation

Class: defaultcrudrepository = new DefaultCrudRepository()

Default implementation of CRUD repository using legacy juggler model and data source

Properties
Name Type Default Value Flags Description
dataSource DataSource constructorProperty exported public

Legacy data source

entityClass constructorProperty exported public

Default implementation of CRUD repository using legacy juggler model and data source

modelClass PersistedModel exported

Default implementation of CRUD repository using legacy juggler model and data source

constructor(entityClass: , dataSource: DataSource) : DefaultCrudRepository

Constructor of DefaultCrudRepository

Parameters
Name Type Default Value Flags Description
entityClass

Constructor of DefaultCrudRepository

dataSource DataSource

Legacy data source

count(where: Where, options: Options) : Promise<number>

Parameters
Name Type Default Value Flags Description
where Where optional

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

create(entity: Partial<T>, options: Options) : Promise<T>

Parameters
Name Type Default Value Flags Description
entity Partial<T>

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

createAll(entities: Partial<T>[], options: Options) : Promise<T[]>

Parameters
Name Type Default Value Flags Description
entities Partial<T>[]

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

delete(entity: T, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
entity T

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

deleteAll(where: Where, options: Options) : Promise<number>

Parameters
Name Type Default Value Flags Description
where Where optional

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

deleteById(id: ID, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
id ID

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

execute(command: Command, parameters: NamedParameters | PositionalParameters, options: Options) : Promise<AnyObject>

Parameters
Name Type Default Value Flags Description
command Command

Default implementation of CRUD repository using legacy juggler model and data source

parameters NamedParameters | PositionalParameters

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

exists(id: ID, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
id ID

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

find(filter: Filter, options: Options) : Promise<T[]>

Parameters
Name Type Default Value Flags Description
filter Filter optional

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

findById(id: ID, filter: Filter, options: Options) : Promise<T>

Parameters
Name Type Default Value Flags Description
id ID

Default implementation of CRUD repository using legacy juggler model and data source

filter Filter optional

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

findOne(filter: Filter, options: Options) : Promise<T>

Parameters
Name Type Default Value Flags Description
filter Filter optional

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

replaceById(id: ID, data: Partial<T>, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
id ID

Default implementation of CRUD repository using legacy juggler model and data source

data Partial<T>

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

save(entity: T, options: Options) : Promise<T | null>

Parameters
Name Type Default Value Flags Description
entity T

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

update(entity: T, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
entity T

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

updateAll(data: Partial<T>, where: Where, options: Options) : Promise<number>

Parameters
Name Type Default Value Flags Description
data Partial<T>

Default implementation of CRUD repository using legacy juggler model and data source

where Where optional

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

updateById(id: ID, data: Partial<T>, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
id ID

Default implementation of CRUD repository using legacy juggler model and data source

data Partial<T>

Default implementation of CRUD repository using legacy juggler model and data source

options Options optional

Default implementation of CRUD repository using legacy juggler model and data source

const DataSourceConstructor = jugglerModule.DataSource as typeof juggler.DataSource

const ModelBaseConstructor = jugglerModule.ModelBaseClass as typeof juggler.ModelBase

const jugglerModule = require('loopback-datasource-juggler')

Function: bindModel

bindModel(modelClass: T, ds: DataSource) : T

This is a bridge to the legacy DAO class. The function mixes DAO methods into a model class and attach it to a given data source

Returns:

The new model class with DAO (CRUD) operations

Parameters
Name Type Default Value Flags Description
modelClass T

Model class

ds DataSource

Data source

Class: crudrepositoryimpl = new CrudRepositoryImpl()

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

Properties
Name Type Default Value Flags Description
dataSource DataSource constructorProperty exported public

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

model Class<T> constructorProperty exported public

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

constructor(dataSource: DataSource, model: Class<T>) : CrudRepositoryImpl

Parameters
Name Type Default Value Flags Description
dataSource DataSource

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

model Class<T>

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

count(where: Where, options: Options) : Promise<number>

Parameters
Name Type Default Value Flags Description
where Where optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

create(entity: DataObject<T>, options: Options) : Promise<T>

Parameters
Name Type Default Value Flags Description
entity DataObject<T>

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

createAll(entities: DataObject<T>[], options: Options) : Promise<T[]>

Parameters
Name Type Default Value Flags Description
entities DataObject<T>[]

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

delete(entity: DataObject<T>, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
entity DataObject<T>

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

deleteAll(where: Where, options: Options) : Promise<number>

Parameters
Name Type Default Value Flags Description
where Where optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

deleteById(id: ID, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
id ID

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

execute(command: Command, parameters: NamedParameters | PositionalParameters, options: Options) : Promise<AnyObject>

Parameters
Name Type Default Value Flags Description
command Command

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

parameters NamedParameters | PositionalParameters

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

exists(id: ID, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
id ID

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

find(filter: Filter, options: Options) : Promise<T[]>

Parameters
Name Type Default Value Flags Description
filter Filter optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

findById(id: ID, options: Options) : Promise<T>

Parameters
Name Type Default Value Flags Description
id ID

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

replaceById(id: ID, data: DataObject<T>, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
id ID

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

data DataObject<T>

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

save(entity: DataObject<T>, options: Options) : Promise<T | null>

Parameters
Name Type Default Value Flags Description
entity DataObject<T>

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

update(entity: DataObject<T>, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
entity DataObject<T>

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

updateAll(data: DataObject<T>, where: Where, options: Options) : Promise<number>

Parameters
Name Type Default Value Flags Description
data DataObject<T>

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

where Where optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

updateById(id: ID, data: DataObject<T>, options: Options) : Promise<boolean>

Parameters
Name Type Default Value Flags Description
id ID

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

data DataObject<T>

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

options Options optional

Repository implementation

Example:

User can import CrudRepositoryImpl and call its functions like: CrudRepositoryImpl.find(somefilters, someoptions)

Or extend class CrudRepositoryImpl and override its functions:

export class TestRepository extends CrudRepositoryImpl<Test> {
  constructor(dataSource: DataSource, model: Test) {
    super(dataSource, Customer);
  }

  // Override `deleteAll` to disable the operation
  deleteAll(where?: Where, options?: Options) {
    return Promise.reject(new Error('deleteAll is disabled'));
  }
}

Interface: CrudRepository

Basic CRUD operations for ValueObject and Entity. No ID is required.

count(where: Where, options: Options) : Promise<number>

Count matching records

Returns:

A promise of number of records matched

Parameters
Name Type Default Value Flags Description
where Where optional

Matching criteria

options Options optional

Options for the operations

create(dataObject: DataObject<T>, options: Options) : Promise<T>

Create a new record

Returns:

A promise of record created

Parameters
Name Type Default Value Flags Description
dataObject DataObject<T>

The data to be created

options Options optional

Options for the operations

createAll(dataObjects: DataObject<T>[], options: Options) : Promise<T[]>

Create all records

Returns:

A promise of an array of records created

Parameters
Name Type Default Value Flags Description
dataObjects DataObject<T>[]

An array of data to be created

options Options optional

Options for the operations

deleteAll(where: Where, options: Options) : Promise<number>

Delete matching records

Returns:

A promise of number of records deleted

Parameters
Name Type Default Value Flags Description
where Where optional

Matching criteria

options Options optional

Options for the operations

find(filter: Filter, options: Options) : Promise<T[]>

Find matching records

Returns:

A promise of an array of records found

Parameters
Name Type Default Value Flags Description
filter Filter optional

Query filter

options Options optional

Options for the operations

updateAll(dataObject: DataObject<T>, where: Where, options: Options) : Promise<number>

Updating matching records with attributes from the data object

Returns:

A promise of number of records updated

Parameters
Name Type Default Value Flags Description
dataObject DataObject<T>

The data to be updated

where Where optional

Matching criteria

options Options optional

Options for the operations

Interface: EntityCrudRepository

CRUD operations for a repository of entities

delete(entity: DataObject<T>, options: Options) : Promise<boolean>

Delete an entity

Returns:

Promise if the entity is deleted, otherwise Promise

Parameters
Name Type Default Value Flags Description
entity DataObject<T>

Entity to be deleted

options Options optional

Options for the operations

deleteById(id: ID, options: Options) : Promise<boolean>

Delete an entity by id

Returns:

Promise if an entity is deleted for the id, otherwise Promise

Parameters
Name Type Default Value Flags Description
id ID

Value for the entity id

options Options optional

Options for the operations

exists(id: ID, options: Options) : Promise<boolean>

Check if an entity exists for the given id

Returns:

Promise if an entity exists for the id, otherwise Promise

Parameters
Name Type Default Value Flags Description
id ID

Value for the entity id

options Options optional

Options for the operations

findById(id: ID, filter: Filter, options: Options) : Promise<T>

Find an entity by id

Returns:

A promise of an entity found for the id

Parameters
Name Type Default Value Flags Description
id ID

Value for the entity id

filter Filter optional

CRUD operations for a repository of entities

options Options optional

Options for the operations

replaceById(id: ID, data: DataObject<T>, options: Options) : Promise<boolean>

Replace an entity by id

Returns:

Promise if an entity is replaced, otherwise Promise

Parameters
Name Type Default Value Flags Description
id ID

Value for the entity id

data DataObject<T>

Data attributes to be replaced

options Options optional

Options for the operations

save(entity: DataObject<T>, options: Options) : Promise<T | null>

Save an entity. If no id is present, create a new entity

Returns:

A promise of an entity saved or null if the entity does not exist

Parameters
Name Type Default Value Flags Description
entity DataObject<T>

Entity to be saved

options Options optional

Options for the operations

update(entity: DataObject<T>, options: Options) : Promise<boolean>

Update an entity

Returns:

Promise if the entity is updated, otherwise Promise

Parameters
Name Type Default Value Flags Description
entity DataObject<T>

Entity to be updated

options Options optional

Options for the operations

updateById(id: ID, data: DataObject<T>, options: Options) : Promise<boolean>

Update an entity by id with property/value pairs in the data object

Returns:

Promise if the entity is updated, otherwise Promise

Parameters
Name Type Default Value Flags Description
id ID

Value for the entity id

data DataObject<T>

Data attributes to be updated

options Options optional

Options for the operations

Interface: EntityRepository

Base interface for a repository of entities

Interface: Repository

execute(command: Command, parameters: NamedParameters | PositionalParameters, options: Options) : Promise<AnyObject>

Execute a query with the given parameter object or an array of parameters

Parameters
Name Type Default Value Flags Description
command Command

The query string or command object

parameters NamedParameters | PositionalParameters

The object with name/value pairs or an array of parameter values

options Options optional

Options

Class: anytype = new AnyType()

Any type

Properties
Name Type Default Value Flags Description
name "any" exported

Any type

coerce(value: any) : any

Parameters
Name Type Default Value Flags Description
value any

Any type

defaultValue() : any

isCoercible(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Any type

isInstance(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Any type

serialize(value: any) : any

Parameters
Name Type Default Value Flags Description
value any

Any type

Class: arraytype = new ArrayType()

Array type, such as string[]

Properties
Name Type Default Value Flags Description
itemType Type<T> constructorProperty exported public

Array type, such as string[]

name "array" exported

Array type, such as string[]

constructor(itemType: Type<T>) : ArrayType

Parameters
Name Type Default Value Flags Description
itemType Type<T>

Array type, such as string[]

coerce(value: any) : any

Parameters
Name Type Default Value Flags Description
value any

Array type, such as string[]

defaultValue() : Array<T>

isCoercible(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Array type, such as string[]

isInstance(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Array type, such as string[]

serialize(value: Array<T> | null | undefined) : undefined | null | any[]

Parameters
Name Type Default Value Flags Description
value Array<T> | null | undefined

Array type, such as string[]

Class: booleantype = new BooleanType()

Boolean type

Properties
Name Type Default Value Flags Description
name "boolean" exported

Boolean type

coerce(value: any) : any

Parameters
Name Type Default Value Flags Description
value any

Boolean type

defaultValue() : boolean

isCoercible(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Boolean type

isInstance(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Boolean type

serialize(value: boolean | null | undefined) : undefined | null | true | false

Parameters
Name Type Default Value Flags Description
value boolean | null | undefined

Boolean type

Class: buffertype = new BufferType()

Buffer (binary) type

Properties
Name Type Default Value Flags Description
name "buffer" exported

Buffer (binary) type

coerce(value: any, options: Options) : any

Parameters
Name Type Default Value Flags Description
value any

Buffer (binary) type

options Options optional

Buffer (binary) type

defaultValue() : Buffer

isCoercible(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Buffer (binary) type

isInstance(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Buffer (binary) type

serialize(value: Buffer | null | undefined, options: Options) : undefined | null | string

Parameters
Name Type Default Value Flags Description
value Buffer | null | undefined

Buffer (binary) type

options Options optional

Buffer (binary) type

Class: datetype = new DateType()

Date type

Properties
Name Type Default Value Flags Description
name "date" exported

Date type

coerce(value: any) : any

Parameters
Name Type Default Value Flags Description
value any

Date type

defaultValue() : Date

isCoercible(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Date type

isInstance(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Date type

serialize(value: Date | null | undefined) : undefined | null | string

Parameters
Name Type Default Value Flags Description
value Date | null | undefined

Date type

const ANY = new AnyType()

const BOOLEAN = new BooleanType()

const BUFFER = new BufferType()

const DATE = new DateType()

const NUMBER = new NumberType()

const STRING = new StringType()

Class: modeltype = new ModelType()

Model type

Properties
Name Type Default Value Flags Description
modelClass Class<T> constructorProperty exported public

Model type

name string "model" exported

Model type

constructor(modelClass: Class<T>) : ModelType

Parameters
Name Type Default Value Flags Description
modelClass Class<T>

Model type

serialize(value: T | null | undefined) : undefined | null | Object

Parameters
Name Type Default Value Flags Description
value T | null | undefined

Model type

Class: numbertype = new NumberType()

Number type

Properties
Name Type Default Value Flags Description
name "number" exported

Number type

coerce(value: any) : any

Parameters
Name Type Default Value Flags Description
value any

Number type

defaultValue() : number

isCoercible(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Number type

isInstance(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Number type

serialize(value: number | null | undefined) : undefined | null | number

Parameters
Name Type Default Value Flags Description
value number | null | undefined

Number type

Class: objecttype = new ObjectType()

Object type

Properties
Name Type Default Value Flags Description
name string "object" exported

Object type

type Class<T> constructorProperty exported public

Object type

constructor(type: Class<T>) : ObjectType

Parameters
Name Type Default Value Flags Description
type Class<T>

Object type

coerce(value: any) : any

Parameters
Name Type Default Value Flags Description
value any

Object type

defaultValue() : T

isCoercible(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Object type

isInstance(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Object type

serialize(value: T | null | undefined) : any

Parameters
Name Type Default Value Flags Description
value T | null | undefined

Object type

Class: stringtype = new StringType()

String type

Properties
Name Type Default Value Flags Description
name "string" exported

String type

coerce(value: any) : string

Parameters
Name Type Default Value Flags Description
value any

String type

defaultValue() : string

isCoercible(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

String type

isInstance(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

String type

serialize(value: string | null | undefined) : undefined | null | string

Parameters
Name Type Default Value Flags Description
value string | null | undefined

String type

Interface: Type

Properties
Name Type Default Value Flags Description
name string exported

Name of the type

coerce(value: any, options: Options) : T | null | undefined

Coerce the value into this type

Returns:

Coerced value of this type

Parameters
Name Type Default Value Flags Description
value any

The value to be coerced

options Options optional

Options for coercion

defaultValue() : T | null | undefined

Generate the default value for this type

isCoercible(value: any, options: Options) : boolean

Check if the given value can be coerced into this type

Parameters
Name Type Default Value Flags Description
value any

The value to to be coerced

options Options optional

isInstance(value: any) : boolean

Test if the given value is an instance of this type

Parameters
Name Type Default Value Flags Description
value any

The value

serialize(value: T | null | undefined, options: Options) : any

Serialize a value into json

Parameters
Name Type Default Value Flags Description
value T | null | undefined

The value of this type

options Options optional

Options for serialization

Class: uniontype = new UnionType()

Union type, such as string | number

Properties
Name Type Default Value Flags Description
itemTypes Type<any>[] constructorProperty exported public

Union type, such as string | number

name "union" exported

Union type, such as string | number

constructor(itemTypes: Type<any>[]) : UnionType

Parameters
Name Type Default Value Flags Description
itemTypes Type<any>[]

Union type, such as string | number

coerce(value: any) : any

Parameters
Name Type Default Value Flags Description
value any

Union type, such as string | number

defaultValue() : any

isCoercible(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Union type, such as string | number

isInstance(value: any) : boolean

Parameters
Name Type Default Value Flags Description
value any

Union type, such as string | number

serialize(value: any) : any

Parameters
Name Type Default Value Flags Description
value any

Union type, such as string | number