Add host for linux

This commit is contained in:
wqy
2022-09-17 18:41:10 +08:00
parent b52515b26f
commit 47e0b48025
2 changed files with 9 additions and 9 deletions

View File

@@ -4,13 +4,13 @@ from .connection import g_conn_dict as conn
# no undo/redo
def have_project(name: str) -> bool:
with pg.connect(conninfo="dbname=postgres", autocommit=True) as conn:
with pg.connect(conninfo="dbname=postgres host=127.0.0.1", autocommit=True) as conn:
with conn.cursor() as cur:
cur.execute(f"select * from pg_database where datname = '{name}'")
return cur.rowcount > 0
def copy_project(source: str, new: str) -> None:
with pg.connect(conninfo="dbname=postgres", autocommit=True) as conn:
with pg.connect(conninfo="dbname=postgres host=127.0.0.1", autocommit=True) as conn:
with conn.cursor() as cur:
cur.execute(f"create database {new} with template = {source}")
@@ -18,12 +18,12 @@ def create_project(name: str) -> None:
return copy_project('project', name)
def delete_project(name: str) -> None:
with pg.connect(conninfo="dbname=postgres", autocommit=True) as conn:
with pg.connect(conninfo="dbname=postgres host=127.0.0.1", autocommit=True) as conn:
with conn.cursor() as cur:
cur.execute(f"drop database {name}")
def open_project(name: str) -> None:
conn[name] = pg.connect(conninfo=f"dbname={name}", autocommit=True)
conn[name] = pg.connect(conninfo=f"dbname={name} host=127.0.0.1", autocommit=True)
def is_project_open(name: str) -> bool:
return name in conn