Adding an adapter
An adapter teaches odcr one platform. Most are 30–60 lines.
- Create
src/odcr/adapters/<platform>.py, subclassAdapter(SQL) orDocumentAdapter:
from .base import Adapter
class ClickHouseAdapter(Adapter):
dialect = "clickhouse"
driver = "clickhouse_connect"
paramstyle = "format" # format (%s) | qmark (?) | named (:p0) | inline (odcr renders literals)
quote_open = quote_close = "`"
def _connect(self):
import clickhouse_connect.dbapi
return clickhouse_connect.dbapi.connect(host=self.options["host"], ...)
def meta_types(self):
return {"id": "String", "name": "String", "short": "String", "text": "String",
"ts": "DateTime64(6)", "int": "Int64", "num": "Float64"}
def create_table_sql(self, table, columns_sql):
return f"CREATE TABLE IF NOT EXISTS {table} ({columns_sql}) ENGINE = MergeTree ORDER BY tuple()"
- Override only what differs from
base.py:
| Method / attribute | Default | Override when |
|---|---|---|
paramstyle |
format |
the driver uses ?, named or no parameters |
quote_open/close, quote_policy |
", always |
backticks / brackets; needed for upper-case-folding platforms |
columns() |
information_schema.columns |
another catalog (SYSCAT, ALL_TAB_COLUMNS, DESCRIBE) |
limit() |
LIMIT n |
TOP n / FETCH FIRST |
create_schema_sql() / create_table_sql() |
IF NOT EXISTS |
no IF NOT EXISTS (set ignore_errors) |
meta_types() / sample_types() |
ANSI | platform types |
meta_in_current_schema |
False | no schemas (prefix meta tables) |
-
Register it in
src/odcr/adapters/__init__.py(ADAPTERS, with extra, connection template and aliases), add the extra topyproject.toml, and runpython scripts/generate_examples.pyandpython scripts/generate_docs.py. -
Add the target to
tests/conftest.py(TARGETSandconnection_options). Every end-to-end test then runs against your platform — the contract runs, quarantine, notifications, reconciliation (also across platforms), tracing and streaming micro-batches. When they pass, the adapter is supported. Add a service to.github/workflows/ci.ymlif it runs in a container.