-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
executable file
·72 lines (47 loc) · 1.65 KB
/
Copy pathbase.py
File metadata and controls
executable file
·72 lines (47 loc) · 1.65 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import aiosqlite
async def Connect():
db = await aiosqlite.connect('base.db')
sql = await db.cursor()
return db, sql
async def createTables():
db, sql = await Connect()
await sql.execute("""CREATE TABLE IF NOT EXISTS users (
user_id INTEGER,
first_name TEXT,
thread_id INTEGER
)""")
await db.commit()
await db.close()
async def isExist(user_id: int) -> bool:
db, sql = await Connect()
await sql.execute("SELECT * FROM users WHERE user_id = ?", (user_id,))
result = await sql.fetchone()
await db.close()
if result == None:
return False
else:
return True
async def insertUser(user_id: int, first_name: int, thread_id: int) -> bool:
db, sql = await Connect()
await sql.execute("INSERT INTO users VALUES (?, ?, ?)", (user_id, first_name, thread_id,))
await db.commit()
await db.close()
async def getThread(user_id: int) -> int:
db, sql = await Connect()
await sql.execute("SELECT thread_id FROM users WHERE user_id = ?", (user_id,))
result = await sql.fetchone()
await db.commit()
await db.close()
return int(result[0])
async def getUserFromThreadId(thread_id : int) -> int:
db, sql = await Connect()
await sql.execute("SELECT user_id FROM users WHERE thread_id = ?", (thread_id,))
result = await sql.fetchone()
await db.close()
return int(result[0])
async def getAllUsers() -> list:
db, sql = await Connect()
await sql.execute("SELECT * FROM users")
result = await sql.fetchall()
await db.close()
return result