Skip to content

Commit 8fe6f5d

Browse files
authored
Merge pull request #125 from Maxteabag/fix/motherduck-optional-database
fix: make MotherDuck database field optional
2 parents 6ec0072 + 9b2aa6d commit 8fe6f5d

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

sqlit/domains/connections/providers/motherduck/adapter.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,24 @@ def connect(self, config: ConnectionConfig) -> Any:
3737
package_name=self.install_package,
3838
)
3939

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

4345
# Get token from tcp_endpoint.password (stored in keyring)
4446
token = ""
4547
if config.tcp_endpoint:
4648
token = config.tcp_endpoint.password or ""
4749

48-
if not database:
49-
raise ValueError("MotherDuck connections require a database name.")
5050
if not token:
5151
raise ValueError("MotherDuck connections require an access token.")
5252

53-
conn_str = f"md:{database}?motherduck_token={token}"
53+
# Connect with or without specific database
54+
if database:
55+
conn_str = f"md:{database}?motherduck_token={token}"
56+
else:
57+
conn_str = f"md:?motherduck_token={token}"
5458

5559
duckdb_any: Any = duckdb
5660
return duckdb_any.connect(conn_str)

sqlit/domains/connections/providers/motherduck/schema.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
display_name="MotherDuck",
1212
fields=(
1313
SchemaField(
14-
name="default_database",
15-
label="Default Database",
16-
placeholder="my_database",
17-
required=True,
14+
name="database",
15+
label="Database",
16+
placeholder="(empty = browse all)",
17+
required=False,
1818
),
1919
SchemaField(
2020
name="password",

tests/unit/test_motherduck_adapter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ def test_motherduck_schema_uses_password_field():
3636
from sqlit.domains.connections.providers.motherduck.schema import SCHEMA
3737

3838
field_names = [f.name for f in SCHEMA.fields]
39-
assert "default_database" in field_names
39+
assert "database" in field_names
4040
assert "password" in field_names # Uses standard password field for token
4141

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

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

5050

5151
def test_motherduck_supports_multiple_databases():

0 commit comments

Comments
 (0)