· 6 years ago · Aug 12, 2019, 09:16 PM
1import aiosqlite
2
3
4class sqlite(object):
5 def __init__(self, connect):
6
7 self.file = connect
8
9 async def table_contact(self) -> None:
10 async with aiosqlite.connect(self.file) as db:
11 await db.execute(f"""
12 CREATE TABLE IF NOT EXISTS CONTACT_TABLE(
13 id INTEGER PRIMARY KEY AUTOINCREMENT,
14 USERNAME CHAR
15 );
16 """)
17 await db.commit()
18
19 async def insert(self, what, table="data_table") -> None:
20 async with aiosqlite.connect(self.file) as db:
21 await db.execute(f'INSERT INTO {table} {what};')
22 await db.commit()
23
24 async def table(self, test=0) -> None:
25 if test:
26 async with aiosqlite.connect(self.file) as db:
27 await db.execute(f'')
28 await db.commit()
29
30 async def select(self, what, table="data_table") -> None:
31 async with aiosqlite.connect(self.file) as db:
32 await db.execute(f'SELECT FROM {table} {what};')
33 await db.commit()
34
35 async def insert(self, data: str, colums: str=None, table="data_table") -> None:
36 async with aiosqlite.connect(self.file) as db:
37 if colums is None:
38 await db.execute(f"""INSERT INTO {table} VALUES("{data}");""")
39 await db.commit()
40 else:
41 await db.execute(f"""INSERT INTO {table}({colums}) VALUES("{data}");""")
42 await db.commit()
43
44
45 async def create_teblae(self, create: bool = True) -> None:
46 if create:
47 async with aiosqlite.connect(self.file) as db:
48 await db.execute(f"""
49 CREATE TABLE IF NOT EXISTS data_table (
50 id INTEGER PRIMARY KEY AUTOINCREMENT
51 );
52 """)
53 await db.commit()
54
55 async def get_lang(self) -> str:
56 data = []
57 async with aiosqlite.connect(self.file) as db:
58 async with db.execute('SELECT lang FROM lang_table;') as cursor:
59 row = await cursor.fetchone()
60 for i in row:
61 data.append(i)
62 return data
63
64
65
66
67 async def create_teblae_lang(self) -> None:
68 async with aiosqlite.connect(self.file) as db:
69 await db.execute(f"""
70 CREATE TABLE IF NOT EXISTS lang_table (
71 id INTEGER PRIMARY KEY AUTOINCREMENT,
72 lang String
73 );
74 """)