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

ObjectionJS #1176

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
24 changes: 18 additions & 6 deletions modules/reports/server-ts/sql.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
34 changes: 23 additions & 11 deletions modules/upload/server-ts/sql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { knex } from '@gqlapp/database-server-ts';
import { Model } from 'objection';

interface File {
name: string;
Expand All @@ -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);
}
}