Spaces:
Running
Running
liquidcarbon
commited on
Commit
•
55a58f8
1
Parent(s):
f469b00
10K 1MB limit
Browse files- history.json +1 -1
- main.py +13 -7
- sql.py +5 -1
history.json
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
{"id": "01HWDNFA8QB96PV3RQCEPSG3C2", "q": "SELECT 42 AS answer", "alias": "example1", "template": "SELECT {x} AS {colname}", "definitions": "# Define variables: one '=' per line\nx=42\ncolname='answer'", "kwargs": {"x": 42, "colname": "answer"}, "rows": 1, "cols": 1, "source_id": null, "start": "2024-04-26 16:58:09.479", "end": "2024-04-26 16:58:09.479"}
|
2 |
{"id": "01HWDNFA8QTEA1Y1V229501RMF", "q": "SELECT\n Symbol,\n Number,\n Mass,\n Abundance\nFROM 'https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv'", "alias": "example2", "template": "SELECT\n Symbol,\n Number,\n Mass,\n Abundance\nFROM '{url}'", "definitions": "url = https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv", "kwargs": {"url": "https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv"}, "rows": 354, "cols": 4, "source_id": null, "start": "2024-04-26 16:58:13.425", "end": "2024-04-26 16:58:13.725"}
|
3 |
-
{"id": "01HWE3CN3BPK6S4XT9B7H3GMSA", "q": "SELECT *\nFROM 'history.json'\nORDER BY id DESC", "alias": "example3", "template": "SELECT *\nFROM 'history.json'\nORDER BY id DESC", "kwargs": {}, "definitions": "", "rows": 2, "cols": 11, "source_id": null, "start": "2024-04-26 21:01:13.707", "end": "2024-04-26 21:01:13.709"}
|
4 |
{"id": "01HWK493FKWHNGN8PTZJ4JCVZT", "q": "SELECT nothing", "alias": "bad_example", "template": "SELECT nothing", "kwargs": {}, "definitions": "", "rows": null, "cols": null, "source_id": null, "start": "2024-04-28 19:53:11.444", "end": "2024-04-28 19:53:11.444"}
|
|
|
1 |
{"id": "01HWDNFA8QB96PV3RQCEPSG3C2", "q": "SELECT 42 AS answer", "alias": "example1", "template": "SELECT {x} AS {colname}", "definitions": "# Define variables: one '=' per line\nx=42\ncolname='answer'", "kwargs": {"x": 42, "colname": "answer"}, "rows": 1, "cols": 1, "source_id": null, "start": "2024-04-26 16:58:09.479", "end": "2024-04-26 16:58:09.479"}
|
2 |
{"id": "01HWDNFA8QTEA1Y1V229501RMF", "q": "SELECT\n Symbol,\n Number,\n Mass,\n Abundance\nFROM 'https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv'", "alias": "example2", "template": "SELECT\n Symbol,\n Number,\n Mass,\n Abundance\nFROM '{url}'", "definitions": "url = https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv", "kwargs": {"url": "https://raw.githubusercontent.com/ekwan/cctk/master/cctk/data/isotopes.csv"}, "rows": 354, "cols": 4, "source_id": null, "start": "2024-04-26 16:58:13.425", "end": "2024-04-26 16:58:13.725"}
|
3 |
+
{"id": "01HWE3CN3BPK6S4XT9B7H3GMSA", "q": "SELECT *\nFROM 'history.json'\nWHERE start IS NOT NULL\nORDER BY id DESC", "alias": "example3", "template": "SELECT *\nFROM 'history.json'\nWHERE start IS NOT NULL\nORDER BY id DESC", "kwargs": {}, "definitions": "", "rows": 2, "cols": 11, "source_id": null, "start": "2024-04-26 21:01:13.707", "end": "2024-04-26 21:01:13.709"}
|
4 |
{"id": "01HWK493FKWHNGN8PTZJ4JCVZT", "q": "SELECT nothing", "alias": "bad_example", "template": "SELECT nothing", "kwargs": {}, "definitions": "", "rows": null, "cols": null, "source_id": null, "start": "2024-04-28 19:53:11.444", "end": "2024-04-28 19:53:11.444"}
|
main.py
CHANGED
@@ -17,6 +17,7 @@ from sql import Q
|
|
17 |
from itables import options as itoptions, to_html_datatable
|
18 |
itoptions.classes = "display compact cell-border"
|
19 |
itoptions.column_filters = "footer"
|
|
|
20 |
itoptions.layout = {
|
21 |
"top": {
|
22 |
"buttons": ["copyHtml5", "csvHtml5", "pageLength"],
|
@@ -56,6 +57,11 @@ RESULT_TEMPLATE = f"""
|
|
56 |
<hr><h3>Formatted query:</h3>
|
57 |
<pre>{{q}}</pre>
|
58 |
<hr>ran at {{ran}}</h3>
|
|
|
|
|
|
|
|
|
|
|
59 |
</body>
|
60 |
</html>
|
61 |
"""
|
@@ -134,19 +140,19 @@ with gr.Blocks(
|
|
134 |
css=CSS,
|
135 |
) as gradio_sql_interface:
|
136 |
with gr.Row():
|
137 |
-
with gr.Column(scale=2, min_width=
|
138 |
caption1 = gr.Markdown("# SQL Editor\nClick buttons below to see examples")
|
139 |
-
with gr.Row():
|
140 |
-
ex1_button = gr.Button("Variables", link="/?alias=example1")
|
141 |
-
ex2_button = gr.Button("URL", link="/?alias=example2")
|
142 |
-
ex3_button = gr.Button("Local File", link="/?alias=example3")
|
143 |
-
ex4_button = gr.Button("Bad Query", link="/?alias=bad_example")
|
144 |
definitions = gr.Code(label="Definitions", lines=2, interactive=True)
|
145 |
sql_input = gr.Code(label="SQL Query", language="sql", lines=25, interactive=True)
|
146 |
run_button = gr.Button("run", variant="primary")
|
147 |
editor_url = gr.Code(label="Share Editor URL", lines=1)
|
148 |
result_url = gr.Code(label="Share Query Results URL", lines=1)
|
149 |
-
with gr.Column(scale=3, min_width=
|
150 |
caption2 = gr.Markdown("# RESULTS")
|
151 |
result = gr.HTML(elem_classes="block")
|
152 |
|
|
|
17 |
from itables import options as itoptions, to_html_datatable
|
18 |
itoptions.classes = "display compact cell-border"
|
19 |
itoptions.column_filters = "footer"
|
20 |
+
itoptions.maxBytes = 2**20
|
21 |
itoptions.layout = {
|
22 |
"top": {
|
23 |
"buttons": ["copyHtml5", "csvHtml5", "pageLength"],
|
|
|
57 |
<hr><h3>Formatted query:</h3>
|
58 |
<pre>{{q}}</pre>
|
59 |
<hr>ran at {{ran}}</h3>
|
60 |
+
<hr>
|
61 |
+
<footer>
|
62 |
+
<p>this demo returns a maximum of 10K rows or 1MB of data</p>
|
63 |
+
<p><a href="https://www.linkedin.com/in/alekis/">like / comment / get in touch</a></p>
|
64 |
+
</footer>
|
65 |
</body>
|
66 |
</html>
|
67 |
"""
|
|
|
140 |
css=CSS,
|
141 |
) as gradio_sql_interface:
|
142 |
with gr.Row():
|
143 |
+
with gr.Column(scale=2, min_width=480):
|
144 |
caption1 = gr.Markdown("# SQL Editor\nClick buttons below to see examples")
|
145 |
+
with gr.Row(variant="compact"):
|
146 |
+
ex1_button = gr.Button("Variables", link="/?alias=example1", min_width=100)
|
147 |
+
ex2_button = gr.Button("URL", link="/?alias=example2", min_width=100)
|
148 |
+
ex3_button = gr.Button("Local File", link="/?alias=example3", min_width=100)
|
149 |
+
ex4_button = gr.Button("Bad Query", link="/?alias=bad_example", min_width=100)
|
150 |
definitions = gr.Code(label="Definitions", lines=2, interactive=True)
|
151 |
sql_input = gr.Code(label="SQL Query", language="sql", lines=25, interactive=True)
|
152 |
run_button = gr.Button("run", variant="primary")
|
153 |
editor_url = gr.Code(label="Share Editor URL", lines=1)
|
154 |
result_url = gr.Code(label="Share Query Results URL", lines=1)
|
155 |
+
with gr.Column(scale=3, min_width=540):
|
156 |
caption2 = gr.Markdown("# RESULTS")
|
157 |
result = gr.HTML(elem_classes="block")
|
158 |
|
sql.py
CHANGED
@@ -7,6 +7,7 @@ import textwrap
|
|
7 |
from ulid import ULID
|
8 |
|
9 |
HISTORY_FILE = "history.json"
|
|
|
10 |
|
11 |
class SQLError(Exception):
|
12 |
pass
|
@@ -61,7 +62,10 @@ class Q(str):
|
|
61 |
self.save()
|
62 |
|
63 |
def run_duckdb(self):
|
64 |
-
|
|
|
|
|
|
|
65 |
|
66 |
def df(self, sql_engine=None, save=False, _raise=False):
|
67 |
res = self.run(sql_engine=sql_engine, save=save, _raise=_raise)
|
|
|
7 |
from ulid import ULID
|
8 |
|
9 |
HISTORY_FILE = "history.json"
|
10 |
+
MAX_ROWS = 10000
|
11 |
|
12 |
class SQLError(Exception):
|
13 |
pass
|
|
|
62 |
self.save()
|
63 |
|
64 |
def run_duckdb(self):
|
65 |
+
if MAX_ROWS:
|
66 |
+
return duckdb.sql(f"WITH x AS ({self}) SELECT * FROM x LIMIT {MAX_ROWS}")
|
67 |
+
else:
|
68 |
+
return duckdb.sql(self)
|
69 |
|
70 |
def df(self, sql_engine=None, save=False, _raise=False):
|
71 |
res = self.run(sql_engine=sql_engine, save=save, _raise=_raise)
|