quillsql 0.2__tar.gz → 0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: quillsql
3
- Version: 0.2
3
+ Version: 0.3
4
4
  Summary: Quill SDK for Python.
5
5
  Home-page: https://github.com/quill-sql/quill-python
6
6
  Author: Quill
@@ -1,7 +1,6 @@
1
1
  import psycopg2
2
2
  import requests
3
3
 
4
-
5
4
  class Quill:
6
5
  def __init__(
7
6
  self,
@@ -14,28 +13,27 @@ class Quill:
14
13
 
15
14
  def query(self, org_id, data):
16
15
  metadata = data["metadata"]
17
-
16
+
18
17
  target_pool = self.main_pool
19
18
  task = metadata["task"]
20
- query = metadata["id"]
21
19
 
22
20
  headers = {"Authorization": f"Bearer {self.private_key}"}
23
21
 
24
22
  if task == "query":
25
- url = "https://quill-344421.uc.r.appspot.com/validate"
26
- headers = {
27
- "Authorization": f"Bearer {self.private_key}",
28
- }
29
- params = {
30
- "orgId": org_id,
31
- }
32
- response = requests.post(
33
- url, json={"query": query}, headers=headers, params=params
34
- )
35
- response_data = response.json()
36
- field_to_remove = response_data.get("fieldToRemove")
37
-
38
23
  try:
24
+ url = "https://quill-344421.uc.r.appspot.com/validate"
25
+ headers = {
26
+ "Authorization": f"Bearer {self.private_key}",
27
+ }
28
+ params = {
29
+ "orgId": org_id,
30
+ }
31
+ response = requests.post(
32
+ url, json={"query": metadata.get("query")}, headers=headers, params=params
33
+ )
34
+ response_data = response.json()
35
+ field_to_remove = response_data.get("fieldToRemove")
36
+
39
37
  cursor = target_pool.cursor()
40
38
  cursor.execute(response_data["query"])
41
39
  query_result = cursor.fetchall()
@@ -53,59 +51,73 @@ class Quill:
53
51
  return formatted_result
54
52
 
55
53
  except Exception as err:
56
- return {"error": True, "errorMessage": str(err)}
54
+ return {"error": str(err), "errorMessage": str(err) if err else ""}
57
55
 
58
56
  elif task == "config":
59
- response = requests.get(
60
- "https://quill-344421.uc.r.appspot.com/config",
61
- params={
62
- "orgId": org_id,
63
- "name": metadata.get("name") if metadata else None,
64
- },
65
- headers={
66
- "Authorization": f"Bearer {self.private_key}",
67
- },
68
- )
69
- dash_config = response.json()
57
+ try:
58
+ response = requests.get(
59
+ "https://quill-344421.uc.r.appspot.com/config",
60
+ params={
61
+ "orgId": org_id,
62
+ "name": metadata.get("name")
63
+ },
64
+ headers={
65
+ "Authorization": f"Bearer {self.private_key}",
66
+ },
67
+ )
68
+ dash_config = response.json()
70
69
 
71
- if dash_config["filters"]:
72
- for i, filter in enumerate(dash_config["filters"]):
73
- # run query
74
- cursor = target_pool.cursor()
75
- cursor.execute(filter["query"])
76
- rows = cursor.fetchall()
70
+ if dash_config and dash_config["filters"]:
71
+ for i, filter in enumerate(dash_config["filters"]):
72
+ # run query
73
+ cursor = target_pool.cursor()
74
+ cursor.execute(filter["query"])
75
+ rows = cursor.fetchall()
77
76
 
78
- # Update the options for each filter with the rows
79
- dash_config["filters"][i]["options"] = rows
77
+ # Update the options for each filter with the rows
78
+ dash_config["filters"][i]["options"] = rows
80
79
 
81
- return dash_config
80
+ return dash_config
81
+
82
+ except Exception as err:
83
+ return {"error": str(err), "errorMessage": str(err) if err else ""}
82
84
 
83
85
  elif task == "create":
84
- response = requests.post(
85
- "https://quill-344421.uc.r.appspot.com/item",
86
- json=metadata,
87
- params={"orgId": org_id},
88
- headers=headers,
89
- ).json()
86
+ try:
87
+ response = requests.post(
88
+ "https://quill-344421.uc.r.appspot.com/item",
89
+ json=metadata,
90
+ params={"orgId": org_id},
91
+ headers=headers,
92
+ ).json()
90
93
 
91
- return response
94
+ return response
95
+ except:
96
+ return {"error": str(err), "errorMessage": str(err) if err else ""}
92
97
 
93
98
  elif task == "item":
94
99
  try:
95
100
  resp = requests.get(
96
101
  "https://quill-344421.uc.r.appspot.com/selfhostitem",
97
- params={"id": id, "orgId": org_id},
102
+ params={"id": metadata.get("id"), "orgId": org_id},
98
103
  headers={"Authorization": f"Bearer {self.private_key}"},
99
104
  )
100
105
  resp_data = resp.json()
106
+ data_to_send = {
107
+ "query": resp_data["queryString"],
108
+ "orgId": org_id,
109
+ "filters": metadata.get("filters")
110
+ }
111
+
101
112
  response = requests.post(
102
113
  "https://quill-344421.uc.r.appspot.com/validate",
103
- json={"query": resp_data["queryString"]},
104
- params={"orgId": org_id},
105
- headers={"Authorization": f"Bearer {self.private_key}"},
114
+ json=data_to_send,
115
+ headers={"Authorization": f"Bearer {self.private_key}"}
106
116
  )
107
117
  response_data = response.json()
108
- field_to_remove = response_data["fieldToRemove"]
118
+
119
+
120
+ field_to_remove = response_data["fieldToRemove"] if response_data["fieldToRemove"] else None
109
121
 
110
122
  with target_pool.cursor() as cursor:
111
123
  cursor.execute(response_data["query"])
@@ -125,4 +137,4 @@ class Quill:
125
137
  return {**resp_data, "fields": fields, "rows": rows}
126
138
 
127
139
  except Exception as err:
128
- return {"error": str(err), "errorMessage": str(err) if err else ""}
140
+ return {"error": str(err), "errorMessage": str(err) if err else ""}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: quillsql
3
- Version: 0.2
3
+ Version: 0.3
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,2 @@
1
+ psycopg2-binary
2
+ requests
@@ -2,9 +2,9 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="quillsql",
5
- version="0.2",
5
+ version="0.3",
6
6
  packages=find_packages(),
7
- install_requires=["psycopg2", "requests"],
7
+ install_requires=["psycopg2-binary", "requests"],
8
8
  author="Quill",
9
9
  author_email="shawn@quillsql.com",
10
10
  description="Quill SDK for Python.",
@@ -1,2 +0,0 @@
1
- psycopg2
2
- requests
File without changes
File without changes
File without changes
File without changes