thanosql.resources._file
Module Contents
Classes
Service layer for file methods. |
- class thanosql.resources._file.FileService(client: thanosql._client.ThanoSQL)
Bases:
thanosql._service.ThanoSQLServiceService layer for file methods.
- list(path: str | os.PathLike) dict
Lists all files and directories under the specified path.
- Parameters:
path (str or path_like) – The path that contains the files and directories to be listed. It should begin with ‘drive/’. Regex pattern is recommended.
- Returns:
A dictionary containing the list of files and folders under the input path in the format of:
{ "data": { "matched_pathnames": [list of matched pathnames], } }
- Return type:
dict
- Raises:
ThanoSQLValueError – If path is not within the ‘drive’ directory.
- upload(path: str | os.PathLike, db_commit: bool | None = None, table: str | None = None, column: str | None = None, schema: str | None = None, dir: str | None = None, if_exists: str | None = None) dict
Uploads a file to the workspace.
- Parameters:
path (str or path_like) – The path to the local file to be uploaded to the workspace.
db_commit (bool, optional) – Whether to save the uploaded file path to a table or not.
table (str, optional) – The name of the table to save the uploaded file path in. Only relevant if db_commit is set to True.
column (str, optional) – The column name in the table where the uploaded file path will be saved in. Only relevant if db_commit is set to True.
schema (str, optional) – The schema where the table to save the uploaded file path in resides. Only relevant if db_commit is set to True and defaults to “public”.
dir (str, optional) – Path to directory under drive/ to store the uploaded file in. If the directory does not exist, it will be created by the API.
- Returns:
Dictionary containing values of “file_path”, “table_name”, “column_name”, and “schema”. “file_path” will always be returned, while the rest are only returned if db_commit is set to True. The result is in the format of:
{ "data": { "file_path": file_path, "table_name": table_name | null, "column_name": column_name | null, "schema": schema | null } }
- Return type:
dict
- Raises:
If dir is not within the ‘drive’ directory.
If the path cannot be saved to table due to integrity or data error.
- delete(path: str | os.PathLike, db_commit: bool | None = None, table: str | None = None, column: str | None = None, schema: str | None = None) dict
Deletes the specified file from the workspace.
- Parameters:
path (str or path_like) – The path to the file to be removed from the workspace.
db_commit (bool, optional) – Whether to remove the file path from a table or not.
table (str, optional) – The name of the table where the file path to be removed is in. Only relevant if db_commit is set to True.
column (str, optional) – The column name in the table where the file path to be removed is in. Only relevant if db_commit is set to True.
schema (str, optional) – The schema where the table to remove the file path from resides. Only relevant if db_commit is set to True and defaults to “public”.
- Returns:
A dictionary containing a success message in the format of:
{ "message": "string" }
- Return type:
dict
- Raises:
ThanoSQLValueError – If path is not within the ‘drive’ directory.