|
13 | 13 | from .utils import get_workspace_manager |
14 | 14 |
|
15 | 15 |
|
| 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 | + |
16 | 69 | class ShowRegionsHandler(SQLHandler): |
17 | 70 | """ |
18 | 71 | SHOW REGIONS [ <like> ] |
|
0 commit comments