Add host for linux
This commit is contained in:
@@ -4,13 +4,13 @@ from .connection import g_conn_dict as conn
|
|||||||
# no undo/redo
|
# no undo/redo
|
||||||
|
|
||||||
def have_project(name: str) -> bool:
|
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:
|
with conn.cursor() as cur:
|
||||||
cur.execute(f"select * from pg_database where datname = '{name}'")
|
cur.execute(f"select * from pg_database where datname = '{name}'")
|
||||||
return cur.rowcount > 0
|
return cur.rowcount > 0
|
||||||
|
|
||||||
def copy_project(source: str, new: str) -> None:
|
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:
|
with conn.cursor() as cur:
|
||||||
cur.execute(f"create database {new} with template = {source}")
|
cur.execute(f"create database {new} with template = {source}")
|
||||||
|
|
||||||
@@ -18,12 +18,12 @@ def create_project(name: str) -> None:
|
|||||||
return copy_project('project', name)
|
return copy_project('project', name)
|
||||||
|
|
||||||
def delete_project(name: str) -> None:
|
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:
|
with conn.cursor() as cur:
|
||||||
cur.execute(f"drop database {name}")
|
cur.execute(f"drop database {name}")
|
||||||
|
|
||||||
def open_project(name: str) -> None:
|
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:
|
def is_project_open(name: str) -> bool:
|
||||||
return name in conn
|
return name in conn
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ sql_drop = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
def create_template():
|
def create_template():
|
||||||
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:
|
with conn.cursor() as cur:
|
||||||
cur.execute("create database project")
|
cur.execute("create database project")
|
||||||
with pg.connect(conninfo="dbname=project") as conn:
|
with pg.connect(conninfo="dbname=project host=127.0.0.1") as conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
for sql in sql_create:
|
for sql in sql_create:
|
||||||
with open(sql, "r") as f:
|
with open(sql, "r") as f:
|
||||||
@@ -79,20 +79,20 @@ def create_template():
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
def have_template():
|
def have_template():
|
||||||
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:
|
with conn.cursor() as cur:
|
||||||
cur.execute("select * from pg_database where datname = 'project'")
|
cur.execute("select * from pg_database where datname = 'project'")
|
||||||
return cur.rowcount > 0
|
return cur.rowcount > 0
|
||||||
|
|
||||||
def delete_template():
|
def delete_template():
|
||||||
with pg.connect(conninfo="dbname=project") as conn:
|
with pg.connect(conninfo="dbname=project host=127.0.0.1") as conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
for sql in sql_drop:
|
for sql in sql_drop:
|
||||||
with open(sql, "r") as f:
|
with open(sql, "r") as f:
|
||||||
cur.execute(f.read())
|
cur.execute(f.read())
|
||||||
print(f'executed {sql}')
|
print(f'executed {sql}')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
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:
|
with conn.cursor() as cur:
|
||||||
cur.execute("drop database project")
|
cur.execute("drop database project")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user