예제 #1
0
    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"]
예제 #2
0
    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)
예제 #3
0
    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"]
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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"]
예제 #7
0
    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]
예제 #8
0
    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)