-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
49 lines (43 loc) · 1016 Bytes
/
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
47
48
49
import psycopg2
from dotenv import load_dotenv
load_dotenv()
import os
conn = None
def connect():
global conn
conn = psycopg2.connect(
host=os.getenv('DB_HOST'),
user=os.getenv('DB_USER'),
password=os.getenv('DB_PASSWORD'),
database =os.getenv('DB_NAME'),
)
conn.autocommit = True
return True
def disconnect():
global conn
conn.close()
return True
def create():
cur = conn.cursor()
q = '''CREATE TABLE IF NOT EXISTS tarpusers(
id SERIAL PRIMARY KEY,
regno VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
inside VARCHAR(255) NOT NULL DEFAULT 'YES',
fine INTEGER NOT NULL DEFAULT 0,
encodings TEXT NOT NULL
)'''
cur.execute(q)
cur.close()
return True
def select(query):
cur = conn.cursor()
cur.execute(query)
rows = cur.fetchall()
cur.close()
return rows
def insert(query):
cur = conn.cursor()
cur.execute(query)
cur.close()
return True