Schema¶
Schema definition classes for sqbooster table system.
Provides Column and TableSchema classes for defining database table structure.
- class sqbooster.schema.Column(name, col_type, primary_key=False, nullable=True, unique=False, default=None, autoincrement=False)[source]¶
Bases:
objectDefines a database column with type and constraints.
- Parameters:
name – Column name.
col_type – Column type instance (e.g., Integer(), Text(), Float()).
primary_key – Whether this column is the primary key.
nullable – Whether NULL values are allowed.
unique – Whether values must be unique.
default – Default value for the column.
autoincrement – Whether the value auto-increments (primary key only).
Example
Column(“id”, Integer(), primary_key=True, autoincrement=True) Column(“name”, Text(), nullable=False) Column(“age”, Integer(), default=0)
- property sql_type¶
Return the SQL type string, accounting for VARCHAR length.
- class sqbooster.schema.TableSchema(name, columns)[source]¶
Bases:
objectDefines a complete table schema with columns and metadata.
- Parameters:
name – Table name.
columns – List of Column instances.
- property primary_key¶
Return the primary key column, or None.
- to_sql_create(backend='sqlite')[source]¶
Generate the CREATE TABLE SQL statement.
- Parameters:
backend – ‘sqlite’ or ‘postgresql’.
- validate_row(data)[source]¶
Validate a data dict against this schema.
- Parameters:
data – Dictionary of column_name -> value.
- Raises:
ValueError – If validation fails.