update schema, add db init
This commit is contained in:
+21
-21
@@ -1,32 +1,32 @@
|
||||
import sqlite3
|
||||
|
||||
#def __init__(self, path: str) -> None:
|
||||
# self.db_connection = sqlite3.connect(path)
|
||||
# cursor = self.db_connection.cursor()
|
||||
# cursor.execute('''
|
||||
# CREATE TABLE IF NOT EXISTS Tokens (
|
||||
# TOKEN TEXT PRIMARY KEY NOT NULL,
|
||||
# USER TEXT NOT NULL,
|
||||
# NAME TEXT NOT NULL
|
||||
# )
|
||||
# ''')
|
||||
#
|
||||
# cursor.execute('''
|
||||
# CREATE TABLE IF NOT EXISTS Domains (
|
||||
# DOMAIN TEXT PRIMARY KEY NOT NULL,
|
||||
# USER TEXT NOT NULL
|
||||
# )
|
||||
# ''')
|
||||
#
|
||||
# self.db_connection.commit()
|
||||
# cursor.close()
|
||||
def init_db(path: str) -> None:
|
||||
with sqlite3.connect(path) as connection:
|
||||
cursor = connection.cursor()
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS Tokens (
|
||||
TOKEN TEXT PRIMARY KEY NOT NULL,
|
||||
USERID INTEGER NOT NULL,
|
||||
NAME TEXT NOT NULL
|
||||
)
|
||||
''')
|
||||
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS Domains (
|
||||
DOMAIN TEXT PRIMARY KEY NOT NULL,
|
||||
USERID INTEGER NOT NULL
|
||||
)
|
||||
''')
|
||||
|
||||
connection.commit()
|
||||
cursor.close()
|
||||
|
||||
def check_token_domain(db_path: str, token: str, domain: str) -> bool:
|
||||
with sqlite3.connect(db_path) as connection:
|
||||
cursor = connection.cursor()
|
||||
cursor.execute('''
|
||||
SELECT COUNT(*) FROM Tokens
|
||||
JOIN Domains ON Tokens.user = Domains.user
|
||||
JOIN Domains ON Tokens.userid = Domains.userid
|
||||
WHERE token = ?
|
||||
AND domain = ?
|
||||
''', (token,domain))
|
||||
|
||||
Reference in New Issue
Block a user