This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
uwu-me/uwume/lib/databaseMethods.py

22 lines
762 B
Python
Raw Normal View History

from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, Boolean
from os import environ
pg_pass_file = open(environ['POSTGRES_PASSWORD_FILE'])
pg_pass = pg_pass_file.readline().strip('\n')
engine = create_engine(
f"postgresql+psycopg2://{environ['POSTGRES_USER']}:{pg_pass}@{environ['POSTGRES_HOST']}:{environ['POSTGRES_PORT']}/{environ['POSTGRES_DB']}")
def initialize_database():
conn = engine.connect()
md = MetaData()
users = Table('users', md,
Column('id', Integer()),
Column('name', String(255)),
Column('pass', String(255)),
Column('count', Integer()))
try:
md.create_all(engine)
except Exception as e:
print(f'{e}')