Coverage for mindsdb / integrations / handlers / ms_one_drive_handler / ms_one_drive_tables.py: 0%
28 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
1from io import BytesIO
2from typing import List, Text
4import pandas as pd
6from mindsdb.integrations.libs.api_handler import APIResource
7from mindsdb.integrations.utilities.sql_utils import (
8 FilterCondition,
9 SortColumn
10)
12from mindsdb.integrations.utilities.files.file_reader import FileReader
15class ListFilesTable(APIResource):
16 """
17 The table abstraction for querying the files (tables) in Microsoft OneDrive.
18 """
20 def list(
21 self,
22 conditions: List[FilterCondition] = None,
23 limit: int = None,
24 sort: List[SortColumn] = None,
25 targets: List[Text] = None,
26 **kwargs
27 ):
28 """
29 Lists the files in Microsoft OneDrive.
31 Args:
32 conditions (List[FilterCondition]): The conditions to filter the files.
33 limit (int): The maximum number of files to return.
34 sort (List[SortColumn]): The columns to sort the files by.
35 targets (List[Text]): The columns to return in the result.
37 Returns:
38 pd.DataFrame: The list of files in Microsoft OneDrive based on the specified clauses.
39 """
40 client = self.handler.connect()
41 files = client.get_all_items()
43 data = []
44 for file in files:
45 item = {
46 "name": file["name"],
47 "path": file["path"],
48 "extension": file["name"].split(".")[-1]
49 }
51 # If the 'content' column is explicitly requested, fetch the content of the file.
52 if targets and "content" in targets:
53 item["content"] = client.get_item_content(file["path"])
55 # If a SELECT * query is executed, i.e., targets is empty, set the content to None.
56 elif not targets:
57 item["content"] = None
59 data.append(item)
61 df = pd.DataFrame(data)
62 return df
64 def get_columns(self):
65 return ["name", "path", "extension", "content"]
68class FileTable(APIResource):
69 """
70 The table abstraction for querying the content of a file (table) in Microsoft OneDrive.
71 """
73 def list(self, targets: List[str] = None, table_name=None, *args, **kwargs) -> pd.DataFrame:
74 """
75 Retrieves the content of the specified file (table) in Microsoft OneDrive.
77 Args:
78 targets (List[str]): The columns to return in the result.
79 table_name (str): The name of the file (table) to retrieve.
81 Returns:
82 pd.DataFrame: The content of the specified file (table) in Microsoft OneDrive.
83 """
84 client = self.handler.connect()
86 file_content = client.get_item_content(table_name)
88 reader = FileReader(file=BytesIO(file_content), name=table_name)
90 return reader.get_page_content()