diff --git a/.gitignore b/.gitignore index ad4a1f1..c99e3ac 100644 --- a/.gitignore +++ b/.gitignore @@ -81,6 +81,7 @@ target/ # Jupyter Notebook .ipynb_checkpoints +__marimo__/ # IPython profile_default/ diff --git a/README.md b/README.md index 0eda484..7df9b34 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,19 @@ con.disconnect() `database` means schema. Queries run remotely; results are buffered in memory. Writes use the SDK directly. See the [runnable example](examples/ibis_queries.py). +### marimo + +Use the Ibis connection with `mo.sql(query, engine=con)`. Try the +[notebook](examples/marimo_notebook.py) with `ALTERTABLE_USERNAME` and +`ALTERTABLE_PASSWORD` set: + +```bash +pip install -e '.[ibis]' marimo +marimo edit examples/marimo_notebook.py +``` + +Use marimo's Datasources panel to add SQL cells for your own tables. + ## Usage ### Initialization diff --git a/examples/marimo_notebook.py b/examples/marimo_notebook.py new file mode 100644 index 0000000..5e35d62 --- /dev/null +++ b/examples/marimo_notebook.py @@ -0,0 +1,49 @@ +import marimo + +__generated_with = "0.25.1" +app = marimo.App(width="medium", sql_output="pandas") + + +@app.cell +def _(): + import ibis + import marimo as mo + + return ibis, mo + + +@app.cell +def _(ibis): + connection = ibis.altertable.connect() + return (connection,) + + +@app.cell +def _(mo): + minimum = mo.ui.slider( + 0, 40, value=10, label="Minimum customer total", debounce=True, show_value=True + ) + minimum + return (minimum,) + + +@app.cell +def _(connection, minimum, mo): + totals = mo.sql( + f""" + WITH orders(customer, amount) AS ( + VALUES ('alice', 10), ('alice', 20), ('bob', 5) + ) + SELECT customer, sum(amount) AS total + FROM orders + GROUP BY customer + HAVING sum(amount) >= {minimum.value} + ORDER BY customer + """, + engine=connection, + ) + return (totals,) + + +if __name__ == "__main__": + app.run()