Skip to main content
SQLBuild uses adapters to connect to different database engines. Set the adapter in sqlbuild_project.toml:
Or override it per developer in sqlbuild_local.toml:

Custom adapters

You can write your own adapter for any database engine by placing Python files under adapters/ in your project directory.

Extending a built-in adapter

The most common case is extending an existing adapter with custom behavior. Subclass the built-in adapter, set a new adapter_name, and override what you need:

Writing an adapter from scratch

For a database engine with no built-in support, subclass BaseAdapter. It provides ANSI SQL defaults for most methods - you only need to implement connect, execute, close, and any methods where your engine differs from standard SQL:
Set sql_analysis_dialect_name to the SQL dialect name that matches your engine’s SQL syntax. This enables compile-time SQL validation, column inference, column lineage, and local scenario replay for your adapter. If omitted, SQLBuild uses generic SQL parsing. SQL analysis is powered by Polyglot, a Rust reimplementation of SQLGlot supporting 32+ dialects. For full control with no inherited defaults, subclass StrictAdapter instead. Every method is abstract and must be implemented explicitly. SQLBuild raises a clear error listing any unimplemented methods.

Discovery rules

  • SQLBuild discovers all .py files under adapters/ recursively (excluding __init__.py and files starting with _)
  • Each file is scanned for classes that define a string adapter_name and subclass StrictAdapter (or any of its subclasses like BaseAdapter or a built-in adapter)
  • Adapter names must be unique across all adapter files - duplicates raise an error
  • Custom adapter names cannot shadow built-in names (duckdb, snowflake, bigquery, databricks, postgres, sqlserver)

Adapter class hierarchy

StrictAdapter composes four mixins that define the full adapter contract:
  • ConnectionMixin - connect, close, begin, commit, rollback
  • SchemaMixin - relation_exists, list_relations, describe_relation, ensure_schema
  • MaterializationMixin - create_table_as, create_view, drop, rename, swap, load_seed
  • DiffMixin - diff_schema, diff_rows, sample_unequal_rows, sample_side_only_rows