sqlexercise.assignments¶
Data structures for SQL assignments.
Classes¶
A full SQL assignment consisting of a dataset and exercises. |
|
A SQL exercise consisting of a title, request, and solutions. |
|
A SQL dataset related to a specific domain, including schema creation and data insertion commands. |
Package Contents¶
- class sqlexercise.assignments.Assignment¶
A full SQL assignment consisting of a dataset and exercises.
- dataset: sqlexercise.assignments.dataset.Dataset¶
The dataset associated with the assignment.
- exercises: list[sqlexercise.assignments.exercise.Exercise]¶
The exercises included in the assignment.
- class sqlexercise.assignments.Exercise¶
A SQL exercise consisting of a title, request, and solutions.
- title: str¶
The title of the exercise.
- request: str¶
The natural language request or question for the exercise.
- solutions: list[sqlscope.Query]¶
The list of SQL query solutions for the exercise.
- difficulty: sqlexercise.difficulty_level.DifficultyLevel¶
The difficulty level of the exercise.
- error: sqlerrors.SqlErrors¶
The SQL error type associated with the exercise.
- static generate(error, difficulty, constraints, *, db_host, db_port, db_user, db_password, extra_details, dataset, title, sql_dialect, language, max_attempts=3, on_attempt_start=lambda : ...)¶
Generate a SQL exercise based on the specified parameters.
- Parameters:
error (sqlerrors.SqlErrors)
difficulty (sqlexercise.difficulty_level.DifficultyLevel)
constraints (list[sqlexercise.constraints.QueryConstraint])
db_host (str)
db_port (int)
db_user (str)
db_password (str)
extra_details (str)
dataset (sqlexercise.assignments.dataset.Dataset)
title (str)
sql_dialect (str)
language (str)
max_attempts (int)
on_attempt_start (Callable[[], None])
- Return type:
- class sqlexercise.assignments.Dataset¶
A SQL dataset related to a specific domain, including schema creation and data insertion commands.
- create_commands: list[str]¶
SQL commands to create the database schema.
- insert_commands: list[str]¶
SQL commands to insert data into the database.
- domain: str¶
The domain associated with the dataset.
- _catalog_cache: sqlscope.Catalog | None = None¶
Cached SQLScope Catalog for the dataset.
- _catalog_cache_commands_hash: int | None = None¶
Hash of the CREATE TABLE commands used to build the cached Catalog.
- property catalog: sqlscope.Catalog¶
Build and return a SQLScope Catalog from the dataset’s SQL commands. The result is cached for handling multiple accesses efficiently. Cache is properly invalidated if the CREATE TABLE commands change.
- Return type:
sqlscope.Catalog
- to_sql_no_context()¶
Generate the SQL commands to create and populate the dataset without schema context.
- Return type:
str
- to_sql(schema)¶
Generate the SQL commands to create and populate the dataset within the specified schema.
- Parameters:
schema (str)
- Return type:
str
- static from_sql(sql_str, sql_dialect)¶
Create a Dataset instance from a raw SQL string containing CREATE TABLE and INSERT INTO commands.
- Parameters:
sql_str (str)
sql_dialect (str)
- Return type:
- static generate(domain, sql_dialect, constraints, extra_details=[], *, db_host, db_port, db_user, db_password, language, max_attempts=5, on_attempt_start=lambda : ...)¶
Generate a SQL dataset based on the specified parameters.
- Parameters:
domain (str)
sql_dialect (str)
constraints (collections.abc.Sequence[sqlexercise.constraints.SchemaConstraint])
extra_details (list[str])
db_host (str)
db_port (int)
db_user (str)
db_password (str)
language (str)
max_attempts (int)
on_attempt_start (Callable[[], None])
- Return type: