forked from SAGIRI-kawaii/saya_plugins_collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sqlite3Manager.py
58 lines (49 loc) · 1.58 KB
/
Sqlite3Manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sqlite3
import os
class Sqlite3Manager:
__instance = None
__first_init: bool = False
path: str = None
__conn = None
def __new__(cls):
if not cls.__instance:
cls.__instance = object.__new__(cls)
return cls.__instance
def __init__(self):
if not self.__first_init:
self.path = os.getcwd()
self.__conn = sqlite3.connect(self.path + './modules/KeywordDetection/keywordDetection.db')
cur = self.__conn.cursor()
cur.execute(
"""CREATE TABLE IF NOT EXISTS `keywords` (
`keyword` TEXT PRIMARY KEY
)"""
)
cur.execute(
"""CREATE TABLE IF NOT EXISTS `setting` (
`groupId` INT PRIMARY KEY,
`switch` INT NOT NULL DEFAULT 0
)"""
)
self.__conn.commit()
Sqlite3Manager.__first_init = True
else:
raise ValueError("Sqlite3Manager already initialized!")
@classmethod
def get_instance(cls):
if cls.__instance:
return cls.__instance
else:
raise ValueError("Sqlite3Manager not initialized!")
@classmethod
def get_connection(cls):
if cls.__conn:
return cls.__conn
else:
raise ValueError("Sqlite3Manager not initialized!")
def get_conn(self):
if self.__conn:
return self.__conn
else:
raise ValueError("Sqlite3Manager not initialized!")
manager = Sqlite3Manager()