feat: moved knex to new file

This commit is contained in:
원더 2021-01-09 13:07:12 +09:00
parent 12856d7993
commit 03c02c7d46
2 changed files with 15 additions and 11 deletions

12
utils/Knex.ts Normal file
View File

@ -0,0 +1,12 @@
import knex from 'knex'
export default knex({
client: 'mysql',
connection: {
host: process.env.MYSQL_HOST || 'localhost',
user: process.env.MYSQL_USER || 'root',
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE || 'discordbots',
},
debug: process.env.NODE_ENV === 'development',
})

View File

@ -1,22 +1,14 @@
import fetch from 'node-fetch'
import jwt from 'jsonwebtoken'
import fs from 'fs'
import knsexy from 'knex'
import { Bot, User } from '../types'
import knex from './Knex'
const publicPem = fs.readFileSync('./public.pem')
const privateKey = fs.readFileSync('./private.key')
export const knex = knsexy({
client: 'mysql',
connection: {
host: process.env.MYSQL_HOST || 'localhost',
user: process.env.MYSQL_USER || 'root',
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE || 'discordbots',
},
})
export async function getBot(id: string, owners = true): Promise<Bot> {
const res = await knex('bots')
.select([