def get_tables(self) -> list: try: r = requests.get(f"{self.address}/api/table", timeout=self.timeout, headers=self.headers, gcp_auth=self.gcp_auth) except Exception as e: handle_exception(e) return parse_response(r)["tables"]
def delete_column(self, column_name: str): try: params = {"table": self.table_name, "column": column_name} r = requests.delete(f"{self.address}/api/column", params=params, timeout=self.timeout, headers=self.headers, gcp_auth=self.gcp_auth) except Exception as e: handle_exception(e) parse_response(r)
def list_columns(self) -> list: try: params = {"table": self.table_name} r = requests.get(f"{self.address}/api/column", params=params, timeout=self.timeout, headers=self.headers, gcp_auth=self.gcp_auth) except Exception as e: handle_exception(e) return parse_response(r)["columns"]
def delete_rows(self, prefix: str): try: params = {"table": self.table_name, "prefix": prefix} r = requests.delete(f"{self.address}/api/row", params=params, timeout=self.timeout, headers=self.headers, gcp_auth=self.gcp_auth) except Exception as e: handle_exception(e) parse_response(r)
def set_row(self, key: str, column_value_map: dict): try: params = {"table": self.table_name, "key": key} r = requests.post(f"{self.address}/api/row", params=params, json=column_value_map, timeout=self.timeout, headers=self.headers, gcp_auth=self.gcp_auth) except Exception as e: handle_exception(e) parse_response(r)
def list_rows(self, prefix: str = None) -> list: try: params = {"table": self.table_name} if prefix: params["prefix"] = prefix r = requests.get(f"{self.address}/api/row/list", params=params, timeout=self.timeout, headers=self.headers, gcp_auth=self.gcp_auth) except Exception as e: handle_exception(e) return parse_response(r)["rowKeys"]
def read_row(self, key: str, columns: list = None) -> dict: try: params = {"table": self.table_name, "key": key} if columns: params["columns"] = ",".join(columns) r = requests.get(f"{self.address}/api/row", params=params, timeout=self.timeout, headers=self.headers, gcp_auth=self.gcp_auth) except Exception as e: handle_exception(e) return parse_response(r)[key]
def read_rows(self, prefix: str = None, columns: list = None, limit: int = None) -> dict: try: params = {"table": self.table_name} if prefix: params["prefix"] = prefix if columns: params["columns"] = ",".join(columns) if limit: params["limit"] = limit r = requests.get(f"{self.address}/api/row", params=params, timeout=self.timeout, headers=self.headers, gcp_auth=self.gcp_auth) except Exception as e: handle_exception(e) return parse_response(r)