From b7a127e15ca87e53fbd36f92e3b095cf9479ee2f Mon Sep 17 00:00:00 2001 From: Aaron Steers Date: Fri, 16 Feb 2024 14:30:56 -0800 Subject: [PATCH] very basic motherduck cache --- airbyte/caches/__init__.py | 3 +++ airbyte/caches/motherduck.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 airbyte/caches/motherduck.py diff --git a/airbyte/caches/__init__.py b/airbyte/caches/__init__.py index 724abd7c..1f5cb83f 100644 --- a/airbyte/caches/__init__.py +++ b/airbyte/caches/__init__.py @@ -3,6 +3,7 @@ from airbyte.caches.base import SQLCacheBase from airbyte.caches.duckdb import DuckDBCache, DuckDBCacheConfig +from airbyte.caches.motherduck import MotherDuckCache, MotherDuckCacheConfig from airbyte.caches.postgres import PostgresCache, PostgresCacheConfig from airbyte.caches.snowflake import SnowflakeCacheConfig, SnowflakeSQLCache @@ -11,6 +12,8 @@ __all__ = [ "DuckDBCache", "DuckDBCacheConfig", + "MotherDuckCache", + "MotherDuckCacheConfig", "PostgresCache", "PostgresCacheConfig", "SQLCacheBase", diff --git a/airbyte/caches/motherduck.py b/airbyte/caches/motherduck.py new file mode 100644 index 00000000..7db8f62b --- /dev/null +++ b/airbyte/caches/motherduck.py @@ -0,0 +1,31 @@ +"""A cache implementation for the MotherDuck service, built on DuckDB.""" +from __future__ import annotations + +from overrides import overrides + +from airbyte.caches.duckdb import DuckDBCacheBase, DuckDBCacheConfig + + +class MotherDuckCacheConfig(DuckDBCacheConfig): + """Configuration for the MotherDuck cache.""" + + db_path = "md:" + database: str + api_key: str + + @overrides + def get_sql_alchemy_url(self) -> str: + """Return the SQLAlchemy URL to use.""" + # return f"duckdb:///{self.db_path}?schema={self.schema_name}" + return f"duckdb:///md:{self.api_key}@{self.database}" + + @overrides + def get_database_name(self) -> str: + """Return the name of the database.""" + return self.database + + +class MotherDuckCache(DuckDBCacheBase): + """A cache implementation for the MotherDuck service, built on DuckDB.""" + + config_class = MotherDuckCacheConfig