sqlmeta.objects.table
Classes
|
Represents a database table. |
- class sqlmeta.objects.table.Table(name: str, columns: List[SqlColumn] = None, schema: str | None = None, constraints: List[SqlConstraint] = None, temporary: bool = False, tablespace: str | None = None, dialect: str | None = None, comment: str | None = None, storage_engine: str | None = None, partitions: List | None = None, filegroup: str | None = None, memory_optimized: bool = False, system_versioned: bool = False, history_table: str | None = None, history_schema: str | None = None, derived_from: str | None = None)[source]
Represents a database table.
- __init__(name: str, columns: List[SqlColumn] = None, schema: str | None = None, constraints: List[SqlConstraint] = None, temporary: bool = False, tablespace: str | None = None, dialect: str | None = None, comment: str | None = None, storage_engine: str | None = None, partitions: List | None = None, filegroup: str | None = None, memory_optimized: bool = False, system_versioned: bool = False, history_table: str | None = None, history_schema: str | None = None, derived_from: str | None = None)[source]
Initialize a table.
- Parameters:
name – Table name
columns – List of columns
schema – Schema name (optional)
constraints – List of constraints
temporary – Whether the table is temporary
tablespace – Tablespace name (optional)
dialect – SQL dialect
comment – Table comment/description (optional)
storage_engine – Storage engine (MySQL: InnoDB, MyISAM, etc.)
partitions – List of Partition objects (optional)
filegroup – Filegroup name (SQL Server T-SQL grammar-based)
memory_optimized – Whether table is memory-optimized (SQL Server T-SQL grammar-based)
system_versioned – Whether table is system-versioned temporal table (SQL Server T-SQL grammar-based)
history_table – History table name for system-versioned tables (SQL Server T-SQL grammar-based)
history_schema – History table schema for system-versioned tables (SQL Server T-SQL grammar-based)
derived_from – Source for derived tables (e.g., “CTAS”, “LIKE source_table”, “SELECT”)
- add_column(column: SqlColumn) None[source]
Add a column to the table.
- Parameters:
column – The column to add
- get_column(name: str) SqlColumn | None[source]
Get a column by name.
- Parameters:
name – Column name
- Returns:
The column or None if not found
- add_constraint(constraint: SqlConstraint) None[source]
Add a constraint to the table.
- Parameters:
constraint – The constraint to add
- get_primary_key() SqlConstraint | None[source]
Get the primary key constraint.
- Returns:
The primary key constraint or None if not found
- get_foreign_keys() List[SqlConstraint][source]
Get all foreign key constraints.
- Returns:
List of foreign key constraints
- get_unique_constraints() List[SqlConstraint][source]
Get all unique constraints.
- Returns:
List of unique constraints
- get_check_constraints() List[SqlConstraint][source]
Get all check constraints.
- Returns:
List of check constraints
- property create_statement: str
Generate CREATE TABLE statement.
- Returns:
SQL CREATE TABLE statement for this table
- property drop_statement: str
Generate DROP TABLE statement.
- Returns:
SQL DROP TABLE statement for this table
- compare_with_defaults(other: SqlObject, schema_defaults: Dict[str, Any] = None) Dict[str, Any][source]
Compare two tables, taking into account schema defaults.
This method extends the base class method to handle table-specific properties.
- Parameters:
other – The other table to compare with
schema_defaults – Dictionary of schema default values
- Returns:
Dictionary of differences between the tables