sqlexercise.constraints.schema

Constraints related to database schema.

Classes

SchemaConstraint

Base class for schema-related constraints.

Functions

merge_constraints(constraints)

Merge similar schema constraints into a single set of constraints.

Package Contents

class sqlexercise.constraints.schema.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

sqlexercise.constraints.schema.merge_constraints(constraints)

Merge similar schema constraints into a single set of constraints.

Parameters:

constraints (collections.abc.Sequence[base.SchemaConstraint])

Return type:

collections.abc.Sequence[base.SchemaConstraint]