KemoFureApi/modules/Archive/databaseController.py

32 lines
814 B
Python
Raw Normal View History

2024-12-26 22:54:55 +08:00
import os
import sqlite3
TABLE_ACCOUNTS = "accounts"
TABLE_X = "x_posts"
class DatabaseController:
def __init__(self, db_name):
self.conn = sqlite3.connect(db_name, isolation_level="DEFERRED")
self.cursor = self.conn.cursor()
def run_query(self, query):
try:
self.cursor.execute(query)
results = self.cursor.fetchall()
return results
2024-12-30 16:35:57 +08:00
except Exception as e:
print(e)
2024-12-26 22:54:55 +08:00
return None
2025-01-02 19:05:25 +08:00
def run_command(self, commnd):
try:
self.cursor.execute(commnd)
result = self.cursor.rowcount
self.conn.commit()
return result > 0
except Exception as e:
print(e)
return False
2024-12-26 22:54:55 +08:00
def close(self):
self.conn.close()