definite-sdk 0.1.11__tar.gz → 0.1.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/PKG-INFO +1 -1
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/definite_sdk/sql.py +29 -15
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/pyproject.toml +1 -1
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/LICENSE +0 -0
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/README.md +0 -0
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/definite_sdk/__init__.py +0 -0
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/definite_sdk/client.py +0 -0
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/definite_sdk/dlt.py +0 -0
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/definite_sdk/integration.py +0 -0
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/definite_sdk/message.py +0 -0
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/definite_sdk/py.typed +0 -0
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/definite_sdk/secret.py +0 -0
- {definite_sdk-0.1.11 → definite_sdk-0.1.12}/definite_sdk/store.py +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any, Dict,
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
2
|
|
|
3
3
|
import requests
|
|
4
4
|
|
|
@@ -31,7 +31,9 @@ class DefiniteSqlClient:
|
|
|
31
31
|
... "timeDimensions": [{"dimension": "sales.date", "granularity": "month"}],
|
|
32
32
|
... "limit": 1000
|
|
33
33
|
... }
|
|
34
|
-
>>> result = sql_client.execute_cube_query(
|
|
34
|
+
>>> result = sql_client.execute_cube_query(
|
|
35
|
+
... cube_query, integration_id="my_cube_integration"
|
|
36
|
+
... )
|
|
35
37
|
>>> print(result)
|
|
36
38
|
"""
|
|
37
39
|
|
|
@@ -46,11 +48,7 @@ class DefiniteSqlClient:
|
|
|
46
48
|
self._api_key = api_key
|
|
47
49
|
self._sql_url = api_url + SQL_ENDPOINT
|
|
48
50
|
|
|
49
|
-
def execute(
|
|
50
|
-
self,
|
|
51
|
-
sql: str,
|
|
52
|
-
integration_id: Optional[str] = None
|
|
53
|
-
) -> Dict[str, Any]:
|
|
51
|
+
def execute(self, sql: str, integration_id: Optional[str] = None) -> Dict[str, Any]:
|
|
54
52
|
"""
|
|
55
53
|
Executes a SQL query against a database integration.
|
|
56
54
|
|
|
@@ -69,7 +67,7 @@ class DefiniteSqlClient:
|
|
|
69
67
|
>>> result = sql_client.execute("SELECT COUNT(*) FROM users")
|
|
70
68
|
>>> print(result)
|
|
71
69
|
"""
|
|
72
|
-
payload = {"sql": sql}
|
|
70
|
+
payload: Dict[str, Any] = {"sql": sql}
|
|
73
71
|
if integration_id:
|
|
74
72
|
payload["integration_id"] = integration_id
|
|
75
73
|
|
|
@@ -82,11 +80,12 @@ class DefiniteSqlClient:
|
|
|
82
80
|
return response.json()
|
|
83
81
|
|
|
84
82
|
def execute_cube_query(
|
|
85
|
-
self,
|
|
86
|
-
cube_query: Dict[str, Any],
|
|
83
|
+
self,
|
|
84
|
+
cube_query: Dict[str, Any],
|
|
87
85
|
integration_id: Optional[str] = None,
|
|
88
86
|
persist: bool = True,
|
|
89
87
|
invalidate: bool = False,
|
|
88
|
+
raw: bool = False,
|
|
90
89
|
) -> Dict[str, Any]:
|
|
91
90
|
"""
|
|
92
91
|
Executes a Cube query against a Cube integration.
|
|
@@ -97,6 +96,7 @@ class DefiniteSqlClient:
|
|
|
97
96
|
If not provided, the default integration will be used.
|
|
98
97
|
persist (bool): Whether to persist the query result to the cache.
|
|
99
98
|
invalidate (bool): Whether to invalidate the cached result.
|
|
99
|
+
raw (bool): Whether to return raw/unformatted cube results.
|
|
100
100
|
|
|
101
101
|
Returns:
|
|
102
102
|
Dict[str, Any]: The query result as returned by the API.
|
|
@@ -110,24 +110,38 @@ class DefiniteSqlClient:
|
|
|
110
110
|
... "measures": ["sales.total_amount"],
|
|
111
111
|
... "timeDimensions": [{
|
|
112
112
|
... "dimension": "sales.date",
|
|
113
|
-
... "granularity": "month"
|
|
113
|
+
... "granularity": "month",
|
|
114
114
|
... }],
|
|
115
115
|
... "limit": 1000
|
|
116
116
|
... }
|
|
117
|
-
>>> result = sql_client.execute_cube_query(
|
|
117
|
+
>>> result = sql_client.execute_cube_query(
|
|
118
|
+
... cube_query, "my_cube_integration"
|
|
119
|
+
... )
|
|
118
120
|
>>> print(result)
|
|
121
|
+
|
|
122
|
+
>>> # To get raw/unformatted results:
|
|
123
|
+
>>> raw_result = sql_client.execute_cube_query(
|
|
124
|
+
... cube_query, "my_cube_integration", raw=True
|
|
125
|
+
... )
|
|
126
|
+
>>> print(raw_result)
|
|
119
127
|
"""
|
|
120
|
-
payload = {"cube_query": cube_query}
|
|
128
|
+
payload: Dict[str, Any] = {"cube_query": cube_query}
|
|
121
129
|
if integration_id:
|
|
122
130
|
payload["integration_id"] = integration_id
|
|
123
131
|
if persist:
|
|
124
132
|
payload["persist"] = persist
|
|
125
133
|
if invalidate:
|
|
126
134
|
payload["invalidate"] = invalidate
|
|
135
|
+
|
|
136
|
+
# Build URL with query parameters
|
|
137
|
+
url = self._sql_url
|
|
138
|
+
if raw:
|
|
139
|
+
url += "?raw=true"
|
|
140
|
+
|
|
127
141
|
response = requests.post(
|
|
128
|
-
|
|
142
|
+
url,
|
|
129
143
|
json=payload,
|
|
130
144
|
headers={"Authorization": "Bearer " + self._api_key},
|
|
131
145
|
)
|
|
132
146
|
response.raise_for_status()
|
|
133
|
-
return response.json()
|
|
147
|
+
return response.json()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|