connect to db with knex
This commit is contained in:
parent
da1dc694f3
commit
c18951b838
6 changed files with 1329 additions and 1 deletions
8
server/data/db.js
Normal file
8
server/data/db.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
const knex = require('knex');
|
||||||
|
const knexfile = require('../knexfile');
|
||||||
|
|
||||||
|
|
||||||
|
const env = process.env.NODE_ENV || 'development';
|
||||||
|
const configOptions = knexfile[env];
|
||||||
|
|
||||||
|
module.exports = knex(configOptions);
|
37
server/knexfile.js
Normal file
37
server/knexfile.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
// Update with your config settings.
|
||||||
|
require('dotenv').config()
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
development: {
|
||||||
|
client: 'postgresql',
|
||||||
|
connection: process.env.PG_CONNECTION_STRING
|
||||||
|
},
|
||||||
|
|
||||||
|
staging: {
|
||||||
|
client: 'postgresql',
|
||||||
|
connection: process.env.PG_CONNECTION_STRING,
|
||||||
|
migrations: {
|
||||||
|
directory: './data/migrations',
|
||||||
|
},
|
||||||
|
seeds: { directory: './data/seeds' },
|
||||||
|
pool: {
|
||||||
|
min: 2,
|
||||||
|
max: 10
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
production: {
|
||||||
|
client: 'postgresql',
|
||||||
|
connection: process.env.PG_CONNECTION_STRING,
|
||||||
|
migrations: {
|
||||||
|
directory: './data/migrations',
|
||||||
|
},
|
||||||
|
seeds: { directory: './data/seeds' },
|
||||||
|
pool: {
|
||||||
|
min: 2,
|
||||||
|
max: 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
8
server/migrations/20200107214047_init.js
Normal file
8
server/migrations/20200107214047_init.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
exports.up = function(knex) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.down = function(knex) {
|
||||||
|
|
||||||
|
};
|
1269
server/package-lock.json
generated
1269
server/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,10 @@
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./bin/www"
|
"start": "node ./bin/www",
|
||||||
|
"make-migration": "./node_modules/.bin/knex migrate:make",
|
||||||
|
"migrate": "./node_modules/.bin/knex migrate:latest",
|
||||||
|
"seed": "./node_modules/.bin/knex seed:run"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
|
@ -14,6 +17,7 @@
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"express": "~4.16.1",
|
"express": "~4.16.1",
|
||||||
"http-errors": "~1.6.3",
|
"http-errors": "~1.6.3",
|
||||||
|
"knex": "^0.20.7",
|
||||||
"morgan": "~1.9.1",
|
"morgan": "~1.9.1",
|
||||||
"pg": "^7.17.0",
|
"pg": "^7.17.0",
|
||||||
"socket.io": "^2.3.0"
|
"socket.io": "^2.3.0"
|
||||||
|
|
|
@ -6,6 +6,8 @@ const path = require('path');
|
||||||
const cookieParser = require('cookie-parser');
|
const cookieParser = require('cookie-parser');
|
||||||
const logger = require('morgan');
|
const logger = require('morgan');
|
||||||
|
|
||||||
|
const db = require('./data/db');
|
||||||
|
|
||||||
const dotenv = require('dotenv');
|
const dotenv = require('dotenv');
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue