@@ -130,6 +130,30 @@ def get_catalog(self) -> t.Optional[str]:
130130 return None
131131
132132
133+ class DuckDBAttachOptions (BaseConfig ):
134+ type : str
135+ path : str
136+ read_only : bool = False
137+ token : t .Optional [str ] = None
138+
139+ def to_sql (self , alias : str ) -> str :
140+ options = []
141+ # 'duckdb' is actually not a supported type, but we'd like to allow it for
142+ # fully qualified attach options or integration testing, similar to duckdb-dbt
143+ if self .type not in ("duckdb" , "motherduck" ):
144+ options .append (f"TYPE { self .type .upper ()} " )
145+ if self .read_only :
146+ options .append ("READ_ONLY" )
147+ # TODO: Add support for Postgres schema. Currently adding it blocks access to the information_schema
148+ alias_sql = (
149+ # MotherDuck does not support aliasing
150+ f" AS { alias } " if not (self .type == "motherduck" or self .path .startswith ("md:" )) else ""
151+ )
152+ options_sql = f" ({ ', ' .join (options )} )" if options else ""
153+ token_sql = "?motherduck_token=" + self .token if self .token else ""
154+ return f"ATTACH '{ self .path } { token_sql } '{ alias_sql } { options_sql } "
155+
156+
133157class BaseDuckDBConnectionConfig (ConnectionConfig ):
134158 """Common configuration for the DuckDB-based connections.
135159
@@ -357,30 +381,6 @@ def _static_connection_kwargs(self) -> t.Dict[str, t.Any]:
357381 return {"database" : connection_str , "config" : custom_user_agent_config }
358382
359383
360- class DuckDBAttachOptions (BaseConfig ):
361- type : str
362- path : str
363- read_only : bool = False
364- token : t .Optional [str ] = None
365-
366- def to_sql (self , alias : str ) -> str :
367- options = []
368- # 'duckdb' is actually not a supported type, but we'd like to allow it for
369- # fully qualified attach options or integration testing, similar to duckdb-dbt
370- if self .type not in ("duckdb" , "motherduck" ):
371- options .append (f"TYPE { self .type .upper ()} " )
372- if self .read_only :
373- options .append ("READ_ONLY" )
374- # TODO: Add support for Postgres schema. Currently adding it blocks access to the information_schema
375- alias_sql = (
376- # MotherDuck does not support aliasing
377- f" AS { alias } " if not (self .type == "motherduck" or self .path .startswith ("md:" )) else ""
378- )
379- options_sql = f" ({ ', ' .join (options )} )" if options else ""
380- token_sql = "?motherduck_token=" + self .token if self .token else ""
381- return f"ATTACH '{ self .path } { token_sql } '{ alias_sql } { options_sql } "
382-
383-
384384class DuckDBConnectionConfig (BaseDuckDBConnectionConfig ):
385385 """Configuration for the DuckDB connection."""
386386
0 commit comments