chore: Setup objectionjs as ORM
This commit is contained in:
20
packages/backend/knexfile.ts
Normal file
20
packages/backend/knexfile.ts
Normal 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;
|
@@ -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"
|
||||
},
|
||||
|
@@ -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 }));
|
||||
|
6
packages/backend/src/config/database.ts
Normal file
6
packages/backend/src/config/database.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import knexInstance from 'knex';
|
||||
import knexConfig from '../../knexfile';
|
||||
|
||||
const knex = knexInstance(knexConfig)
|
||||
|
||||
export default knex;
|
Reference in New Issue
Block a user