Skip to content

Commit

Permalink
feat: add sql dev command
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev committed Oct 9, 2021
1 parent a002d5d commit a1f4968
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions commands/dev/sql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
name: 'sql',
description: 'Execute SQLite statements',

async execute(client, message, args) {
if (!client.config.developers.includes(message.author.id) || message.content.toUpperCase().includes('DROP')) {
return;
}

const [ action, ...statement ] = args;
let db;
let error;
try {
db = client.db.prepare(statement.join(' '));
} catch (err) {
error = err;
}

let result;
if (action === 'get') {
result = db?.get();
}

if (action === 'run') {
result = db?.run();
}
message.channel.send({
embeds: [{
title: 'SQL',
description: `\`\`\`js\n${result ? JSON.stringify(result) : error}\`\`\``,
color: client.config.color
}]
});
}
};

0 comments on commit a1f4968

Please sign in to comment.