-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
35 lines (27 loc) · 1.02 KB
/
models.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
import sqlite3 as sql
from os import path
ROOT = path.dirname(path.relpath(__file__))
def create_passenger(name, age, sex, pclass, fare, survived):
connection = sql.connect(path.join(ROOT, 'database.db'))
cur = connection.cursor()
cur.execute('insert into passengers (name, age, sex, pclass, fare, survived) values (?,?,?,?,?,?)', (name, age, sex, pclass, fare, survived))
connection.commit()
connection.close()
def get_passengers():
connection = sql.connect(path.join(ROOT, 'database.db'))
cur = connection.cursor()
cur.execute('select * from passengers')
passengers = cur.fetchall()
return passengers
def delete_passenger(id):
connection = sql.connect(path.join(ROOT, 'database.db'))
cur = connection.cursor()
cur.execute("delete from passengers where id=?", (id,), )
connection.commit()
connection.close()
def delete_all_passengers():
connection = sql.connect(path.join(ROOT, 'database.db'))
cur = connection.cursor()
cur.execute('DELETE FROM passengers')
connection.commit()
connection.close()