@@ -42,3 +42,36 @@ def test_motherduck_schema_uses_password_field():
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"
45+
46+
47+ def test_motherduck_build_select_query_with_database ():
48+ """Test MotherDuck uses three-part names (database.schema.table)."""
49+ from sqlit .domains .connections .providers .motherduck .adapter import MotherDuckAdapter
50+
51+ adapter = MotherDuckAdapter ()
52+
53+ # With database - should use three-part name
54+ query = adapter .build_select_query ("hacker_news" , 100 , database = "sample_data" , schema = "hn" )
55+ assert query == 'SELECT * FROM "sample_data"."hn"."hacker_news" LIMIT 100'
56+
57+
58+ def test_motherduck_build_select_query_without_database ():
59+ """Test MotherDuck falls back to two-part names without database."""
60+ from sqlit .domains .connections .providers .motherduck .adapter import MotherDuckAdapter
61+
62+ adapter = MotherDuckAdapter ()
63+
64+ # Without database - should use two-part name
65+ query = adapter .build_select_query ("my_table" , 50 , schema = "main" )
66+ assert query == 'SELECT * FROM "main"."my_table" LIMIT 50'
67+
68+
69+ def test_motherduck_build_select_query_default_schema ():
70+ """Test MotherDuck defaults to 'main' schema."""
71+ from sqlit .domains .connections .providers .motherduck .adapter import MotherDuckAdapter
72+
73+ adapter = MotherDuckAdapter ()
74+
75+ # No schema specified - should default to main
76+ query = adapter .build_select_query ("my_table" , 25 , database = "my_db" )
77+ assert query == 'SELECT * FROM "my_db"."main"."my_table" LIMIT 25'
0 commit comments