Support to copy project
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from .project import have_project, create_project, delete_project
|
from .project import have_project, create_project, delete_project
|
||||||
from .project import is_project_open, open_project, close_project
|
from .project import is_project_open, open_project, close_project
|
||||||
|
from .project import copy_project
|
||||||
|
|
||||||
from .operation import execute_undo as undo
|
from .operation import execute_undo as undo
|
||||||
from .operation import execute_redo as redo
|
from .operation import execute_redo as redo
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ def have_project(name: str) -> bool:
|
|||||||
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 create_project(name: 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", autocommit=True) as conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute(f"create database {name} with template = project")
|
cur.execute(f"create database {new} with template = {source}")
|
||||||
|
|
||||||
|
def create_project(name: str) -> None:
|
||||||
|
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", autocommit=True) as conn:
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ def open_project(name: str) -> None:
|
|||||||
def close_project(name: str) -> None:
|
def close_project(name: str) -> None:
|
||||||
return api.close_project(name)
|
return api.close_project(name)
|
||||||
|
|
||||||
|
def copy_project(source: str, new: str) -> None:
|
||||||
|
return api.copy_project(source, new)
|
||||||
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# operation
|
# operation
|
||||||
|
|||||||
Reference in New Issue
Block a user