-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
46 lines (40 loc) · 1.43 KB
/
db.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
34
35
36
37
38
39
40
41
42
43
44
45
46
import sqlite3
class Database:
def __init__(self, db):
self.con = sqlite3.connect(db)
self.cur = self.con.cursor()
sql = """
CREATE TABLE IF NOT EXISTS employees(
id Integer Primary Key,
name text,
age text,
doj text,
email text,
gender text,
contact text,
address text
)
"""
self.cur.execute(sql)
self.con.commit()
# Insert Function
def insert(self, name, age, doj, email, gender, contact, address):
self.cur.execute("insert into employees values (NULL,?,?,?,?,?,?,?)",
(name, age, doj, email, gender, contact, address))
self.con.commit()
# Fetch All Data from DB
def fetch(self):
self.cur.execute("SELECT * from employees")
rows = self.cur.fetchall()
# print(rows)
return rows
# Delete a Record in DB
def remove(self, id):
self.cur.execute("delete from employees where id=?", (id,))
self.con.commit()
# Update a Record in DB
def update(self, id, name, age, doj, email, gender, contact, address):
self.cur.execute(
"update employees set name=?, age=?, doj=?, email=?, gender=?, contact=?, address=? where id=?",
(name, age, doj, email, gender, contact, address, id))
self.con.commit()