sqlmeta.objects.view

Classes

View(name[, schema, query, columns, ...])

Represents a database view.

class sqlmeta.objects.view.View(name: str, schema: str | None = None, query: str | None = None, columns: List[str] | None = None, materialized: bool = False, dialect: str | None = None, is_populated: bool | None = None, refresh_method: str | None = None, refresh_mode: str | None = None, fast_refreshable: bool | None = None, last_refresh: str | None = None, unlogged: bool | None = None, algorithm: str | None = None, sql_security: str | None = None, definer: str | None = None, force: bool | None = None)[source]

Represents a database view.

Supports both regular views and materialized views with refresh options.

__init__(name: str, schema: str | None = None, query: str | None = None, columns: List[str] | None = None, materialized: bool = False, dialect: str | None = None, is_populated: bool | None = None, refresh_method: str | None = None, refresh_mode: str | None = None, fast_refreshable: bool | None = None, last_refresh: str | None = None, unlogged: bool | None = None, algorithm: str | None = None, sql_security: str | None = None, definer: str | None = None, force: bool | None = None)[source]

Initialize a view.

Parameters:
  • name – View name

  • schema – Schema name (optional)

  • query – SELECT query that defines the view

  • columns – List of column names (optional)

  • materialized – Whether the view is materialized

  • dialect – SQL dialect

  • is_populated – Whether the materialized view is populated (PostgreSQL, Oracle)

  • refresh_method – Refresh method - FAST, COMPLETE, FORCE, MANUAL (Oracle, DB2)

  • refresh_mode – Refresh mode - ON DEMAND, ON COMMIT (Oracle)

  • fast_refreshable – Whether fast refresh is available (Oracle)

  • last_refresh – Timestamp of last refresh (Oracle, DB2)

  • unlogged – Whether the materialized view is UNLOGGED (PostgreSQL grammar-based)

  • algorithm – View algorithm - MERGE, TEMPTABLE, UNDEFINED (MySQL grammar-based)

  • sql_security – SQL security - DEFINER, INVOKER (MySQL grammar-based)

  • definer – Definer user - user@host (MySQL grammar-based)

  • force – Whether view is created with FORCE (True) or NOFORCE (False) (Oracle grammar-based)

property create_statement: str

Generate CREATE VIEW statement.

The syntax varies by dialect.

Returns:

Dialect-specific CREATE VIEW statement

property drop_statement: str

Generate DROP VIEW statement.

Returns:

SQL DROP VIEW statement for this view

__str__() str[source]

Return string representation of the view.

__eq__(other: Any) bool[source]

Check if two views are equal.

classmethod from_dict(data: Dict[str, Any]) View[source]

Create view from dictionary representation.

Parameters:

data – Dictionary with view attributes

Returns:

View object

to_dict() Dict[str, Any][source]

Convert view to dictionary representation.

Returns:

Dictionary with view attributes