sqlmeta.base
Classes
|
Types of SQL constraints. |
|
Represents a column in a database table. |
|
Represents a constraint in a database table. |
|
Base class for SQL objects. |
|
SQL object types that can be created, modified, or dropped. |
- class sqlmeta.base.SqlObjectType(value)[source]
SQL object types that can be created, modified, or dropped.
- TABLE = 'TABLE'
- VIEW = 'VIEW'
- INDEX = 'INDEX'
- SEQUENCE = 'SEQUENCE'
- PROCEDURE = 'PROCEDURE'
- FUNCTION = 'FUNCTION'
- TRIGGER = 'TRIGGER'
- CONSTRAINT = 'CONSTRAINT'
- SCHEMA = 'SCHEMA'
- DATABASE = 'DATABASE'
- TYPE = 'TYPE'
- ROLE = 'ROLE'
- USER = 'USER'
- MATERIALIZED_VIEW = 'MATERIALIZED_VIEW'
- PACKAGE = 'PACKAGE'
- PACKAGE_BODY = 'PACKAGE_BODY'
- SYNONYM = 'SYNONYM'
- EVENT = 'EVENT'
- PARTITION = 'PARTITION'
- DATABASE_LINK = 'DATABASE_LINK'
- EXTENSION = 'EXTENSION'
- FOREIGN_DATA_WRAPPER = 'FOREIGN_DATA_WRAPPER'
- FOREIGN_SERVER = 'FOREIGN_SERVER'
- UNKNOWN = 'UNKNOWN'
- class sqlmeta.base.ConstraintType(value)[source]
Types of SQL constraints.
- PRIMARY_KEY = 'PRIMARY KEY'
- FOREIGN_KEY = 'FOREIGN KEY'
- UNIQUE = 'UNIQUE'
- CHECK = 'CHECK'
- NOT_NULL = 'NOT NULL'
- DEFAULT = 'DEFAULT'
- EXCLUDE = 'EXCLUDE'
- UNKNOWN = 'UNKNOWN'
- class sqlmeta.base.SqlObject(name: str, object_type: SqlObjectType | str, schema: str | None = None, dialect: str | None = None)[source]
Base class for SQL objects.
- __init__(name: str, object_type: SqlObjectType | str, schema: str | None = None, dialect: str | None = None) None[source]
Initialize a SQL object.
- Parameters:
name – Object name
object_type – Object type
schema – Schema name (optional)
dialect – SQL dialect (optional)
- object_type: SqlObjectType
- format_identifier(identifier: str) str[source]
Format an identifier according to the SQL dialect.
- Parameters:
identifier – The identifier to format
- Returns:
Formatted identifier
- mark_property_explicit(property_name: str) None[source]
Mark a property as explicitly defined (not using a schema default).
- Parameters:
property_name – The name of the property
- is_property_explicit(property_name: str) bool[source]
Check if a property was explicitly defined.
- Parameters:
property_name – The name of the property
- Returns:
True if the property was explicitly defined, False otherwise
- compare_with_defaults(other: SqlObject, schema_defaults: Dict[str, Any] = None) Dict[str, Any][source]
Compare two SQL objects, taking into account schema defaults.
- Parameters:
other – The other SQL object to compare with
schema_defaults – Dictionary of schema default values
- Returns:
Dictionary of differences between the objects
- class sqlmeta.base.SqlColumn(name: str, data_type: str, is_nullable: bool = True, default_value: str | None = None, is_primary_key: bool = False, is_unique: bool = False, constraints: List[SqlConstraint] | None = None, dialect: str | None = None, is_identity: bool = False, identity_generation: str | None = None, identity_seed: int | None = None, identity_increment: int | None = None, is_computed: bool = False, computed_expression: str | None = None, computed_stored: bool = False, comment: str | None = None, ordinal_position: int | None = None)[source]
Represents a column in a database table.
- __init__(name: str, data_type: str, is_nullable: bool = True, default_value: str | None = None, is_primary_key: bool = False, is_unique: bool = False, constraints: List[SqlConstraint] | None = None, dialect: str | None = None, is_identity: bool = False, identity_generation: str | None = None, identity_seed: int | None = None, identity_increment: int | None = None, is_computed: bool = False, computed_expression: str | None = None, computed_stored: bool = False, comment: str | None = None, ordinal_position: int | None = None)[source]
Initialize a SQL column.
- Parameters:
name – Column name
data_type – Data type of the column
is_nullable – Whether the column can be NULL
default_value – Default value of the column
is_primary_key – Whether this column is a primary key
is_unique – Whether this column has a unique constraint
constraints – List of constraints on this column
dialect – SQL dialect
is_identity – Whether this is an identity/auto-increment column
identity_generation – Identity generation strategy (ALWAYS, BY DEFAULT)
identity_seed – Starting value for identity column
identity_increment – Increment value for identity column
is_computed – Whether this is a computed/generated column
computed_expression – Expression used to compute the column value
computed_stored – Whether computed column is physically stored (vs virtual)
comment – Column comment/description
ordinal_position – Position of column in table (1-based)
- class sqlmeta.base.SqlConstraint(constraint_type: ConstraintType | str, name: str | None = None, column_names: List[str] | None = None, reference_table: str | None = None, reference_columns: List[str] | None = None, check_expression: str | None = None, dialect: str | None = None)[source]
Represents a constraint in a database table.
- __init__(constraint_type: ConstraintType | str, name: str | None = None, column_names: List[str] | None = None, reference_table: str | None = None, reference_columns: List[str] | None = None, check_expression: str | None = None, dialect: str | None = None)[source]
Initialize a SQL constraint.
- Parameters:
constraint_type – Type of constraint
name – Constraint name
column_names – Names of the columns in the constraint
reference_table – Table referenced by a foreign key
reference_columns – Columns referenced by a foreign key
check_expression – Expression used in a check constraint
dialect – SQL dialect