sqlexercise.constraints

Constraints for assignment generation.

Submodules

Classes

BaseConstraint

Abstract base class for SQL query constraints.

QueryConstraint

Base class for query-related constraints.

SchemaConstraint

Base class for schema-related constraints.

Package Contents

class sqlexercise.constraints.BaseConstraint

Bases: abc.ABC

Abstract base class for SQL query constraints.

property description: sqlexercise.translatable_text.TranslatableText
Abstractmethod:

Return type:

sqlexercise.translatable_text.TranslatableText

Textual description of the constraint, to be used in prompts.

class sqlexercise.constraints.QueryConstraint

Bases: sqlexercise.constraints.base.BaseConstraint

Base class for query-related constraints.

abstractmethod validate(query)

Validate if the given SQL query satisfies the constraint.

Args:

query (Query): The SQL query to validate.

Raises:

ConstraintValidationError: If the query does not satisfy the constraint.

Parameters:

query (sqlscope.Query)

Return type:

None

class sqlexercise.constraints.SchemaConstraint

Bases: sqlexercise.constraints.base.BaseConstraint

Base class for schema-related constraints.

abstractmethod validate(catalog, tables_sql, values_sql)

Validate if the given table creation and insertion statements satisfy the constraint.

Args:

catalog (Catalog): The catalog representing the database schema. tables_sql (list[exp.Create]): List of CREATE TABLE expressions. values_sql (list[exp.Insert]): List of INSERT INTO expressions.

Raises:

ConstraintValidationError: If the schema does not satisfy the constraint.

Parameters:
  • catalog (sqlscope.Catalog)

  • tables_sql (list[sqlglot.exp.Create])

  • values_sql (list[sqlglot.exp.Insert])

Return type:

None

abstractmethod merge(other)

Merges this constraint with another constraint of the same type.

Parameters:

other (SchemaConstraint)

Return type:

SchemaConstraint