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,4 +1,4 @@
from .project import have_project, create_project, delete_project
from .project import list_project, have_project, create_project, delete_project
from .project import is_project_open, get_project_open_count, open_project, close_project
from .project import copy_project

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:

View File

@@ -116,6 +116,9 @@ def read_inp(name: str, inp: str) -> None:
# operation
############################################################
def list_project() -> list[str]:
return api.list_project()
def get_current_operation(name: str) -> int:
return api.get_current_operation(name)