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

Implement repository pattern #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Implement repository pattern
  • Loading branch information
illiakroshka committed Mar 21, 2024
commit fdbba91ca8020a8a582a74dec5a667dd44c178e4
29 changes: 29 additions & 0 deletions lib/repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

class Repository {
constructor(tableName, database) {
this.tableName = tableName;
this.db = database;
}
async select(where, fields = ['*']) {
return this.db.select(this.tableName, fields, where);
}

async update(data, where) {
return this.db.update(this.tableName, data, where);
}

async create(data) {
return this.db.insert(this.tableName, data);
}

async remove(data) {
return this.db.delete(this.tableName, data);
}

async query(sql, values) {
return this.db.query(sql, values);
}
}

module.exports = { Repository };