SQL Common

ANY_JOIN = *.*=*.*

A convenience object that represents any valid join condition. Only use it for a validator that represents full admin access to your database.

class FqColumn(*, table: str, column: str)

This represents a fully-qualified column name.

We require that LLM-produced queries from SQL Bifrosts use fully-qualified columns in their clauses, because if they didn’t, we would need to infer which table owned the column, which requires runtime schema analysis. We could do that, but maybe in the future. It’s much more straightforward to instruct that the LLM give us fully-qualified names.

Parameters:
  • table (str) – The table name.

  • column (str) – The column name.

classmethod from_string(fq_column_name: str) FqColumn

Parses a fully-qualified column name from a string, using the expected format of table.column

Parameters:

fq_column_name (str) – The fully-qualified column name.

Raises:

UnqualifiedColumn – If the string does not contain a period.

Return type:

FqColumn

property name: str

A convenience property that returns the fully-qualified column name as a string in the same format table.column

class JoinCondition(first: str, second: str, *, identity: str | None = None)

This represents an equi-join between two tables, on two columns. The order of the fully-qualified columns does not matter; matching will work correctly in the code.

Parameters:
  • first (str) – The first fully-qualified column.

  • second (str) – The second fully-qualified column.

  • identity (str | None) – If the columns specified in this join condition can also be used as a requester identity for the query, then this should be set to the name of the placeholder where the identity will be populated at runtime.

class ParameterizedConstraint(*, column: str, placeholder: str)

This represents a constraint that must be applied to the query.

In the query, this comes in the form of table.column=:placeholder. Enforced by the grammar, the comparison is always equality, the left hand side is always a fully-qualified column, and the right hand side is always a placeholder. These requirements ensure that the query is always constrained by a value that the developer specifies at query execution time.

Parameters:
  • column (str) – The fully-qualified column name.

  • placeholder (str) – The placeholder name for the value that your database expects to be interpolated at execution time.