-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
37 lines (33 loc) · 870 Bytes
/
database.py
File metadata and controls
37 lines (33 loc) · 870 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
import psycopg2
import os
from dotenv import load_dotenv
load_dotenv()
def get_connection():
conn = psycopg2.connect(
host=os.getenv("DB_HOST"),
port=os.getenv("DB_PORT"),
dbname=os.getenv("DB_NAME"),
user=os.getenv("DB_USER"),
password=os.getenv("DB_PASSWORD")
)
return conn
def create_table():
conn = get_connection()
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS trips (
id SERIAL PRIMARY KEY,
destination VARCHAR(100),
days INTEGER,
people INTEGER,
budget INTEGER,
plan JSONB,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
conn.commit()
cursor.close()
conn.close()
print("Table created successfully!")
if __name__ == "__main__":
create_table()