Support to list project

This commit is contained in:
WQY\qiong
2022-10-30 23:05:34 +08:00
parent 23ce9d73d0
commit e8abbef5a6
3 changed files with 13 additions and 1 deletions

View File

@@ -1,10 +1,19 @@
import psycopg as pg
from psycopg.rows import dict_row
from .connection import g_conn_dict as conn
# no undo/redo
_project_open_count: dict[str, int] = {}
def list_project() -> list[str]:
ps = []
with pg.connect(conninfo="dbname=postgres host=127.0.0.1", autocommit=True) as conn:
with conn.cursor(row_factory=dict_row) as cur:
for p in cur.execute(f"select datname from pg_database where datname <> 'postgres' and datname <> 'template0' and datname <> 'template1' and datname <> 'project'"):
ps.append(p['datname'])
return ps
def have_project(name: str) -> bool:
with pg.connect(conninfo="dbname=postgres host=127.0.0.1", autocommit=True) as conn:
with conn.cursor() as cur: