1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 00:10:58 -05:00

Add raw SQL query support

This commit is contained in:
toast-ts 2024-02-08 07:36:37 +11:00
parent 3170de7ead
commit b58bcc59bb
8 changed files with 8 additions and 0 deletions

View File

@ -55,6 +55,7 @@ export class MPServerSvc {
}) })
this.model.sync(); this.model.sync();
} }
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
async fetchPlayerData(serverName:string) { async fetchPlayerData(serverName:string) {
const findServerByName = await this.model.findOne({where: {serverName: serverName}}); const findServerByName = await this.model.findOne({where: {serverName: serverName}});
if (findServerByName) return findServerByName.dataValues.playerData; if (findServerByName) return findServerByName.dataValues.playerData;

View File

@ -30,6 +30,7 @@ export class DailyMsgsSvc {
}) })
this.model.sync(); this.model.sync();
} }
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
nukeDays = async()=>await this.model.destroy({truncate: true}); nukeDays = async()=>await this.model.destroy({truncate: true});
fetchDays = async()=>await this.model.findAll(); fetchDays = async()=>await this.model.findAll();
async newDay(formattedDate:number, total:number) { async newDay(formattedDate:number, total:number) {

View File

@ -25,6 +25,7 @@ export class ProhibitedWordsSvc {
}) })
this.model.sync(); this.model.sync();
} }
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
findWord = async(word:string)=>await this.model.findByPk(word); findWord = async(word:string)=>await this.model.findByPk(word);
getAllWords = async()=>await this.model.findAll(); getAllWords = async()=>await this.model.findAll();
insertWord = async(word:string)=>await this.model.create({word: word}); insertWord = async(word:string)=>await this.model.create({word: word});

View File

@ -83,6 +83,7 @@ export class PunishmentsSvc {
}); });
this.model.sync(); this.model.sync();
} }
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
async updateReason(caseId:number, reason:string) { async updateReason(caseId:number, reason:string) {
const findCase = this.findCase(caseId); const findCase = this.findCase(caseId);
if (findCase) return this.model.update({reason: reason}, {where: {case_id: caseId}}); if (findCase) return this.model.update({reason: reason}, {where: {case_id: caseId}});

View File

@ -40,6 +40,7 @@ export class SuggestionsSvc {
}) })
this.model.sync(); this.model.sync();
} }
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
fetchById = async(id:number)=>await this.model.findByPk(id); fetchById = async(id:number)=>await this.model.findByPk(id);
updateStatus = async(id:number, status:string)=>await this.model.update({status: status}, {where: {id: id}}); updateStatus = async(id:number, status:string)=>await this.model.update({status: status}, {where: {id: id}});
create =(userid:string, description:string)=>this.model.create({userid: userid, suggestion: description, status: 'Pending'}) create =(userid:string, description:string)=>this.model.create({userid: userid, suggestion: description, status: 'Pending'})

View File

@ -50,6 +50,7 @@ export class TagSystemSvc {
}); });
this.model.sync(); this.model.sync();
} }
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
async createTag(userid:string, tagName:string, message:string, embedFlag:boolean) { async createTag(userid:string, tagName:string, message:string, embedFlag:boolean) {
CacheServer.delete('tags'); CacheServer.delete('tags');
return await this.model.create({userid: userid, tagname: tagName, message: message.replace(/\\n/g, '\n'), embedFlag: embedFlag}); return await this.model.create({userid: userid, tagname: tagName, message: message.replace(/\\n/g, '\n'), embedFlag: embedFlag});

View File

@ -57,6 +57,7 @@ export class UserLevelsSvc {
}); });
this.model.sync(); this.model.sync();
} }
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
fetchEveryone = async()=>await this.model.findAll(); fetchEveryone = async()=>await this.model.findAll();
fetchUser = async(userId:string)=>await this.model.findByPk(userId); fetchUser = async(userId:string)=>await this.model.findByPk(userId);
deleteUser = async(userId:string)=>await this.model.destroy({where: {id: userId}}); deleteUser = async(userId:string)=>await this.model.destroy({where: {id: userId}});

View File

@ -34,6 +34,7 @@ export class YouTubeChannelsSvc {
}) })
this.model.sync(); this.model.sync();
} }
query = async(pattern:string)=>await this.model.sequelize.query(pattern);
async addChannel(YTChannelID:string, DCChannelID:string, DCRole:string) { async addChannel(YTChannelID:string, DCChannelID:string, DCRole:string) {
if (await this.model.findOne({where: {ytchannel: YTChannelID}})) return false; if (await this.model.findOne({where: {ytchannel: YTChannelID}})) return false;
await this.model.create({ytchannel: YTChannelID, dcchannel: DCChannelID, dcrole: DCRole}); await this.model.create({ytchannel: YTChannelID, dcchannel: DCChannelID, dcrole: DCRole});