chore: Setup objectionjs as ORM

This commit is contained in:
Faruk AYDIN
2021-10-05 18:39:28 +02:00
committed by Ali BARIN
parent 908f156a45
commit f032dea77e
5 changed files with 111 additions and 4 deletions

View File

@@ -0,0 +1,20 @@
import appConfig from './src/config/app';
const knexConfig = {
client: 'pg',
connection: {
host: appConfig.postgresHost,
port: appConfig.postgresPort,
user: appConfig.postgresUsername,
password: appConfig.postgresPassword,
database: appConfig.postgresDatabase,
},
migrations: {
directory: __dirname + '/db/migrations',
},
seeds: {
directory: __dirname + '/db/seeds',
}
}
export default knexConfig;

View File

@@ -8,6 +8,7 @@
"start": "node dist/index.js",
"test": "echo \"Error: run tests from root\" && exit 1",
"db:create": "ts-node ./bin/database/create.ts",
"db:migration:create": "knex migrate:make",
"db:drop": "ts-node ./bin/database/drop.ts"
},
"dependencies": {
@@ -17,7 +18,9 @@
"express": "~4.16.1",
"express-graphql": "^0.12.0",
"http-errors": "~1.6.3",
"knex": "^0.95.11",
"morgan": "^1.10.0",
"objection": "^2.2.17",
"pg": "^8.7.1",
"winston": "^3.3.3"
},

View File

@@ -7,10 +7,14 @@ import graphQLInstance from './helpers/graphql-instance';
import logger from './helpers/logger';
import morgan from './helpers/morgan';
import errorHandler from './helpers/error-handler'
import { Model } from 'objection';
const app = express();
const port = appConfig.port;
import knex from './config/database';
Model.knex(knex)
app.use(morgan);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

View File

@@ -0,0 +1,6 @@
import knexInstance from 'knex';
import knexConfig from '../../knexfile';
const knex = knexInstance(knexConfig)
export default knex;