Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:173TECH Sayn DbObjectCompiler

From Leeroopedia
Knowledge Sources
Domains DevOps, Name_Resolution
Last Updated 2026-10-17 00:00 GMT

Overview

Concrete tool for resolving database object names with dev/prod naming rules, from_prod patterns, and reference-level parsing provided by the SAYN framework.

Description

The DbObjectCompiler class is the central engine for database object name resolution. It:

  • Parses object strings (e.g., "schema.table", "db.schema.table") into DbObject instances
  • Applies dev/prod stringify rules (prefix, suffix, override) to each component
  • Determines whether a source should use production naming via from_prod glob patterns and sources_from_prod set
  • Supports reference levels (None/table, schema, db) for partial references
  • Provides src_value()/out_value() for string resolution and src_obj()/out_obj() for object resolution

The is_from_prod method checks:

  1. If the object is on the default_db connection
  2. If the object's raw string matches any from_prod regex pattern
  3. If the object is in the explicit sources_from_prod set (from -u flag)

Usage

Used by TaskWrapper.src() and TaskWrapper.out() to resolve object names during task configuration and setup. Also used by App.setup_execution() for introspection.

Code Reference

Source Location

  • Repository: SAYN
  • File: sayn/database/objects.py
  • Lines: L10-53 (DbObject), L56-279 (DbObjectCompiler)

Signature

class DbObject:
    def __init__(self, compiler, connection_name: str, database: Optional[str],
                 schema: Optional[str], table: Optional[str])
    raw: str        # e.g. "schema.table"
    key: str        # e.g. "connection:schema.table"

class DbObjectCompiler:
    regex_obj = re.compile(r"^\s*((?P<connection>[^:]+):)?((?P<c1>[^.]+)\.)?...")

    def __init__(self, connections: Mapping[str, Database], default_db: str,
                 stringify: Mapping[str, Optional[str]],
                 prod_stringify: Mapping[str, Optional[str]],
                 from_prod: Set[str])

    def from_string(self, obj: str, connection: str | Database = None, level: str = None) -> DbObject
    def is_from_prod(self, obj: DbObject) -> bool
    def set_sources_from_prod(self, sources_from_prod: Set[DbObject]) -> None
    def src_obj(self, obj: DbObject) -> DbObject
    def out_obj(self, obj: DbObject) -> DbObject
    def src_value(self, obj: DbObject) -> str
    def out_value(self, obj: DbObject) -> str
    def _common_value(self, obj: DbObject, run_sensitive: bool) -> str
    def _get_stringify(self, type_: str, prefix: Optional[str], suffix: Optional[str], override: Optional[str]) -> str

Import

from sayn.database.objects import DbObjectCompiler, DbObject

I/O Contract

Inputs

Name Type Required Description
connections Dict[str, Database] Yes All database connections
default_db str Yes Default connection name
stringify Dict Yes Dev prefix/suffix/override for database/schema/table
prod_stringify Dict Yes Prod prefix/suffix/override
from_prod Set[str] No Glob patterns for from_prod sources

Outputs

Name Type Description
from_string returns DbObject Parsed object with connection, database, schema, table
src_value returns str Resolved source name with dev/prod rules
out_value returns str Resolved output name with dev/prod rules

Usage Examples

Resolving Object Names

from sayn.database.objects import DbObjectCompiler

# Created by App.set_settings()
compiler = DbObjectCompiler(
    connections={"warehouse": db, "api": api_db},
    default_db="warehouse",
    stringify={"schema_prefix": "dev", ...},  # dev naming
    prod_stringify={...},                      # prod naming
    from_prod=["raw.*"],                       # use prod names for raw.* tables
)

# Parse and resolve a source
obj = compiler.from_string("analytics.users", connection="warehouse")
# obj.schema = "analytics", obj.table = "users"

src_name = compiler.src_value(obj)
# Returns: "dev_analytics.users" (dev prefix applied)

# Parse and resolve an output
out_obj = compiler.from_string("analytics.users", connection="warehouse")
out_name = compiler.out_value(out_obj)
# Returns: "dev_analytics.users"

Checking from_prod

# Check if a source should use production naming
raw_obj = compiler.from_string("raw.events", connection="warehouse")
is_prod = compiler.is_from_prod(raw_obj)
# True if "raw.*" matches in from_prod patterns

# With upstream_prod (-u flag)
compiler.set_sources_from_prod({raw_obj})
is_prod = compiler.is_from_prod(raw_obj)
# True because it's in the sources_from_prod set

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment