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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
docs: sql docs on db GUI and datasource panel (#3897)
Myles Scolnickd0eef44cd705
diff --git a/docs/_static/docs-sql-choose-database.png b/docs/_static/docs-sql-choose-database.pngnew file mode 100644index 0000000000..b8adebbbf6Binary files /dev/null and b/docs/_static/docs-sql-choose-database.png differdiff --git a/docs/_static/docs-sql-datasources-panel.png b/docs/_static/docs-sql-datasources-panel.pngnew file mode 100644index 0000000000..abda19fe48Binary files /dev/null and b/docs/_static/docs-sql-datasources-panel.png differdiff --git a/docs/guides/working_with_data/sql.md b/docs/guides/working_with_data/sql.mdindex 5440ca4f4f..4d3b1856c7 100644--- a/docs/guides/working_with_data/sql.md+++ b/docs/guides/working_with_data/sql.md@@ -133,10 +133,26 @@ SELECT unnest([{{'a': 42, 'b': 84}}, {{'a': 100, 'b': NULL}}]);## Connecting to a custom database-marimo supports bringing your own database via a **connection engine** created with a library like [SQLAlchemy](https://docs.sqlalchemy.org/en/20/core/connections.html#basic-usage), [SQLModel](https://sqlmodel.tiangolo.com/tutorial/create-db-and-table/?h=create+engine#create-the-engine), or a [custom DuckDB connection](https://duckdb.org/docs/api/python/overview.html#connection-options). By default, marimo uses the [In-Memory duckdb connection](https://duckdb.org/docs/connect/overview.html#in-memory-database).+There are two ways to connect to a database in marimo:-First, you need to define the engine as a Python variable in a cell.-marimo will auto-discover the engine and let you select it in a dropdown in the SQL cell.+### 1. Using the UI++Click the "Add Database Connection" button in your notebook to connect to PostgreSQL, MySQL, SQLite, DuckDB, Snowflake, or BigQuery databases. The UI will guide you through entering your connection details securely.++<div align="center">+ <figure>+ <img src="/_static/docs-sql-choose-database.png"/>+ <figcaption>Add a database connection through the UI</figcaption>+ </figure>+</div>++If you'd like to connect to a database that isn't supported by the UI, you can use the code method below, or submit a [feature request](https://github.com/marimo-team/marimo/issues/new?title=New%20database%20connection:&labels=enhancement&template=feature_request.yaml).++### 2. Using Code++You can also bring your own database via a **connection engine** created with a library like [SQLAlchemy](https://docs.sqlalchemy.org/en/20/core/connections.html#basic-usage), [SQLModel](https://sqlmodel.tiangolo.com/tutorial/create-db-and-table/?h=create+engine#create-the-engine), or a [custom DuckDB connection](https://duckdb.org/docs/api/python/overview.html#connection-options). By default, marimo uses the [In-Memory duckdb connection](https://duckdb.org/docs/connect/overview.html#in-memory-database).++Define the engine as a Python variable in a cell:```pythonimport sqlalchemy@@ -151,6 +167,8 @@ postgres_engine = sqlmodel.create_engine("postgresql://username:password@server:duckdb_conn = duckdb.connect("file.db")```+marimo will auto-discover the engine and let you select it in the SQL cell's connection dropdown.+<div align="center"><figure><img width="750" src="/_static/docs-sql-engine-dropdown.png"/>@@ -158,6 +176,17 @@ duckdb_conn = duckdb.connect("file.db")</figure></div>+## Database, schema, and table auto-discovery++marimo will automatically discover the database connection and display the database, schemas, tables, and columns in the Data Sources panel. This panels lets you quickly navigate your database schema and reference tables and columns to pull in your SQL queries.++<div align="center">+ <figure>+ <img src="/_static/docs-sql-datasources-panel.png"/>+ <figcaption>Data Sources panel</figcaption>+ </figure>+</div>+## Interactive tutorialFor an interactive tutorial, run