33 lines
1000 B
TypeScript
33 lines
1000 B
TypeScript
import { Guild } from "discord.js";
|
|
import { SQLCommon } from "../storage/interfaces";
|
|
import { SQLResult } from "../storage/enumerations";
|
|
|
|
export async function doesGuildExist(db: SQLCommon, guild : Guild) : Promise<boolean> {
|
|
const queryResult : Object[] = await db.getAllParameterized(
|
|
"SELECT * FROM servers WHERE server_snowflake = ?",
|
|
[guild.id]
|
|
)
|
|
|
|
return queryResult.length != 0
|
|
}
|
|
|
|
export async function insertGuild(db: SQLCommon, guild: Guild) : Promise<SQLResult> {
|
|
const alreadyExists: boolean = await doesGuildExist(db, guild)
|
|
|
|
if (alreadyExists) {
|
|
return SQLResult.ALREADYEXISTS
|
|
}
|
|
try {
|
|
await db.runParameterized(
|
|
"INSERT INTO servers VALUES (?, ?, ?)",
|
|
[guild.id, guild.name, guild.description]
|
|
)
|
|
|
|
return SQLResult.CREATED
|
|
} catch (err) {
|
|
console.log("Insert Failed")
|
|
//TODO Winston should handle this
|
|
console.log(err)
|
|
return SQLResult.FAILED
|
|
}
|
|
} |