13
13
14
14
import sqlalchemy as sa
15
15
import sqlalchemy .event
16
- from sqlalchemy import Connection
16
+ from sqlalchemy import Connection , Dialect
17
17
from sqlalchemy .ext import compiler
18
18
from sqlalchemy .schema import BaseDDLElement , DDLElement , MetaData , SchemaItem , Table
19
19
from sqlalchemy .sql import Select
@@ -46,10 +46,12 @@ def _drop_view(element, comp, **kw): # type: ignore
46
46
47
47
def view_exists (
48
48
ddl : BaseDDLElement ,
49
- target : SchemaItem ,
49
+ target : SchemaItem | str ,
50
50
bind : Connection | None ,
51
51
tables : list [Table ] | None = None ,
52
52
state : Any | None = None ,
53
+ * ,
54
+ dialect : Dialect ,
53
55
** kw : Any ,
54
56
) -> bool :
55
57
"""Check if a view exists in the database.
@@ -62,16 +64,18 @@ def view_exists(
62
64
----------
63
65
ddl : BaseDDLElement
64
66
The DDL element that represents the creation or dropping of a view.
65
- target : SchemaItem
67
+ target : SchemaItem | str
66
68
The target schema item (not directly used in this check).
67
69
bind : Connection | None
68
70
The database connection used to inspect the database for existing views.
69
71
tables : list[Table] | None, optional
70
72
A list of tables (not directly used in this check).
71
73
state : Any | None, optional
72
74
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).
73
77
kw : Any
74
- Additional keyword arguments passed to the function (not directly used) .
78
+ Additional keyword arguments passed to the function.
75
79
76
80
Returns
77
81
-------
@@ -86,10 +90,12 @@ def view_exists(
86
90
87
91
def view_doesnt_exist (
88
92
ddl : BaseDDLElement ,
89
- target : SchemaItem ,
93
+ target : SchemaItem | str ,
90
94
bind : Connection | None ,
91
95
tables : list [Table ] | None = None ,
92
96
state : Any | None = None ,
97
+ * ,
98
+ dialect : Dialect ,
93
99
** kw : Any ,
94
100
) -> bool :
95
101
"""Check if a view does not exist in the database.
@@ -101,23 +107,25 @@ def view_doesnt_exist(
101
107
----------
102
108
ddl : BaseDDLElement
103
109
The DDL element that represents the creation or dropping of a view.
104
- target : SchemaItem
110
+ target : SchemaItem | str
105
111
The target schema item (not directly used in this check).
106
112
bind : Connection | None
107
113
The database connection used to inspect the database for existing views.
108
114
tables : list[Table] | None, optional
109
115
A list of tables (not directly used in this check).
110
116
state : Any | None, optional
111
117
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).
112
120
kw : Any
113
- Additional keyword arguments passed to the function (not directly used) .
121
+ Additional keyword arguments passed to the function.
114
122
115
123
Returns
116
124
-------
117
125
bool
118
126
Returns `True` if the view does not exist in the database, `False` otherwise.
119
127
"""
120
- return not view_exists (ddl , target , bind , ** kw )
128
+ return not view_exists (ddl , target , bind , dialect = dialect , ** kw )
121
129
122
130
123
131
def create_view (name : str , metadata : MetaData , selectable : Select [Any ]) -> None :
0 commit comments