· 6 years ago · Apr 09, 2019, 05:12 PM
1import aiosqlite
2
3
4class sqlite(object):
5 def __init__(self, connect):
6 self.file = connect
7
8 async def insert(self, what,table="data_table"):
9 async with aiosqlite.connect(self.file) as db:
10 await db.execute(f'INSERT INTO {table} {what}')
11 await db.commit()
12
13
14 async def table(self,test=0):
15 if test:
16 async with aiosqlite.connect(self.file) as db:
17 await db.execute(f'')
18 await db.commit()
19
20
21
22 async def select(self, what, table="data_table"):
23 async with aiosqlite.connect(self.file) as db:
24 await db.execute(f'SELECT FROM {table} {what}')
25 await db.commit()
26
27
28 async def insert(self, data, table="data_table"):
29 async with aiosqlite.connect(self.file) as db:
30 await db.execute(f'INSERT INTO {table} {data}')
31 await db.commit()
32
33
34 async def create_teblae(self, create: bool = True):
35 if create:
36 async with aiosqlite.connect(self.file) as db:
37
38 await db.execute(f"""
39 CREATE TABLE IF NOT EXISTS data_table (
40 id INTEGER PRIMARY KEY AUTOINCREMENT
41 );
42 """)
43 await db.commit()
44 self.table = "data_table"
45
46
47
48
49
50class State(sqlite, object):
51 def __init__(self, table,db):
52 self.table = table
53 self.file = db.file
54
55
56
57 async def crt(self, tr=1):
58 if tr:
59 async with aiosqlite.connect(self.file) as db:
60 await db.execute(f"""
61 CREATE TABLE IF NOT EXISTS state (
62 id INTEGER PRIMARY KEY AUTOINCREMENT,
63 state STRING
64 );
65 """)
66 await db.commit()
67
68 self.table = "state"
69
70 async def set(self, id, state):
71 async with aiosqlite.connect(self.file) as db:
72 await db.execute(f'INSERT INTO {self.table} {id} {state}')
73 await db.commit()
74
75
76 async def deleted(self):
77 async with aiosqlite.connect(self.file) as db:
78 await db.execute(f'INSERT INTO {self.table} ')
79 await db.commit()