Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions sqlit/domains/connections/providers/motherduck/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,24 @@ def connect(self, config: ConnectionConfig) -> Any:
package_name=self.install_package,
)

# Get default database from options
database = config.get_option("default_database", "")
# Get database from endpoint (optional - empty means browse all)
database = ""
if config.tcp_endpoint:
database = config.tcp_endpoint.database or ""

# Get token from tcp_endpoint.password (stored in keyring)
token = ""
if config.tcp_endpoint:
token = config.tcp_endpoint.password or ""

if not database:
raise ValueError("MotherDuck connections require a database name.")
if not token:
raise ValueError("MotherDuck connections require an access token.")

conn_str = f"md:{database}?motherduck_token={token}"
# Connect with or without specific database
if database:
conn_str = f"md:{database}?motherduck_token={token}"
else:
conn_str = f"md:?motherduck_token={token}"

duckdb_any: Any = duckdb
return duckdb_any.connect(conn_str)
Expand Down
8 changes: 4 additions & 4 deletions sqlit/domains/connections/providers/motherduck/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
display_name="MotherDuck",
fields=(
SchemaField(
name="default_database",
label="Default Database",
placeholder="my_database",
required=True,
name="database",
label="Database",
placeholder="(empty = browse all)",
required=False,
),
SchemaField(
name="password",
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_motherduck_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def test_motherduck_schema_uses_password_field():
from sqlit.domains.connections.providers.motherduck.schema import SCHEMA

field_names = [f.name for f in SCHEMA.fields]
assert "default_database" in field_names
assert "database" in field_names
assert "password" in field_names # Uses standard password field for token

# Password field should be labeled as "Access Token"
password_field = next(f for f in SCHEMA.fields if f.name == "password")
assert password_field.label == "Access Token"

# Database field should be labeled as "Default Database"
db_field = next(f for f in SCHEMA.fields if f.name == "default_database")
assert db_field.label == "Default Database"
# Database field should be optional (empty = browse all)
db_field = next(f for f in SCHEMA.fields if f.name == "database")
assert db_field.required is False


def test_motherduck_supports_multiple_databases():
Expand Down
Loading