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
improvement: add motherduck to database modal (#4740)
Myles Scolnick4c23dcf47c78
diff --git a/frontend/src/components/databases/display.tsx b/frontend/src/components/databases/display.tsxindex 00a135689c..0ea33d1265 100644--- a/frontend/src/components/databases/display.tsx+++ b/frontend/src/components/databases/display.tsx@@ -3,6 +3,8 @@ export function dbDisplayName(name: string) {switch (name) {case "duckdb":return "DuckDB";+ case "motherduck":+ return "MotherDuck";case "sqlite":return "SQLite";case "postgres":diff --git a/frontend/src/components/databases/icon.tsx b/frontend/src/components/databases/icon.tsxindex 61dfef8656..eb87ab58f9 100644--- a/frontend/src/components/databases/icon.tsx+++ b/frontend/src/components/databases/icon.tsx@@ -2,6 +2,7 @@import type { FC } from "react";import SQLiteIcon from "./icons/sqlite.svg";import DuckDBIcon from "./icons/duckdb.svg";+import MotherDuckIcon from "./icons/motherduck.svg";import PostgresQLIcon from "./icons/postgresql.svg";import MySQLIcon from "./icons/mysql.svg";import SnowflakeIcon from "./icons/snowflake.svg";@@ -18,6 +19,7 @@ import { cn } from "@/utils/cn";export type DBLogoName =| "sqlite"| "duckdb"+ | "motherduck"| "postgres"| "postgresql"| "mysql"@@ -43,6 +45,7 @@ interface DatabaseLogoProps {const URLS: Record<DBLogoName, string | undefined> = {sqlite: SQLiteIcon,duckdb: DuckDBIcon,+ motherduck: MotherDuckIcon,postgres: PostgresQLIcon,postgresql: PostgresQLIcon,mysql: MySQLIcon,diff --git a/frontend/src/components/databases/icons/motherduck.svg b/frontend/src/components/databases/icons/motherduck.svgnew file mode 100644index 0000000000..de4601f95f--- /dev/null+++ b/frontend/src/components/databases/icons/motherduck.svg@@ -0,0 +1,9 @@+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">+ <title>MotherDuck</title>+ <g transform="scale(0.85) translate(0, 2)">+ <path fill="#ff9538"+ d="M1.71 15.86s7.45 5.32 7.89 5.59c.44.27 1.08.33 1.64.11.56-.22.98-.71 1.11-1.21s1.85-9.49 1.85-9.49c.02-.12.07-.48-.13-.83-.27-.47-.86-.71-1.38-.57-.42.12-.64.44-.7.55-.09.17-.26.45-.57.7-.24.19-.47.3-.58.34-.96.38-2.02.06-2.61-.72-.38-.48-1.04-.67-1.64-.43-.6.24-.94.84-.89 1.45.11.98-.44 1.94-1.4 2.32-.51.21-1.06.21-1.54.05-.12-.03-.51-.12-.89.09-.48.26-.74.84-.61 1.37.09.39.38.62.48.69z" />+ <path fill="#ff9538"+ d="M14.12 4.21s2.65 8.76 2.83 9.24c.19.48.66.92 1.23 1.09.58.16 1.21.03 1.62-.28.41-.31 7.25-6.39 7.25-6.39.09-.08.35-.34.4-.74.07-.53-.25-1.09-.75-1.29-.4-.16-.78-.04-.89 0-.18.08-.48.2-.88.2-.3.01-.55-.05-.67-.08-.99-.28-1.64-1.18-1.63-2.16-.01-.61-.42-1.17-1.04-1.35-.62-.18-1.26.09-1.59.6-.51.84-1.53 1.27-2.52.99-.53-.15-.96-.48-1.25-.91-.07-.09-.33-.4-.76-.48-.54-.09-1.1.22-1.32.71-.16.37-.08.72-.04.84z" />+ </g>+</svg>diff --git a/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap b/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snapindex ab5be1d1ff..9fc5412e4a 100644--- a/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap+++ b/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap@@ -115,6 +115,14 @@ catalog = SqlCatalog()"`;+exports[`generateDatabaseCode > basic connections > motherduck 1`] = `+"import duckdb+import os++_password = os.environ.get("MOTHERDUCK_TOKEN", "my_token")+conn = duckdb.connect("md:my_db", config={"motherduck_token": _password})"+`;+exports[`generateDatabaseCode > basic connections > mysql with SQLAlchemy 1`] = `"import osimport sqlalchemy@@ -237,6 +245,14 @@ engine = clickhouse_connect.get_client()"`;+exports[`generateDatabaseCode > connections with secrets > motherduck with token as secret 1`] = `+"import duckdb+import os++_password = os.environ.get("ENV_TOKEN")+conn = duckdb.connect("md:my_db", config={"motherduck_token": _password})"+`;+exports[`generateDatabaseCode > connections with secrets > mysql with username and password as secrets 1`] = `"import osimport sqlalchemy@@ -356,6 +372,14 @@ DATABASE_URL = "./relative/path/db.duckdb"engine = sqlmodel.connect(DATABASE_URL, read_only=False)"`;+exports[`generateDatabaseCode > edge cases > motherduck with special chars in database name 1`] = `+"import duckdb+import os++_password = os.environ.get("MOTHERDUCK_TOKEN", "my_token")+conn = duckdb.connect("md:test-db.special", config={"motherduck_token": _password})"+`;+exports[`generateDatabaseCode > edge cases > mysql with extremely long database name 1`] = `"import osimport sqlmodeldiff --git a/frontend/src/components/editor/database/__tests__/as-code.test.ts b/frontend/src/components/editor/database/__tests__/as-code.test.tsindex e705be5b6e..2e06aaecfe 100644--- a/frontend/src/components/editor/database/__tests__/as-code.test.ts+++ b/frontend/src/components/editor/database/__tests__/as-code.test.ts@@ -37,6 +37,12 @@ describe("generateDatabaseCode", () => {read_only: true,};+ const motherduckConnection: DatabaseConnection = {+ type: "motherduck",+ database: "my_db",+ token: "my_token",+ };+const snowflakeConnection: DatabaseConnection = {type: "snowflake",account: "account",@@ -169,6 +175,7 @@ describe("generateDatabaseCode", () => {["mysql with SQLAlchemy", baseMysql, "sqlalchemy"],["sqlite", sqliteConnection, "sqlmodel"],["duckdb", duckdbConnection, "duckdb"],+ ["motherduck", motherduckConnection, "duckdb"],["snowflake", snowflakeConnection, "sqlmodel"],["bigquery", bigqueryConnection, "sqlmodel"],["clickhouse", clickhouseConnection, "clickhouse_connect"],@@ -250,6 +257,14 @@ describe("generateDatabaseCode", () => {},"sqlalchemy",],+ [+ "motherduck with token as secret",+ {+ ...motherduckConnection,+ token: prefixSecret("ENV_TOKEN"),+ },+ "duckdb",+ ],])("%s", (name, connection, orm) => {expect(generateDatabaseCode(connection, orm as ConnectionLibrary),@@ -452,6 +467,14 @@ describe("generateDatabaseCode", () => {},"sqlalchemy",],+ [+ "motherduck with special chars in database name",+ {+ ...motherduckConnection,+ database: "test-db.special",+ },+ "duckdb",+ ],];it.each(testCases)("%s", (name, connection, orm) => {diff --git a/frontend/src/components/editor/database/add-database-form.tsx b/frontend/src/components/editor/database/add-database-form.tsxindex c60962abf7..5ea01d5477 100644--- a/frontend/src/components/editor/database/add-database-form.tsx+++ b/frontend/src/components/editor/database/add-database-form.tsx@@ -20,6 +20,7 @@ import {IcebergConnectionSchema,DataFusionConnectionSchema,PySparkConnectionSchema,+ MotherDuckConnectionSchema,} from "./schemas";import {Dialog,@@ -107,6 +108,16 @@ const DATABASES = [preferred: "duckdb",},},+ {+ name: "MotherDuck",+ schema: MotherDuckConnectionSchema,+ color: "#ff9538",+ logo: "motherduck",+ connectionLibraries: {+ libraries: ["duckdb"],+ preferred: "duckdb",+ },+ },{name: "Snowflake",schema: SnowflakeConnectionSchema,diff --git a/frontend/src/components/editor/database/as-code.ts b/frontend/src/components/editor/database/as-code.tsindex 76fa1dc44f..f22d09ee15 100644--- a/frontend/src/components/editor/database/as-code.ts+++ b/frontend/src/components/editor/database/as-code.ts@@ -12,7 +12,8 @@ export type ConnectionLibrary =| "clickhouse_connect"| "chdb"| "pyiceberg"- | "ibis";+ | "ibis"+ | "motherduck";export const ConnectionDisplayNames: Record<ConnectionLibrary, string> = {sqlmodel: "SQLModel",@@ -22,6 +23,7 @@ export const ConnectionDisplayNames: Record<ConnectionLibrary, string> = {chdb: "chDB",pyiceberg: "PyIceberg",ibis: "Ibis",+ motherduck: "MotherDuck",};abstract class CodeGenerator<T extends DatabaseConnection["type"]> {@@ -327,6 +329,34 @@ class DuckDBGenerator extends CodeGenerator<"duckdb"> {}}+class MotherDuckGenerator extends CodeGenerator<"motherduck"> {+ generateImports(): string[] {+ return [];+ }++ generateConnectionCode(): string {+ const database = this.secrets.printInFString(+ "database",+ this.connection.database,+ );++ if (!this.connection.token) {+ return dedent(`+ conn = duckdb.connect("md:${database}")+ `);+ }++ const token = this.secrets.printPassword(+ this.connection.token,+ "MOTHERDUCK_TOKEN",+ false,+ );+ return dedent(`+ conn = duckdb.connect("md:${database}", config={"motherduck_token": ${token}})+ `);+ }+}+class ClickHouseGenerator extends CodeGenerator<"clickhouse_connect"> {generateImports(): string[] {return ["import clickhouse_connect"];@@ -356,6 +386,7 @@ ${formatUrlParams(params, (inner) => ` ${inner}`)},`);}}+class TimeplusGenerator extends CodeGenerator<"timeplus"> {generateImports(): string[] {return [];@@ -533,7 +564,7 @@ class DataFusionGenerator extends CodeGenerator<"datafusion"> {ctx = SessionContext()# Sample table_ = ctx.from_pydict({"a": [1, 2, 3]}, "my_table")-+con = ibis.datafusion.connect(ctx)`);}@@ -591,6 +622,8 @@ class CodeGeneratorFactory {return new BigQueryGenerator(connection, orm, this.secrets);case "duckdb":return new DuckDBGenerator(connection, orm, this.secrets);+ case "motherduck":+ return new MotherDuckGenerator(connection, orm, this.secrets);case "clickhouse_connect":return new ClickHouseGenerator(connection, orm, this.secrets);case "timeplus":diff --git a/frontend/src/components/editor/database/schemas.ts b/frontend/src/components/editor/database/schemas.tsindex 4f895a633a..aa24aa3fc0 100644--- a/frontend/src/components/editor/database/schemas.ts+++ b/frontend/src/components/editor/database/schemas.ts@@ -174,6 +174,16 @@ export const DuckDBConnectionSchema = z}).describe(FieldOptions.of({ direction: "two-columns" }));+export const MotherDuckConnectionSchema = z+ .object({+ type: z.literal("motherduck"),+ database: databaseField()+ .default("my_db")+ .describe(FieldOptions.of({ label: "Database Name" })),+ token: tokenField(),+ })+ .describe(FieldOptions.of({ direction: "two-columns" }));+export const SnowflakeConnectionSchema = z.object({type: z.literal("snowflake"),@@ -399,6 +409,7 @@ export const DatabaseConnectionSchema = z.discriminatedUnion("type", [MySQLConnectionSchema,SQLiteConnectionSchema,DuckDBConnectionSchema,+ MotherDuckConnectionSchema,SnowflakeConnectionSchema,BigQueryConnectionSchema,ClickhouseConnectionSchema,