r"""Return a callable that will execute this :class:`_ddl.ExecutableDDLElement` conditionally within an event handler. Used to provide a wrapper for event listening:: event.listen( metadata, "before_create", DDL("m
(
self,
dialect: Optional[str] = None,
callable_: Optional[DDLIfCallable] = None,
state: Optional[Any] = None,
)
| 242 | |
| 243 | @_generative |
| 244 | def execute_if( |
| 245 | self, |
| 246 | dialect: Optional[str] = None, |
| 247 | callable_: Optional[DDLIfCallable] = None, |
| 248 | state: Optional[Any] = None, |
| 249 | ) -> Self: |
| 250 | r"""Return a callable that will execute this |
| 251 | :class:`_ddl.ExecutableDDLElement` conditionally within an event |
| 252 | handler. |
| 253 | |
| 254 | Used to provide a wrapper for event listening:: |
| 255 | |
| 256 | event.listen( |
| 257 | metadata, |
| 258 | "before_create", |
| 259 | DDL("my_ddl").execute_if(dialect="postgresql"), |
| 260 | ) |
| 261 | |
| 262 | :param dialect: May be a string or tuple of strings. |
| 263 | If a string, it will be compared to the name of the |
| 264 | executing database dialect:: |
| 265 | |
| 266 | DDL("something").execute_if(dialect="postgresql") |
| 267 | |
| 268 | If a tuple, specifies multiple dialect names:: |
| 269 | |
| 270 | DDL("something").execute_if(dialect=("postgresql", "mysql")) |
| 271 | |
| 272 | :param callable\_: A callable, which will be invoked with |
| 273 | three positional arguments as well as optional keyword |
| 274 | arguments: |
| 275 | |
| 276 | :ddl: |
| 277 | This DDL element. |
| 278 | |
| 279 | :target: |
| 280 | The :class:`_schema.Table` or :class:`_schema.MetaData` |
| 281 | object which is the |
| 282 | target of this event. May be None if the DDL is executed |
| 283 | explicitly. |
| 284 | |
| 285 | :bind: |
| 286 | The :class:`_engine.Connection` being used for DDL execution. |
| 287 | May be None if this construct is being created inline within |
| 288 | a table, in which case ``compiler`` will be present. |
| 289 | |
| 290 | :tables: |
| 291 | Optional keyword argument - a list of Table objects which are to |
| 292 | be created/ dropped within a MetaData.create_all() or drop_all() |
| 293 | method call. |
| 294 | |
| 295 | :dialect: keyword argument, but always present - the |
| 296 | :class:`.Dialect` involved in the operation. |
| 297 | |
| 298 | :compiler: keyword argument. Will be ``None`` for an engine |
| 299 | level DDL invocation, but will refer to a :class:`.DDLCompiler` |
| 300 | if this DDL element is being created inline within a table. |
| 301 |