Fix bug 366 (#764)
* Optimize DB * Clean up names * fixup! Clean up names * fixup! fixup! Clean up names
This commit is contained in:
parent
b4de9c23eb
commit
542be2c1e9
175 changed files with 8503 additions and 5587 deletions
46
backend/shared/database/BaseRepository.js
Normal file
46
backend/shared/database/BaseRepository.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* Base repository class providing common data access methods.
|
||||
* Extend this class to create entity-specific repositories.
|
||||
*/
|
||||
class BaseRepository {
|
||||
constructor(model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
async findById(id, options = {}) {
|
||||
return this.model.findByPk(id, options);
|
||||
}
|
||||
|
||||
async findOne(where, options = {}) {
|
||||
return this.model.findOne({ where, ...options });
|
||||
}
|
||||
|
||||
async findAll(where = {}, options = {}) {
|
||||
return this.model.findAll({ where, ...options });
|
||||
}
|
||||
|
||||
async create(data, options = {}) {
|
||||
return this.model.create(data, options);
|
||||
}
|
||||
|
||||
async update(instance, data, options = {}) {
|
||||
return instance.update(data, options);
|
||||
}
|
||||
|
||||
async destroy(instance, options = {}) {
|
||||
return instance.destroy(options);
|
||||
}
|
||||
|
||||
async count(where = {}, options = {}) {
|
||||
return this.model.count({ where, ...options });
|
||||
}
|
||||
|
||||
async exists(where) {
|
||||
const count = await this.count(where);
|
||||
return count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseRepository;
|
||||
Loading…
Add table
Add a link
Reference in a new issue