pir_pipeline.utils.sql_alchemy_view.DropView¶
- class pir_pipeline.utils.sql_alchemy_view.DropView(name)¶
Bases:
ExecutableDDLElement
Class for dropping a view
- __init__(name)¶
Methods
__init__
(name)against
(target)Return a copy of this
_schema.ExecutableDDLElement
which will include the given target.compare
(other, **kw)Compare this
_expression.ClauseElement
to the given_expression.ClauseElement
.compile
([bind, dialect])Compile this SQL expression.
execute_if
([dialect, callable_, state])Return a callable that will execute this
_ddl.ExecutableDDLElement
conditionally within an event handler.execution_options
(**kw)Set non-SQL options for the statement which take effect during execution.
get_children
(*[, omit_attrs])Return immediate child
visitors.HasTraverseInternals
elements of thisvisitors.HasTraverseInternals
.Get the non-SQL options which will take effect during execution.
memoized_instancemethod
(fn)Decorate a method memoize its return value.
options
(*options)Apply options to this statement.
params
([_ClauseElement__optionaldict])Return a copy with
_expression.bindparam()
elements replaced.self_group
([against])Apply a 'grouping' to this
_expression.ClauseElement
.unique_params
([_ClauseElement__optionaldict])Return a copy with
_expression.bindparam()
elements replaced.Attributes
allows_lambda
description
entity_namespace
Indicate if this
HasCacheKey
instance should make use of the cache key generation scheme used by its immediate superclass.is_clause_element
is_delete
is_dml
is_from_statement
is_insert
is_select
is_selectable
is_text
is_update
stringify_dialect
supports_execution
target
uses_inspection
negation_clause
proxy_set
- against(target: SchemaItem) Self ¶
Return a copy of this
_schema.ExecutableDDLElement
which will include the given target.This essentially applies the given item to the
.target
attribute of the returned_schema.ExecutableDDLElement
object. This target is then usable by event handlers and compilation routines in order to provide services such as tokenization of a DDL string in terms of a particular_schema.Table
.When a
_schema.ExecutableDDLElement
object is established as an event handler for the_events.DDLEvents.before_create()
or_events.DDLEvents.after_create()
events, and the event then occurs for a given target such as a_schema.Constraint
or_schema.Table
, that target is established with a copy of the_schema.ExecutableDDLElement
object using this method, which then proceeds to the_schema.ExecutableDDLElement.execute()
method in order to invoke the actual DDL instruction.- Parameters:
target – a
_schema.SchemaItem
that will be the subject of a DDL operation.- Returns:
a copy of this
_schema.ExecutableDDLElement
with the.target
attribute assigned to the given_schema.SchemaItem
.
See also
_schema.DDL
- uses tokenization against the “target” when processing the DDL string.
- compare(other: ClauseElement, **kw: Any) bool ¶
Compare this
_expression.ClauseElement
to the given_expression.ClauseElement
.Subclasses should override the default behavior, which is a straight identity comparison.
**kw are arguments consumed by subclass
compare()
methods and may be used to modify the criteria for comparison (see_expression.ColumnElement
).
- compile(bind: _HasDialect | None = None, dialect: Dialect | None = None, **kw: Any) Compiled ¶
Compile this SQL expression.
The return value is a
Compiled
object. Callingstr()
orunicode()
on the returned value will yield a string representation of the result. TheCompiled
object also can return a dictionary of bind parameter names and values using theparams
accessor.- Parameters:
bind – An
Connection
orEngine
which can provide aDialect
in order to generate aCompiled
object. If thebind
anddialect
parameters are both omitted, a default SQL compiler is used.column_keys – Used for INSERT and UPDATE statements, a list of column names which should be present in the VALUES clause of the compiled statement. If
None
, all columns from the target table object are rendered.dialect – A
Dialect
instance which can generate aCompiled
object. This argument takes precedence over thebind
argument.compile_kwargs –
optional dictionary of additional parameters that will be passed through to the compiler within all “visit” methods. This allows any custom flag to be passed through to a custom compilation construct, for example. It is also used for the case of passing the
literal_binds
flag through:from sqlalchemy.sql import table, column, select t = table("t", column("x")) s = select(t).where(t.c.x == 5) print(s.compile(compile_kwargs={"literal_binds": True}))
See also
faq_sql_expression_string
- execute_if(dialect: str | None = None, callable_: DDLIfCallable | None = None, state: Any | None = None) Self ¶
Return a callable that will execute this
_ddl.ExecutableDDLElement
conditionally within an event handler.Used to provide a wrapper for event listening:
event.listen( metadata, "before_create", DDL("my_ddl").execute_if(dialect="postgresql"), )
- Parameters:
dialect –
May be a string or tuple of strings. If a string, it will be compared to the name of the executing database dialect:
DDL("something").execute_if(dialect="postgresql")
If a tuple, specifies multiple dialect names:
DDL("something").execute_if(dialect=("postgresql", "mysql"))
callable_ –
A callable, which will be invoked with three positional arguments as well as optional keyword arguments:
- ddl:
This DDL element.
- target:
The
_schema.Table
or_schema.MetaData
object which is the target of this event. May be None if the DDL is executed explicitly.- bind:
The
_engine.Connection
being used for DDL execution. May be None if this construct is being created inline within a table, in which casecompiler
will be present.- tables:
Optional keyword argument - a list of Table objects which are to be created/ dropped within a MetaData.create_all() or drop_all() method call.
- dialect:
keyword argument, but always present - the
Dialect
involved in the operation.- compiler:
keyword argument. Will be
None
for an engine level DDL invocation, but will refer to aDDLCompiler
if this DDL element is being created inline within a table.- state:
Optional keyword argument - will be the
state
argument passed to this function.- checkfirst:
Keyword argument, will be True if the ‘checkfirst’ flag was set during the call to
create()
,create_all()
,drop()
,drop_all()
.
If the callable returns a True value, the DDL statement will be executed.
state – any value which will be passed to the callable_ as the
state
keyword argument.
See also
SchemaItem.ddl_if()
DDLEvents
event_toplevel
- execution_options(**kw: Any) Self ¶
Set non-SQL options for the statement which take effect during execution.
Execution options can be set at many scopes, including per-statement, per-connection, or per execution, using methods such as
_engine.Connection.execution_options()
and parameters which accept a dictionary of options such as :paramref:`_engine.Connection.execute.execution_options` and :paramref:`_orm.Session.execute.execution_options`.The primary characteristic of an execution option, as opposed to other kinds of options such as ORM loader options, is that execution options never affect the compiled SQL of a query, only things that affect how the SQL statement itself is invoked or how results are fetched. That is, execution options are not part of what’s accommodated by SQL compilation nor are they considered part of the cached state of a statement.
The
_sql.Executable.execution_options()
method is generative, as is the case for the method as applied to the_engine.Engine
and_orm.Query
objects, which means when the method is called, a copy of the object is returned, which applies the given parameters to that new copy, but leaves the original unchanged:statement = select(table.c.x, table.c.y) new_statement = statement.execution_options(my_option=True)
An exception to this behavior is the
_engine.Connection
object, where the_engine.Connection.execution_options()
method is explicitly not generative.The kinds of options that may be passed to
_sql.Executable.execution_options()
and other related methods and parameter dictionaries include parameters that are explicitly consumed by SQLAlchemy Core or ORM, as well as arbitrary keyword arguments not defined by SQLAlchemy, which means the methods and/or parameter dictionaries may be used for user-defined parameters that interact with custom code, which may access the parameters using methods such as_sql.Executable.get_execution_options()
and_engine.Connection.get_execution_options()
, or within selected event hooks using a dedicatedexecution_options
event parameter such as :paramref:`_events.ConnectionEvents.before_execute.execution_options` or_orm.ORMExecuteState.execution_options
, e.g.:from sqlalchemy import event @event.listens_for(some_engine, "before_execute") def _process_opt(conn, statement, multiparams, params, execution_options): "run a SQL function before invoking a statement" if execution_options.get("do_special_thing", False): conn.exec_driver_sql("run_special_function()")
Within the scope of options that are explicitly recognized by SQLAlchemy, most apply to specific classes of objects and not others. The most common execution options include:
:paramref:`_engine.Connection.execution_options.isolation_level` - sets the isolation level for a connection or a class of connections via an
_engine.Engine
. This option is accepted only by_engine.Connection
or_engine.Engine
.:paramref:`_engine.Connection.execution_options.stream_results` - indicates results should be fetched using a server side cursor; this option is accepted by
_engine.Connection
, by the :paramref:`_engine.Connection.execute.execution_options` parameter on_engine.Connection.execute()
, and additionally by_sql.Executable.execution_options()
on a SQL statement object, as well as by ORM constructs like_orm.Session.execute()
.:paramref:`_engine.Connection.execution_options.compiled_cache` - indicates a dictionary that will serve as the SQL compilation cache for a
_engine.Connection
or_engine.Engine
, as well as for ORM methods like_orm.Session.execute()
. Can be passed asNone
to disable caching for statements. This option is not accepted by_sql.Executable.execution_options()
as it is inadvisable to carry along a compilation cache within a statement object.:paramref:`_engine.Connection.execution_options.schema_translate_map` - a mapping of schema names used by the Schema Translate Map feature, accepted by
_engine.Connection
,_engine.Engine
,_sql.Executable
, as well as by ORM constructs like_orm.Session.execute()
.
See also
_engine.Connection.execution_options()
:paramref:`_engine.Connection.execute.execution_options`
:paramref:`_orm.Session.execute.execution_options`
orm_queryguide_execution_options - documentation on all ORM-specific execution options
- get_children(*, omit_attrs: Tuple[str, ...] = (), **kw: Any) Iterable[HasTraverseInternals] ¶
Return immediate child
visitors.HasTraverseInternals
elements of thisvisitors.HasTraverseInternals
.This is used for visit traversal.
**kw may contain flags that change the collection that is returned, for example to return a subset of items in order to cut down on larger traversals, or to return child items from a different context (such as schema-level collections instead of clause-level).
- get_execution_options() _ExecuteOptions ¶
Get the non-SQL options which will take effect during execution.
Added in version 1.3.
See also
Executable.execution_options()
- inherit_cache: bool | None = None¶
Indicate if this
HasCacheKey
instance should make use of the cache key generation scheme used by its immediate superclass.The attribute defaults to
None
, which indicates that a construct has not yet taken into account whether or not its appropriate for it to participate in caching; this is functionally equivalent to setting the value toFalse
, except that a warning is also emitted.This flag can be set to
True
on a particular class, if the SQL that corresponds to the object does not change based on attributes which are local to this class, and not its superclass.See also
compilerext_caching - General guideslines for setting the
HasCacheKey.inherit_cache
attribute for third-party or user defined SQL constructs.
- options(*options: ExecutableOption) Self ¶
Apply options to this statement.
In the general sense, options are any kind of Python object that can be interpreted by the SQL compiler for the statement. These options can be consumed by specific dialects or specific kinds of compilers.
The most commonly known kind of option are the ORM level options that apply “eager load” and other loading behaviors to an ORM query. However, options can theoretically be used for many other purposes.
For background on specific kinds of options for specific kinds of statements, refer to the documentation for those option objects.
Changed in version 1.4: - added
Executable.options()
to Core statement objects towards the goal of allowing unified Core / ORM querying capabilities.See also
loading_columns - refers to options specific to the usage of ORM queries
relationship_loader_options - refers to options specific to the usage of ORM queries
- params(_ClauseElement__optionaldict: Mapping[str, Any] | None = None, **kwargs: Any) Self ¶
Return a copy with
_expression.bindparam()
elements replaced.Returns a copy of this ClauseElement with
_expression.bindparam()
elements replaced with values taken from the given dictionary:>>> clause = column("x") + bindparam("foo") >>> print(clause.compile().params) {'foo':None} >>> print(clause.params({"foo": 7}).compile().params) {'foo':7}
- self_group(against: OperatorType | None = None) ClauseElement ¶
Apply a ‘grouping’ to this
_expression.ClauseElement
.This method is overridden by subclasses to return a “grouping” construct, i.e. parenthesis. In particular it’s used by “binary” expressions to provide a grouping around themselves when placed into a larger expression, as well as by
_expression.select()
constructs when placed into the FROM clause of another_expression.select()
. (Note that subqueries should be normally created using the_expression.Select.alias()
method, as many platforms require nested SELECT statements to be named).As expressions are composed together, the application of
self_group()
is automatic - end-user code should never need to use this method directly. Note that SQLAlchemy’s clause constructs take operator precedence into account - so parenthesis might not be needed, for example, in an expression likex OR (y AND z)
- AND takes precedence over OR.The base
self_group()
method of_expression.ClauseElement
just returns self.
- unique_params(_ClauseElement__optionaldict: Dict[str, Any] | None = None, **kwargs: Any) Self ¶
Return a copy with
_expression.bindparam()
elements replaced.Same functionality as
_expression.ClauseElement.params()
, except adds unique=True to affected bind parameters so that multiple statements can be used.