-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
43 lines (35 loc) · 856 Bytes
/
database.py
File metadata and controls
43 lines (35 loc) · 856 Bytes
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
import sqlite3 as sqlite
DB_NAME = "Shop.db"
conn = sqlite.connect(DB_NAME)
conn.cursor().execute('''
CREATE TABLE IF NOT EXISTS user
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
password TEXT,
email TEXT,
address TEXT,
phone_number TEXT
)
''')
conn.commit()
conn.cursor().execute('''
CREATE TABLE IF NOT EXISTS ads
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
title TEXT NOT NULL UNIQUE,
description TEXT,
price DOUBLE,
date TEXT,
isActive BOOL,
buyer TEXT
)
''')
conn.commit()
class SQLite(object):
def __enter__(self):
self.conn = sqlite.connect(DB_NAME)
return self.conn.cursor()
def __exit__(self, type, value, traceback):
self.conn.commit()