mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-10-06 11:16:10 +08:00
[iso-core]: Update api for loadModels
This commit is contained in:
parent
edd49c0f4a
commit
f2a032c87c
2 changed files with 9 additions and 6 deletions
|
@ -1,12 +1,12 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function loadModels(Sequelize, sequelize, modelsPath, {schema} = {}) {
|
||||
function loadModels(Sequelize, sequelize, {modelsDir = __dirname, modelsSubPath = '', schema} = {}) {
|
||||
const db = {};
|
||||
const modelsDirectory = path.join(__dirname, modelsPath)
|
||||
for (const filename of fs.readdirSync(modelsDirectory)) {
|
||||
const fullModelsDir = path.join(modelsDir, modelsSubPath)
|
||||
for (const filename of fs.readdirSync(fullModelsDir)) {
|
||||
if (filename.endsWith('.js')) {
|
||||
let model = sequelize.import(path.join(modelsDirectory, filename));
|
||||
let model = sequelize.import(path.join(fullModelsDir, filename));
|
||||
if (schema) {
|
||||
model = model.schema(schema);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,10 @@ class LocalDatabaseConnector {
|
|||
}
|
||||
|
||||
const newSequelize = this._sequelizePoolForDatabase(`a-${accountId}`);
|
||||
const db = loadModels(Sequelize, newSequelize, 'account', {schema: `a${accountId}`})
|
||||
const db = loadModels(Sequelize, newSequelize, {
|
||||
modelsSubPath: 'account',
|
||||
schema: `a${accountId}`,
|
||||
})
|
||||
|
||||
HookTransactionLog(db, newSequelize);
|
||||
HookIncrementVersionOnSave(db, newSequelize);
|
||||
|
@ -69,7 +72,7 @@ class LocalDatabaseConnector {
|
|||
|
||||
_sequelizeForShared() {
|
||||
const sequelize = this._sequelizePoolForDatabase(`shared`);
|
||||
const db = loadModels(Sequelize, sequelize, 'shared')
|
||||
const db = loadModels(Sequelize, sequelize, {modelsSubPath: 'shared'})
|
||||
|
||||
HookAccountCRUD(db, sequelize);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue