1313
1414import sqlalchemy as sa
1515import sqlalchemy .event
16- from sqlalchemy import Connection
16+ from sqlalchemy import Connection , Dialect
1717from sqlalchemy .ext import compiler
1818from sqlalchemy .schema import BaseDDLElement , DDLElement , MetaData , SchemaItem , Table
1919from sqlalchemy .sql import Select
@@ -46,10 +46,12 @@ def _drop_view(element, comp, **kw): # type: ignore
4646
4747def view_exists (
4848 ddl : BaseDDLElement ,
49- target : SchemaItem ,
49+ target : SchemaItem | str ,
5050 bind : Connection | None ,
5151 tables : list [Table ] | None = None ,
5252 state : Any | None = None ,
53+ * ,
54+ dialect : Dialect ,
5355 ** kw : Any ,
5456) -> bool :
5557 """Check if a view exists in the database.
@@ -62,16 +64,18 @@ def view_exists(
6264 ----------
6365 ddl : BaseDDLElement
6466 The DDL element that represents the creation or dropping of a view.
65- target : SchemaItem
67+ target : SchemaItem | str
6668 The target schema item (not directly used in this check).
6769 bind : Connection | None
6870 The database connection used to inspect the database for existing views.
6971 tables : list[Table] | None, optional
7072 A list of tables (not directly used in this check).
7173 state : Any | None, optional
7274 The state of the object (not directly used in this check).
75+ dialect : Dialect
76+ The database dialect to be used for generating SQL (not directly used in this check).
7377 kw : Any
74- Additional keyword arguments passed to the function (not directly used) .
78+ Additional keyword arguments passed to the function.
7579
7680 Returns
7781 -------
@@ -86,10 +90,12 @@ def view_exists(
8690
8791def view_doesnt_exist (
8892 ddl : BaseDDLElement ,
89- target : SchemaItem ,
93+ target : SchemaItem | str ,
9094 bind : Connection | None ,
9195 tables : list [Table ] | None = None ,
9296 state : Any | None = None ,
97+ * ,
98+ dialect : Dialect ,
9399 ** kw : Any ,
94100) -> bool :
95101 """Check if a view does not exist in the database.
@@ -101,23 +107,25 @@ def view_doesnt_exist(
101107 ----------
102108 ddl : BaseDDLElement
103109 The DDL element that represents the creation or dropping of a view.
104- target : SchemaItem
110+ target : SchemaItem | str
105111 The target schema item (not directly used in this check).
106112 bind : Connection | None
107113 The database connection used to inspect the database for existing views.
108114 tables : list[Table] | None, optional
109115 A list of tables (not directly used in this check).
110116 state : Any | None, optional
111117 The state of the object (not directly used in this check).
118+ dialect : Dialect
119+ The database dialect to be used for generating SQL (not directly used in this check).
112120 kw : Any
113- Additional keyword arguments passed to the function (not directly used) .
121+ Additional keyword arguments passed to the function.
114122
115123 Returns
116124 -------
117125 bool
118126 Returns `True` if the view does not exist in the database, `False` otherwise.
119127 """
120- return not view_exists (ddl , target , bind , ** kw )
128+ return not view_exists (ddl , target , bind , dialect = dialect , ** kw )
121129
122130
123131def create_view (name : str , metadata : MetaData , selectable : Select [Any ]) -> None :
0 commit comments