Skip to content

Commit d212487

Browse files
committed
Add USE WORKSPACE Fusion command
1 parent e5bb10a commit d212487

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

singlestoredb/fusion/handlers/workspace.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,59 @@
1313
from .utils import get_workspace_manager
1414

1515

16+
class UseWorkspaceHandler(SQLHandler):
17+
"""
18+
USE WORKSPACE workspace [ with_database ];
19+
20+
# Workspace
21+
workspace = { workspace_id | workspace_name }
22+
23+
# ID of workspace
24+
workspace_id = ID '<workspace-id>'
25+
26+
# Name of workspace
27+
workspace_name = '<workspace-name>'
28+
29+
# Name of database
30+
with_database = WITH DATABASE 'database-name'
31+
32+
Description
33+
-----------
34+
Change the workspace and database in the notebook.
35+
36+
Arguments
37+
---------
38+
* ``<workspace-id>``: The ID of the workspace to delete.
39+
* ``<workspace-name>``: The name of the workspace to delete.
40+
41+
Remarks
42+
-------
43+
* Specify the ``WITH DATABASE`` clause to select a default
44+
database for the session.
45+
* This command only works in a notebook session in the
46+
Managed Service.
47+
48+
Example
49+
-------
50+
The following command sets the workspace to ``examplews`` and
51+
select 'dbname' as the default database::
52+
53+
USE WORKSPACE 'examplews' WITH DATABASE 'dbname';
54+
55+
"""
56+
def run(self, params: Dict[str, Any]) -> Optional[FusionSQLResult]:
57+
from singlestoredb.notebook import portal
58+
if params.get('with_database'):
59+
portal.connection = params['workspace']['workspace_name'], \
60+
params['with_database']
61+
else:
62+
portal.workspace = params['workspace']['workspace_name']
63+
return None
64+
65+
66+
UseWorkspaceHandler.register(overwrite=True)
67+
68+
1669
class ShowRegionsHandler(SQLHandler):
1770
"""
1871
SHOW REGIONS [ <like> ]

0 commit comments

Comments
 (0)