Last active
October 23, 2018 07:30
-
-
Save thomasstr/be025a6363634b21a24910c73f7d8137 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const connection = require('./knex/MySQL'); | |
var checkUser = conncetion.userExists("226018734496546817") | |
if (checkUser == 1) { | |
console.log("User exists"); | |
else { | |
connection.createUser({ | |
name: "Thomas Strømme", | |
id: "226018734496546817" | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const environment = process.env.ENVIRONMENT || 'development' | |
const config = require('../knexfile.js')[environment]; | |
module.exports = require('knex')(config); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
development: { | |
client: 'mysql', | |
connection: { | |
user: 'root', | |
password: '', | |
database: 'facebookdiscordrole', | |
charset: 'utf8' | |
}, | |
acquireConnectionTimeout: 4000, | |
migrations: { | |
directory: __dirname + '/knex/migrations', | |
}, | |
seeds: { | |
directory: __dirname + '/knex/seeds' | |
} | |
}, | |
production: { | |
client: 'mysql', | |
connection: { | |
database: 'facebookdiscordrole', | |
user: 'root', | |
password: '', | |
charset: 'utf8' | |
}, | |
pool: { | |
min: 2, | |
max: 10 | |
}, | |
migrations: { | |
tableName: 'knex_migrations' | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
userExists (id) { | |
// console.log(`User ${discord_id} already exists`) | |
return knex('user') | |
.count('discord_id') | |
.where('discord_id', + id) | |
.limit(1) | |
.then((rows) => { | |
if (rows.length === 0) { return 0;} | |
else { return 1 }; | |
}) | |
.catch((err) => { | |
console.log(err); | |
}) | |
.finally(() => { | |
knex.destroy(); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment