Skip to content

Instantly share code, notes, and snippets.

@ChillFish8
Created August 16, 2020 15:58
Show Gist options
  • Save ChillFish8/2b711c209291c410faf84d148bb1a4bf to your computer and use it in GitHub Desktop.
Save ChillFish8/2b711c209291c410faf84d148bb1a4bf to your computer and use it in GitHub Desktop.
import sqlite3
from sqlite3 import Error
from datetime import datetime
print(sqlite3.version)
# Prefix Load up
class PrefixDB:
def __init__(self):
self.conn = None
self.c = None
""" Creating DB Connection """
def create_conn(self, Path):
try:
self.conn = sqlite3.connect(Path)
self.c = self.conn.cursor()
print(f"[{datetime.now().strftime('%y/%m/%d | %M:%M:%S')}] Connection Successful")
except Error as e:
print(f"[{datetime.now().strftime('%y/%m/%d | %M:%M:%S')}] An Error has occurred when creating a connection:\n {e}")
def create_table(self):
try:
self.c.execute('''CREATE TABLE prefixes (guildId text, prefix text)''')
print(f"[{datetime.now().strftime('%y/%m/%d | %M:%M:%S')}] Table Successfully made")
self.conn.commit()
except Error:
print(f"[{datetime.now().strftime('%y/%m/%d | %M:%M:%S')}] Table Already Exists, ignoring this task.")
def get_prefix(self, guildId):
self.c.execute("SELECT * FROM prefixes WHERE guildId=?", (guildId,))
Fetched = self.c.fetchall()
if len(Fetched) > 0:
return Fetched[0][1]
else:
return False
def add_prefix(self, guildId, prefix):
self.c.execute("INSERT INTO prefixes (guildId, prefix) VALUES (?, ?)", (guildId, prefix,))
self.conn.commit()
def update_prefix(self, guildId, prefix):
self.c.execute("""UPDATE prefixes
SET prefix=?
WHERE guildId=?
""", (prefix, guildId,))
self.conn.commit()
def remove_prefix(self, guildId):
self.c.execute("DELETE FROM prefixes WHERE guildId=?", (guildId,))
self.conn.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment