Page Contents
Home > @loopback/sequelize > SequelizeCrudRepository
SequelizeCrudRepository class
Sequelize implementation of CRUD repository to be used with default loopback entities and SequelizeDataSource for SQL Databases
Signature:
export declare class SequelizeCrudRepository<T extends Entity, ID, Relations extends object = {}> implements EntityCrudRepository<T, ID, Relations>
Implements: EntityCrudRepository<T, ID, Relations>
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(entityClass, dataSource) | Constructs a new instance of the SequelizeCrudRepository class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
dataSource | SequelizeDataSource | ||
DB_SPECIFIC_SETTINGS_KEYS | readonly |
readonly [“postgresql”, “mysql”, “sqlite3”] | <p>Object keys used in models for set database specific settings. Example: In model property definition one can use postgresql dataType as float { type: 'number', postgresql: { dataType: 'float', precision: 20, scale: 4, }, } </p><p>This array of keys is used while building model definition for sequelize.</p> |
DEFAULT_ORDER_STYLE | readonly |
(not declared) | Default order filter style if only column name is specified |
defaultFnRegistry | protected |
Record<string, unknown> | <p>The alias registry for defaultFn option used in model property definition.</p><p>See: https://loopback.io/doc/en/lb4/Model.html#property-decorator</p> |
entityClass | typeof Entity & { prototype: T; } | ||
inclusionResolvers | readonly |
Map<string, InclusionResolver<T, Entity>> | |
NANO_ID_LENGTH | number | Length of the nanoid generated for defaultFn’s shortid and nanoid aliases. |
|
sequelizeModel | ModelStatic<Model<T>> | Sequelize Model Instance created from the model definition received from the entityClass |
Methods
Method | Modifiers | Description |
---|---|---|
beginTransaction(options) | ||
buildSequelizeAttributeFilter(fields) | protected |
Get Sequelize attributes filter value from fields of loopback. |
buildSequelizeIncludeFilter(inclusionFilters, sourceModel) | protected |
Build Sequelize compatible include filter |
buildSequelizeOrder(order) | protected |
<p>Get Sequelize Order filter value from loopback style order value.</p><p>It also supports passing associations in the order array to sort by nested models. Example: ["user email ASC"] .</p> |
buildSequelizeWhere(where) | protected |
Build Sequelize compatible where condition object |
count(where, options) | ||
create(entity, options) | ||
createAll(entities, options) | ||
createBelongsToAccessorFor(relationName, targetRepositoryGetter) | protected |
Function to create a belongs to accessor |
createHasManyRepositoryFactoryFor(relationName, targetRepositoryGetter) | protected |
Function to create a constrained relation repository factory |
createHasManyThroughRepositoryFactoryFor(relationName, targetRepositoryGetter, throughRepositoryGetter) | protected |
Function to create a constrained hasManyThrough relation repository factory |
createHasOneRepositoryFactoryFor(relationName, targetRepositoryGetter) | protected |
Function to create a constrained hasOne relation repository factory |
createReferencesManyAccessorFor(relationName, targetRepoGetter) | protected |
Function to create a references many accessor |
delete(entity, options) | ||
deleteAll(where, options) | ||
deleteById(id, options) | ||
excludeHiddenProps(entity) | protected |
Remove hidden properties specified in model from response body. (See: https://github.com/sourcefuse/loopback4-sequelize/issues/3) |
execute(command, parameters, options) | <p>Execute a SQL command.</p><p>**WARNING:** In general, it is always better to perform database actions through repository methods. Directly executing SQL may lead to unexpected results, corrupted data, security vulnerabilities and other issues.</p> | |
exists(id, _options) | ||
find(filter, options) | ||
findById(id, filter, options) | ||
findOne(filter, options) | ||
getDefaultFnRegistry() | protected |
|
getSequelizeModel(entityClass) | Get Sequelize Model | |
getSequelizeModelAttributes(definition) | protected |
Get Sequelize Model Attributes |
getSequelizeOperator(key) | protected |
Get Sequelize Operator |
getTableName(entityClass) | <p>This function retrieves the table name associated with a given entity class. Different loopback connectors have different conventions for picking up table names, unless the name is specified in the decorator.</p><p>The function follows the following cases to determine the table name: - It checks if the name property is specified in the decorator and uses it. (this takes precedence over all other cases) - If the dialect of the dataSource is PostgreSQL, it uses the lowercased version of the model class name. - If the dialect is MySQL or any other dialect, it uses the default model class name.</p> | |
includeReferencesIfRequested(parentEntities, parentEntityClass, inclusionFilters) | protected |
<p>Include related entities of @referencesMany relation</p><p>referencesMany relation is NOT handled by sequelizeModel.findAll as it doesn’t have any direct alternative to it, so to include relation data of referencesMany, we’re manually fetching related data requested</p> |
isInclusionAllowed(include) | protected |
Checks if the resolver of the inclusion relation is registered in the inclusionResolver of the current repository |
registerInclusionResolver(relationName, resolver) | Register an inclusion resolver for the related model name. | |
replaceById(id, data, options) | ||
save(entity, options) | ||
syncLoadedSequelizeModels(options) | Run CREATE TABLE query for the all sequelize models, Useful for quick testing | |
syncSequelizeModel(options) | Run CREATE TABLE query for the target sequelize model, Useful for quick testing | |
toEntities(models) | protected |
|
update(entity, options) | ||
updateAll(data, where, options) | ||
updateById(id, data, options) |