Added: Full Postgres Support
This commit is contained in:
parent
a14dd8553b
commit
6a23a47ed2
@ -1,6 +1,7 @@
|
||||
import pandas as pd
|
||||
import pprint
|
||||
import sys
|
||||
import sys
|
||||
import getpass
|
||||
sys.path.append('../learnlytics/')
|
||||
from dbmodel import *
|
||||
|
||||
@ -32,7 +33,9 @@ groups = {
|
||||
|
||||
print(df)
|
||||
#init_db('WiSe_24_25.db')
|
||||
init_postgres('postgresql://admin:admin@100.96.135.91/learnlytics')
|
||||
name = getpass.getuser()
|
||||
create_database(name)
|
||||
init_postgres(name, 'postgres.cyperpunk.de', 'dergrumpf', '1P2h3i4lon$%', 5432)
|
||||
db.drop_tables(tables)
|
||||
db.create_tables(tables)
|
||||
# Create Class
|
||||
|
@ -3,6 +3,7 @@ from .utils import (
|
||||
table_labels,
|
||||
init_local,
|
||||
init_postgres,
|
||||
create_database,
|
||||
save_as_json,
|
||||
create_from_json
|
||||
)
|
||||
|
@ -11,10 +11,13 @@ Includes:
|
||||
import sys, inspect, json
|
||||
from datetime import datetime, date
|
||||
from pathlib import Path
|
||||
from peewee import *
|
||||
from playhouse.shortcuts import model_to_dict, dict_to_model
|
||||
from playhouse.db_url import connect
|
||||
from .model import *
|
||||
|
||||
import psycopg2
|
||||
from psycopg2 import sql
|
||||
|
||||
class DateTimeEncoder(json.JSONEncoder):
|
||||
'''
|
||||
Helper Class converting datetime.datetime -> isoformated String
|
||||
@ -79,11 +82,28 @@ def init_local(name: Path | str) -> None:
|
||||
db.create_tables(tables) # Ensure tables exist
|
||||
|
||||
|
||||
def init_postgres(url: str) -> None:
|
||||
def create_database(name: str) -> None:
|
||||
config = {
|
||||
'user': 'dergrumpf',
|
||||
'password': '1P2h3i4lon$%',
|
||||
'host': 'postgres.cyperpunk.de',
|
||||
'port': 5432,
|
||||
'dbname': 'postgres'
|
||||
}
|
||||
con = psycopg2.connect(**config)
|
||||
con.autocommit = True
|
||||
cur = con.cursor()
|
||||
query = sql.SQL(f'CREATE DATABASE {name}')
|
||||
try:
|
||||
cur.execute(query)
|
||||
except psycopg2.errors.DuplicateDatabase:
|
||||
pass
|
||||
|
||||
assert isinstance(url, str), "Provided url isnt a String"
|
||||
con.close()
|
||||
|
||||
database = connect(url)
|
||||
|
||||
def init_postgres(name: str, host: str, user: str, password: str, port: int = 5432) -> None:
|
||||
database = PostgresqlDatabase(name, host=host, port=port, user=user, password=password)
|
||||
db.initialize(database)
|
||||
db.connect()
|
||||
db.create_tables(tables)
|
||||
|
@ -10,7 +10,8 @@ from gui import (
|
||||
status_bar
|
||||
)
|
||||
|
||||
from dbmodel import init_postgres
|
||||
from dbmodel import init_postgres, create_database, init_local
|
||||
import getpass
|
||||
from pathlib import Path
|
||||
|
||||
def main() -> None:
|
||||
@ -24,8 +25,10 @@ def main() -> None:
|
||||
file = str(Path.home() / "learnlytics.db")
|
||||
with open("./pickles/database_location.txt", "w") as f:
|
||||
f.write(file)
|
||||
|
||||
init_postgres('postgres://admin:admin@100.96.135.91:5432/learnlytics')
|
||||
|
||||
name = getpass.getuser()
|
||||
create_database(name)
|
||||
init_postgres(name, 'postgres.cyperpunk.de', 'dergrumpf', '1P2h3i4lon$%', 5432)
|
||||
|
||||
# Set Window Parameters
|
||||
runner_params = hello_imgui.RunnerParams()
|
||||
|
Loading…
Reference in New Issue
Block a user