mirror of
https://github.com/OMGeeky/gpt-pilot.git
synced 2026-01-06 11:19:33 +01:00
add sqlite db
This commit is contained in:
22
pilot/database/connection/postgres.py
Normal file
22
pilot/database/connection/postgres.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import psycopg2
|
||||
from peewee import PostgresqlDatabase
|
||||
from psycopg2.extensions import quote_ident
|
||||
from database.config import DB_NAME, DB_HOST, DB_PORT, DB_USER, DB_PASSWORD
|
||||
|
||||
def get_postgres_database():
|
||||
return PostgresqlDatabase(DB_NAME, user=DB_USER, password=DB_PASSWORD, host=DB_HOST, port=DB_PORT)
|
||||
|
||||
def create_postgres_database():
|
||||
conn = psycopg2.connect(
|
||||
dbname='postgres',
|
||||
user=DB_USER,
|
||||
password=DB_PASSWORD,
|
||||
host=DB_HOST,
|
||||
port=DB_PORT
|
||||
)
|
||||
conn.autocommit = True
|
||||
cursor = conn.cursor()
|
||||
safe_db_name = quote_ident(DB_NAME, conn)
|
||||
cursor.execute(f"CREATE DATABASE {safe_db_name}")
|
||||
cursor.close()
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user