-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
37 lines (30 loc) · 888 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const environment = process.env.NODE_ENV || 'development'
const config = require('./knexfile')[environment]
const connection = require('knex')(config)
function getUsers (db = connection) {
return db('trainers').select()
}
function getUser (id, db = connection) {
return db('trainers').where('id', id).first()
}
function getTrainersPokemon (id, db = connection) {
return db('tPokemon').where('trainer_id', id)
.join('pokemonList', 'pokemonList.id', 'tPokemon.id')
.select('pokemonList.name', 'pokemonList.image')
}
function getAllPokemon(db = connection){
return db('pokemonList')
.select('pokemonList.name', 'pokemonList.image')
}
function createNewTrainer(name, db = connection){
console.log(name)
return db('trainers')
.insert({name})
}
module.exports = {
getUser: getUser,
getUsers: getUsers,
getTrainersPokemon,
getAllPokemon,
createNewTrainer
}