From cec202a8549cd63c7eaf12c32d73c6e5c8ddf992 Mon Sep 17 00:00:00 2001 From: Mithilesh Kohale Date: Thu, 19 Dec 2019 03:31:10 +0530 Subject: [PATCH 1/2] Converted Upload module to use ObjectionJS --- modules/upload/server-ts/sql.ts | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/modules/upload/server-ts/sql.ts b/modules/upload/server-ts/sql.ts index 5257e2967f..167a6c6b48 100644 --- a/modules/upload/server-ts/sql.ts +++ b/modules/upload/server-ts/sql.ts @@ -1,4 +1,4 @@ -import { knex } from '@gqlapp/database-server-ts'; +import { Model } from 'objection'; interface File { name: string; @@ -7,25 +7,37 @@ interface File { size: number; } -export default class Upload { +// Upload model. +export default class Upload extends Model { + static get jsonSchema() { + return { + type: 'object', + + properties: { + id: { type: 'integer' }, + name: { type: 'string' }, + type: { type: 'string' }, + path: { type: 'string' }, + size: { type: 'integer' } + } + }; + } + + public static tableName = 'upload'; + public files() { - return knex('upload').select('*'); + return Upload.query(); } public file(id: number) { - return knex('upload') - .select('*') - .where({ id }) - .first(); + return Upload.query().findById(id); } public saveFiles(files: [File]) { - return knex('upload').insert(files); + return Upload.query().insertGraph(files); } public deleteFile(id: number) { - return knex('upload') - .where({ id }) - .del(); + return Upload.query().deleteById(id); } } From 0e2fab8d1ccbe677dcf53a9c9b92351a2de5b830 Mon Sep 17 00:00:00 2001 From: Mithilesh Kohale Date: Thu, 19 Dec 2019 03:38:04 +0530 Subject: [PATCH 2/2] Converted Reports module to use ObjectionJS --- modules/reports/server-ts/sql.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/reports/server-ts/sql.ts b/modules/reports/server-ts/sql.ts index 73846b24c2..6a9165b60d 100644 --- a/modules/reports/server-ts/sql.ts +++ b/modules/reports/server-ts/sql.ts @@ -1,10 +1,22 @@ -import { knex } from '@gqlapp/database-server-ts'; +import { Model } from 'objection'; + +export default class ContactsDAO extends Model { + static get jsonSchema() { + return { + type: 'object', + + properties: { + id: { type: 'integer' }, + name: { type: 'string' }, + phone: { type: 'string' }, + email: { type: 'string' } + } + }; + } + + public static tableName = 'report'; -export default class ContactsDAO { public getContacts() { - return knex - .select('id', 'name', 'phone', 'email') - .from('report') - .orderBy('id', 'asc'); + return ContactsDAO.query(); } }