-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
36 lines (28 loc) · 1.12 KB
/
database.py
File metadata and controls
36 lines (28 loc) · 1.12 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
import sqlite3
class Connector:
def __init__(self):
self.connect = sqlite3.connect('myDatabase.db')
self.cursor = self.connect.cursor()
self.create_user_table()
self.create_admin_table()
def create_user_table(self):
with self.connect:
self.cursor.execute("""CREATE TABLE IF NOT EXISTS users(
first_name TEXT,
last_name TEXT
)""")
def create_admin_table(self):
with self.connect:
self.cursor.execute("""CREATE TABLE IF NOT EXISTS users(
first_name TEXT,
last_name TEXT
)""")
def add_user(self, firstname, lastname):
with self.connect:
self.cursor.execute("""INSERT INTO users(first_name, last_name) VALUES (:first_name, :last_name)""",
{'first_name': firstname, 'last_name': lastname})
def delete_user(self,firstname):
with self.connect:
self.cursor.execute("""DELETE FROM users WHERE first_name=(:firstname)""",
{'firstname': firstname})
db = Connector()