Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: broken example discovered during bug bash (#5059)

Dylan Madisetti9563ef74caae
diff --git a/examples/sql/misc/database_explorer.py b/examples/sql/misc/database_explorer.py
index fcc1b544c5..8a34e60b67 100644
--- a/examples/sql/misc/database_explorer.py
+++ b/examples/sql/misc/database_explorer.py
@@ -3,19 +3,22 @@
# dependencies = [
# "duckdb==1.1.1",
# "marimo",
+# "numpy==2.2.6",
+# "pandas==2.2.3",
# "polars==1.18.0",
# "pyarrow==18.1.0",
+# "sqlglot==26.19.0",
# ]
# ///
import marimo
-__generated_with = "0.9.1"
+__generated_with = "0.13.11"
app = marimo.App(width="full")
@app.cell
-def __():
+def _():
import os
import duckdb
@@ -24,19 +27,19 @@ def __():
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
- # Database explorer
+ # Database explorer
- This notebook lets you explore the contents of a database. Start by providing a database URL.
- """
+ This notebook lets you explore the contents of a database. Start by providing a database URL.
+ """
)
return
@app.cell
-def __(mo, os):
+def _(mo, os):
database_url = mo.ui.text(
label="Database URL",
full_width=True,
@@ -47,9 +50,7 @@ def __(mo, os):
@app.cell
-def __(database_url):
- import duckdb
-
+def _(database_url, duckdb):
if database_url.value:
duckdb.sql(
f"""
@@ -60,23 +61,23 @@ def __(database_url):
ATTACH DATABASE '{database_url.value}' AS my_db (TYPE postgres, READ_ONLY);
"""
)
- return duckdb, my_db
+ return (my_db,)
@app.cell
-def __(duckdb):
+def _(duckdb):
duckdb.sql("SHOW DATABASES").show()
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(r"""## Tables""")
return
@app.cell
-def __(mo):
+def _(mo):
_df = mo.sql(
f"""
SHOW ALL TABLES;
@@ -86,13 +87,13 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(r"""## Other meta table functions""")
return
@app.cell
-def __():
+def _():
FUNCTIONS = [
"duckdb_columns()", # columns
"duckdb_constraints()", # constraints
@@ -115,7 +116,7 @@ def __():
@app.cell
-def __(FUNCTIONS, mo):
+def _(FUNCTIONS, mo):
function = mo.ui.dropdown(
label="Dropdown",
options=FUNCTIONS,
@@ -126,7 +127,7 @@ def __(FUNCTIONS, mo):
@app.cell
-def __(_, function, mo):
+def _(function, mo):
_df = mo.sql(
f"""
SELECT * FROM {function.value} WHERE database_name == 'my_db'
@@ -136,13 +137,13 @@ def __(_, function, mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(r"""## Interact with your tables""")
return
@app.cell
-def __(duckdb, duckdb_tables, mo):
+def _(duckdb, mo):
tables = duckdb.execute(
"""
SELECT table_name FROM duckdb_tables() WHERE internal = False;
@@ -150,11 +151,11 @@ def __(duckdb, duckdb_tables, mo):
).df()
table_names = list(tables["table_name"])
mo.accordion({f"Found {len(table_names)} tables": table_names})
- return table_names, tables
+ return (table_names,)
@app.cell
-def __(mo, table_names):
+def _(mo, table_names):
mo.stop(not table_names)
table_select = mo.ui.dropdown(
label="Table",
@@ -173,14 +174,14 @@ def __(mo, table_names):
@app.cell
-def __(mo, table_select):
+def _(mo, table_select):
mo.stop(not table_select.value)
table_select_value = table_select.value
return (table_select_value,)
@app.cell
-def __(limit, mo, table_select_value):
+def _(limit, mo, my_db, null, table_select_value):
selected_table = mo.sql(
f"""
select * from my_db.{table_select_value} LIMIT {limit.value};
@@ -190,7 +191,7 @@ def __(limit, mo, table_select_value):
@app.cell
-def __(mo, selected_table):
+def _(mo, selected_table):
mo.ui.data_explorer(selected_table)
return