Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/macaron/database/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import sqlalchemy as sa
import sqlalchemy.event
from sqlalchemy import Connection
from sqlalchemy import Connection, Dialect
from sqlalchemy.ext import compiler
from sqlalchemy.schema import BaseDDLElement, DDLElement, MetaData, SchemaItem, Table
from sqlalchemy.sql import Select
Expand Down Expand Up @@ -46,10 +46,12 @@ def _drop_view(element, comp, **kw): # type: ignore

def view_exists(
ddl: BaseDDLElement,
target: SchemaItem,
target: SchemaItem | str,
bind: Connection | None,
tables: list[Table] | None = None,
state: Any | None = None,
*,
dialect: Dialect,
**kw: Any,
) -> bool:
"""Check if a view exists in the database.
Expand All @@ -62,16 +64,18 @@ def view_exists(
----------
ddl : BaseDDLElement
The DDL element that represents the creation or dropping of a view.
target : SchemaItem
target : SchemaItem | str
The target schema item (not directly used in this check).
bind : Connection | None
The database connection used to inspect the database for existing views.
tables : list[Table] | None, optional
A list of tables (not directly used in this check).
state : Any | None, optional
The state of the object (not directly used in this check).
dialect : Dialect
The database dialect to be used for generating SQL (not directly used in this check).
kw : Any
Additional keyword arguments passed to the function (not directly used).
Additional keyword arguments passed to the function.

Returns
-------
Expand All @@ -86,10 +90,12 @@ def view_exists(

def view_doesnt_exist(
ddl: BaseDDLElement,
target: SchemaItem,
target: SchemaItem | str,
bind: Connection | None,
tables: list[Table] | None = None,
state: Any | None = None,
*,
dialect: Dialect,
**kw: Any,
) -> bool:
"""Check if a view does not exist in the database.
Expand All @@ -101,23 +107,25 @@ def view_doesnt_exist(
----------
ddl : BaseDDLElement
The DDL element that represents the creation or dropping of a view.
target : SchemaItem
target : SchemaItem | str
The target schema item (not directly used in this check).
bind : Connection | None
The database connection used to inspect the database for existing views.
tables : list[Table] | None, optional
A list of tables (not directly used in this check).
state : Any | None, optional
The state of the object (not directly used in this check).
dialect : Dialect
The database dialect to be used for generating SQL (not directly used in this check).
kw : Any
Additional keyword arguments passed to the function (not directly used).
Additional keyword arguments passed to the function.

Returns
-------
bool
Returns `True` if the view does not exist in the database, `False` otherwise.
"""
return not view_exists(ddl, target, bind, **kw)
return not view_exists(ddl, target, bind, dialect=dialect, **kw)


def create_view(name: str, metadata: MetaData, selectable: Select[Any]) -> None:
Expand Down
Loading