|
|
|
@ -18,7 +18,7 @@ abstract class Store {
|
|
|
|
|
* @param {tableName}
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
constructor(db: object, tableName?: string) {
|
|
|
|
|
public constructor(db: object, tableName?: string) {
|
|
|
|
|
this.db = db
|
|
|
|
|
this.tableName = tableName
|
|
|
|
|
}
|
|
|
|
@ -27,7 +27,7 @@ abstract class Store {
|
|
|
|
|
* create row
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
findOneById(id: integer): object {
|
|
|
|
|
public findOneById(id: integer): object {
|
|
|
|
|
return this.db
|
|
|
|
|
.query('SELECT * FROM ' + this.tableName + ' WHERE id = $id')
|
|
|
|
|
.get({
|
|
|
|
@ -39,7 +39,7 @@ abstract class Store {
|
|
|
|
|
* create row
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
create(data: object): integer {
|
|
|
|
|
public create(data: object): integer {
|
|
|
|
|
this.db
|
|
|
|
|
.query('INSERT INTO ' + this.tableName + ' (' + Object.keys(data).join(', ') + ') VALUES (' + this.prepareInsertBinding(data) + ')')
|
|
|
|
|
.run(this.prepareData(data))
|
|
|
|
@ -51,7 +51,7 @@ abstract class Store {
|
|
|
|
|
* update row
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
update(id: integer, data: object): void {
|
|
|
|
|
public update(id: integer, data: object): void {
|
|
|
|
|
this.db
|
|
|
|
|
.query('UPDATE ' + this.tableName + ' SET ' + this.prepareUpdateBinding(data) + ' WHERE id = $id')
|
|
|
|
|
.run(this.prepareData(Object.assign(data, {
|
|
|
|
@ -63,7 +63,7 @@ abstract class Store {
|
|
|
|
|
* create row
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
remove(id: integer): remove {
|
|
|
|
|
public remove(id: integer): void {
|
|
|
|
|
this.db
|
|
|
|
|
.query('DELETE FROM ' + this.tableName + ' WHERE id = $id')
|
|
|
|
|
.run({
|
|
|
|
@ -74,7 +74,7 @@ abstract class Store {
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
prepareData(data: object) {
|
|
|
|
|
protected prepareData(data: object) {
|
|
|
|
|
const results = {}
|
|
|
|
|
|
|
|
|
|
for (const key in data) {
|
|
|
|
@ -91,7 +91,7 @@ abstract class Store {
|
|
|
|
|
* @param {object} data
|
|
|
|
|
* @return {string}
|
|
|
|
|
*/
|
|
|
|
|
prepareInsertBinding(data: array) {
|
|
|
|
|
protected prepareInsertBinding(data: array) {
|
|
|
|
|
let result = []
|
|
|
|
|
|
|
|
|
|
for (const key in data) {
|
|
|
|
@ -108,7 +108,7 @@ abstract class Store {
|
|
|
|
|
* @param {object} data
|
|
|
|
|
* @return {string}
|
|
|
|
|
*/
|
|
|
|
|
prepareUpdateBinding(data: array) {
|
|
|
|
|
protected prepareUpdateBinding(data: array) {
|
|
|
|
|
let result = []
|
|
|
|
|
|
|
|
|
|
for (const key in data) {
|
|
|
|
|