Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refact attach db to Model #5

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,34 @@ export interface CoreDBConstructorArgs {
logger?: ExLogger;
}

let _db: PGDispatcher;
export function getModel() {
let _db: PGDispatcher;

class CoreBaseModel extends Model {
static set db(value: PGDispatcher) {
if (!_db) {
_db = value;
}
}

class CoreBaseModel extends Model {
static set db(value: PGDispatcher) {
if (!_db) {
_db = value;
static get primary() {
return _db.primary;
}
}

static get primary() {
return _db.primary;
}
get primary() {
return _db.primary;
}

get primary() {
return _db.primary;
}
static get replica() {
return _db.replica;
}

static get replica() {
return _db.replica;
get replica() {
return _db.replica;
}
}

get replica() {
return _db.replica;
}
return CoreBaseModel;
}

export function initDB({
Expand Down Expand Up @@ -83,7 +87,8 @@ export function initDB({
process.on('SIGUSR1', terminate);
process.on('SIGUSR2', terminate);

_db = db;
const CoreBaseModel = getModel();
CoreBaseModel.db = db;

const helpers = {
clearDatabase: async function () {
Expand Down
Loading