Skip to content

Instantly share code, notes, and snippets.

@thomasstr
Last active October 23, 2018 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasstr/be025a6363634b21a24910c73f7d8137 to your computer and use it in GitHub Desktop.
Save thomasstr/be025a6363634b21a24910c73f7d8137 to your computer and use it in GitHub Desktop.
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"
});
}
const environment = process.env.ENVIRONMENT || 'development'
const config = require('../knexfile.js')[environment];
module.exports = require('knex')(config);
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'
}
}
};
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