quillsql 0.5__py3-none-any.whl → 0.8__py3-none-any.whl

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.
quillsql/core.py CHANGED
@@ -13,18 +13,22 @@ class Quill:
13
13
 
14
14
  def query(self, org_id, data):
15
15
  metadata = data["metadata"]
16
+
16
17
 
17
18
  target_pool = self.main_pool
18
19
  task = metadata["task"]
20
+ print("task", task)
21
+
19
22
 
20
23
  headers = {"Authorization": f"Bearer {self.private_key}"}
21
24
 
22
25
  if task == "query":
23
26
  try:
27
+ query = metadata["query"]
24
28
 
25
29
  url = "https://quill-344421.uc.r.appspot.com/validate"
26
30
  headers = {
27
- "Authorization": f"Bearer {private_key}"
31
+ "Authorization": f"Bearer {self.private_key}"
28
32
  }
29
33
 
30
34
  data = {
@@ -41,16 +45,27 @@ class Quill:
41
45
  cursor = target_pool.cursor()
42
46
  cursor.execute(response_data["query"])
43
47
  query_result = cursor.fetchall()
44
- columns = [desc[0] for desc in cursor.description]
48
+ names = [desc[0] for desc in cursor.description]
49
+ fields = [{"name": desc[0], "dataTypeID": desc[1]} for desc in cursor.description if desc[0] != field_to_remove]
50
+ # rearrange_fields = any(field["dataTypeID"] == 1082 or field["name"] == "created_at" for field in fields)
51
+ # if rearrange_fields:
52
+ # # Sort fields so that the entry with dataTypeID = 1082 or name "created_at" is the first element
53
+ # fields.sort(key=lambda x: (x["dataTypeID"] != 1082, x["name"] != "created_at"))
54
+ # fields.sort(key=lambda x: x["dataTypeID"] != 1082)
45
55
  formatted_result = {
46
- "fields": [col for col in columns if col != field_to_remove],
47
- "rows": [dict(zip(columns, row)) for row in query_result],
56
+ "fields": fields,
57
+ "rows": [dict(zip(names, row)) for row in query_result],
48
58
  }
49
59
 
50
60
  # Remove the undesired field from the row dictionaries
51
61
  for row in formatted_result["rows"]:
52
62
  if field_to_remove in row:
53
63
  del row[field_to_remove]
64
+ row['created_at'] = row['created_at'].strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'
65
+
66
+
67
+
68
+ print('formatted result', formatted_result)
54
69
 
55
70
  return formatted_result
56
71
 
@@ -59,6 +74,7 @@ class Quill:
59
74
 
60
75
  elif task == "config":
61
76
  try:
77
+ print('here we are in config')
62
78
  response = requests.get(
63
79
  "https://quill-344421.uc.r.appspot.com/config",
64
80
  params={
@@ -71,9 +87,13 @@ class Quill:
71
87
  )
72
88
  dash_config = response.json()
73
89
 
90
+ print('common sense')
91
+
92
+
74
93
  if dash_config and dash_config["filters"]:
75
94
  for i, filter in enumerate(dash_config["filters"]):
76
95
  # run query
96
+ print('stuff', dash_config)
77
97
  cursor = target_pool.cursor()
78
98
  cursor.execute(filter["query"])
79
99
  rows = cursor.fetchall()
@@ -81,6 +101,9 @@ class Quill:
81
101
  # Update the options for each filter with the rows
82
102
  dash_config["filters"][i]["options"] = rows
83
103
 
104
+ if not dash_config:
105
+ dash_config["filters"] = []
106
+
84
107
  return dash_config
85
108
 
86
109
  except Exception as err:
@@ -88,6 +111,7 @@ class Quill:
88
111
 
89
112
  elif task == "create":
90
113
  try:
114
+ print('check create', metadata, org_id)
91
115
  response = requests.post(
92
116
  "https://quill-344421.uc.r.appspot.com/item",
93
117
  json=metadata,
@@ -96,7 +120,7 @@ class Quill:
96
120
  ).json()
97
121
 
98
122
  return response
99
- except:
123
+ except Exception as err:
100
124
  return {"error": str(err), "errorMessage": str(err) if err else ""}
101
125
 
102
126
  elif task == "item":
@@ -128,7 +152,7 @@ class Quill:
128
152
  query_result = cursor.fetchall()
129
153
  columns = [desc[0] for desc in cursor.description]
130
154
  rows = [dict(zip(columns, row)) for row in query_result]
131
- fields = [column for column in columns if column != field_to_remove]
155
+ fields = [{"name": desc[0], "dataTypeID": desc[1]} for desc in cursor.description if desc[0] != field_to_remove]
132
156
  rows = [
133
157
  {
134
158
  key: value
@@ -141,4 +165,73 @@ class Quill:
141
165
  return {**resp_data, "fields": fields, "rows": rows}
142
166
 
143
167
  except Exception as err:
144
- return {"error": str(err), "errorMessage": str(err) if err else ""}
168
+ return {"error": str(err), "errorMessage": str(err) if err else ""}
169
+
170
+ elif task == "view":
171
+ print('inside of view')
172
+ query = metadata.get("query", None)
173
+ name = metadata.get("name", None)
174
+ id = metadata.get("id", None)
175
+ deleted = metadata.get("deleted", None)
176
+ try:
177
+ if query and not deleted:
178
+ with target_pool.cursor() as cursor:
179
+ cursor.execute(query)
180
+ query_result = cursor.fetchall()
181
+ cursor.execute("select typname, oid, typarray from pg_type order by oid;")
182
+ types_query = cursor.fetchall()
183
+
184
+
185
+
186
+ if (id and deleted):
187
+ table_post = {"id": id, "deleted": deleted}
188
+ elif (id):
189
+ fields = [{"name": desc[0], "dataTypeID": desc[1]} for desc in cursor.description]
190
+ print('almost there')
191
+ table_post = {
192
+ "id": id,
193
+ "name": name,
194
+ "isVisible": True,
195
+ "viewQuery": query,
196
+ "columns": [
197
+ {
198
+ "fieldType": next((type[0] for type in types_query if field['dataTypeID'] == type[2]), None),
199
+ "name": field['name'],
200
+ "displayName": field['name'],
201
+ "isVisible": True
202
+ }
203
+ for field in fields
204
+ ]
205
+ }
206
+ else:
207
+ fields = [{"name": desc[0], "dataTypeID": desc[1]} for desc in cursor.description if desc[0]]
208
+ table_post = {
209
+ "name": name,
210
+ "isVisible": True,
211
+ "viewQuery": query,
212
+ "columns": [
213
+ {
214
+ "fieldType": next((type[0] for type in types_query if field['dataTypeID'] == type[2]), None),
215
+ "name": field['name'],
216
+ "displayName": field['name'],
217
+ "isVisible": True
218
+ }
219
+ for field in fields
220
+ ]
221
+ }
222
+
223
+ response = requests.post(
224
+ "http://localhost:8080/createtable",
225
+ json=table_post,
226
+ headers={"Authorization": f"Bearer {self.private_key}"}
227
+ )
228
+ response_data = response.json()
229
+
230
+ return response_data
231
+
232
+ except Exception as e:
233
+ print(f"An error occurred: {e}")
234
+ # Optionally, re-raise the error if you want it to be handled by an upper layer or if you want the program to exit
235
+ # raise
236
+
237
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: quillsql
3
- Version: 0.5
3
+ Version: 0.8
4
4
  Summary: Quill SDK for Python.
5
5
  Home-page: https://github.com/quill-sql/quill-python
6
6
  Author: Quill
@@ -0,0 +1,7 @@
1
+ quillsql/__init__.py,sha256=IgJnPRLx5GcenVt82mMQo0ydvXYB_-39Ft4Of5sEEGA,39
2
+ quillsql/core.py,sha256=dsEHtdi-pcVReDp1MdXMCKoFHyn4YXC4sjsGq6h-B9A,9465
3
+ quillsql-0.8.dist-info/LICENSE,sha256=f2-T2fNvArbqfNW8RwsOu2IWEwpsaRX6G-AJvLJKuzg,1068
4
+ quillsql-0.8.dist-info/METADATA,sha256=KHos9m3vUMS5cvXrJQcTxY-HHXd0_QR7BVBRKIL8iWM,320
5
+ quillsql-0.8.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
6
+ quillsql-0.8.dist-info/top_level.txt,sha256=eU2vHnVqwpYQJ3ADl1Q-DIBzbYejZRUhcMdN_4zMCz8,9
7
+ quillsql-0.8.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- quillsql/__init__.py,sha256=IgJnPRLx5GcenVt82mMQo0ydvXYB_-39Ft4Of5sEEGA,39
2
- quillsql/core.py,sha256=zcPE0LVh9n-DUvuS75kOV1ftoKiHPAlBKxdqhA1rhX4,5354
3
- quillsql-0.5.dist-info/LICENSE,sha256=f2-T2fNvArbqfNW8RwsOu2IWEwpsaRX6G-AJvLJKuzg,1068
4
- quillsql-0.5.dist-info/METADATA,sha256=uzLkAdYw-pAqzYPx6BZh66tkzVX1pnAEIsZCQp_odiw,320
5
- quillsql-0.5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
6
- quillsql-0.5.dist-info/top_level.txt,sha256=eU2vHnVqwpYQJ3ADl1Q-DIBzbYejZRUhcMdN_4zMCz8,9
7
- quillsql-0.5.dist-info/RECORD,,
File without changes