-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrud.py
33 lines (24 loc) · 899 Bytes
/
crud.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
"""
Complete CRUD operations
"""
#CREATE TABLE users (userID INTEGER primary key autoincrement, firstName char, lastName char, rfid INTEGER, keypad VARCHAR);
#CREATE TABLE logs (userID INTEGER, time TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
#CREATE TABLE test (text varchar);
import sqlite3
con = sqlite3.connect('door.db', check_same_thread=False)
cur = con.cursor()
def insert(data):
print(f"inserting {data} into test")
cur.execute("INSERT INTO users (firstName,lastName,rfid,keypad) VALUES (?,?,?,?)",("Bruce","Wayne",2281054330,"bats"))
con.commit()
insert("me")
def retrieve(table):
print("Listing data from:",table,'\n')
for row in cur.execute(f"SELECT * FROM {table}"):
print(row)
retrieve('users')
def delete(table):
print("Deleting data from:",table,'\n')
cur.execute(f"DELETE FROM {table} WHERE text='me'")
con.commit()
delete('test')