connect to db with knex

This commit is contained in:
Sorrel Bri 2020-01-07 21:46:24 -08:00
parent da1dc694f3
commit c18951b838
6 changed files with 1329 additions and 1 deletions

8
server/data/db.js Normal file
View 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
View 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
}
}
};

View file

@ -0,0 +1,8 @@
exports.up = function(knex) {
};
exports.down = function(knex) {
};

1269
server/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,10 @@
"version": "0.0.0",
"private": true,
"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": {
"chai": "^4.2.0",
@ -14,6 +17,7 @@
"dotenv": "^8.2.0",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"knex": "^0.20.7",
"morgan": "~1.9.1",
"pg": "^7.17.0",
"socket.io": "^2.3.0"

View file

@ -6,6 +6,8 @@ const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const db = require('./data/db');
const dotenv = require('dotenv');
dotenv.config();