engine = create_engine('mysql://scott:tiger@localhost/test')
-The typical usage of :func:`_sa.create_engine()` is once per particular database
+The typical usage of :func:`_sa.create_engine` is once per particular database
URL, held globally for the lifetime of a single application process. A single
:class:`_engine.Engine` manages many individual :term:`DBAPI` connections on behalf of
the process and is intended to be called upon in a concurrent fashion. The
in the execution for the ``counter`` column, plus the number 12.
For a single statement that is being executed using "executemany" style, e.g.
-with multiple parameter sets passed to :meth:`_engine.Connection.execute`, the user-
-defined function is called once for each set of parameters. For the use case of
+with multiple parameter sets passed to :meth:`_engine.Connection.execute`, the
+user-defined function is called once for each set of parameters. For the use case of
a multi-valued :class:`_expression.Insert` construct (e.g. with more than one VALUES
clause set up via the :meth:`_expression.Insert.values` method), the user-defined function
is also called once for each set of parameters.
:meth:`_engine.CursorResult.last_updated_params` collections on
:class:`~sqlalchemy.engine.CursorResult`. The
:attr:`_engine.CursorResult.inserted_primary_key` collection contains a list of primary
-key values for the row inserted (a list so that single-column and composite-
-column primary keys are represented in the same format).
+key values for the row inserted (a list so that single-column and
+composite-column primary keys are represented in the same format).
.. _server_defaults:
PostgreSQL's SERIAL datatype is an auto-incrementing type that implies
the implicit creation of a PostgreSQL sequence when CREATE TABLE is emitted.
If a :class:`_schema.Column` specifies an explicit :class:`.Sequence` object
-which also specifies a true value for the :paramref:`.Sequence.optional`
+which also specifies a ``True`` value for the :paramref:`.Sequence.optional`
boolean flag, the :class:`.Sequence` will not take effect under PostgreSQL,
and the SERIAL datatype will proceed normally. Instead, the :class:`.Sequence`
will only take effect when used against other sequence-supporting
>>> row._mapping[addresses.c.email_address]
'jack@yahoo.com'
-If on the other hand we used a string column key, the usual rules of name-
-based matching still apply, and we'd get an ambiguous column error for
+If on the other hand we used a string column key, the usual rules of
+name-based matching still apply, and we'd get an ambiguous column error for
the ``id`` value::
>>> row._mapping["id"]
Given a string `table_name` and an optional string `schema`, return
check constraint information as a list of dicts with these keys:
- name
+ * ``name`` -
the check constraint's name
- sqltext
+ * ``sqltext`` -
the check constraint's SQL expression
- \**kw
+ * ``**kw`` -
other options passed to the dialect's get_check_constraints()
method.
"""convert the given name to lowercase if it is detected as
case insensitive.
- this method is only used if the dialect defines
+ This method is only used if the dialect defines
requires_name_normalize=True.
"""
"""convert the given name to a case insensitive identifier
for the backend if it is an all-lowercase name.
- this method is only used if the dialect defines
+ This method is only used if the dialect defines
requires_name_normalize=True.
"""
:meth:`_reflection.Inspector.get_table_names`
:func:`.sort_tables_and_constraints` - similar method which works
- with an already-given :class:`_schema.MetaData`.
+ with an already-given :class:`_schema.MetaData`.
"""
] + [(None, list(remaining_fkcs))]
def get_temp_table_names(self):
- """return a list of temporary table names for the current bind.
+ """Return a list of temporary table names for the current bind.
This method is unsupported by most dialects; currently
only SQLite implements it.
)
def get_temp_view_names(self):
- """return a list of temporary view names for the current bind.
+ """Return a list of temporary view names for the current bind.
This method is unsupported by most dialects; currently
only SQLite implements it.
Given a string `table_name`, and an optional string `schema`, return
primary key information as a dictionary with these keys:
- constrained_columns
+ * ``constrained_columns`` -
a list of column names that make up the primary key
- name
+ * ``name`` -
optional name of the primary key constraint.
:param table_name: string name of the table. For special quoting,
Given a string `table_name`, and an optional string `schema`, return
foreign key information as a list of dicts with these keys:
- constrained_columns
+ * ``constrained_columns`` -
a list of column names that make up the foreign key
- referred_schema
+ * ``referred_schema`` -
the name of the referred schema
- referred_table
+ * ``referred_table`` -
the name of the referred table
- referred_columns
+ * ``referred_columns`` -
a list of column names in the referred table that correspond to
constrained_columns
- name
+ * ``name`` -
optional name of the foreign key constraint.
:param table_name: string name of the table. For special quoting,
Given a string `table_name` and an optional string `schema`, return
index information as a list of dicts with these keys:
- name
+ * ``name`` -
the index's name
- column_names
+ * ``column_names`` -
list of column names in order
- unique
+ * ``unique`` -
boolean
- column_sorting
+ * ``column_sorting`` -
optional dict mapping column names to tuple of sort keywords,
which may include ``asc``, ``desc``, ``nullsfirst``, ``nullslast``.
.. versionadded:: 1.3.5
- dialect_options
+ * ``dialect_options`` -
dict of dialect-specific index options. May not be present
for all dialects.
Given a string `table_name` and an optional string `schema`, return
unique constraint information as a list of dicts with these keys:
- name
+ * ``name`` -
the unique constraint's name
- column_names
+ * ``column_names`` -
list of column names in order
:param table_name: string name of the table. For special quoting,
Given a string ``table_name`` and an optional string ``schema``,
return table comment information as a dictionary with these keys:
- text
+ * ``text`` -
text of the comment.
Raises ``NotImplementedError`` for a dialect that does not support
Given a string `table_name` and an optional string `schema`, return
check constraint information as a list of dicts with these keys:
- name
+ * ``name`` -
the check constraint's name
- sqltext
+ * ``sqltext`` -
the check constraint's SQL expression
- dialect_options
+ * ``dialect_options`` -
may or may not be present; a dictionary with additional
dialect-specific options for this CHECK constraint
resolve_fks=True,
_extend_on=None,
):
- """Given a Table object, load its internal constructs based on
- introspection.
+ """Given a :class:`_schema.Table` object, load its internal
+ constructs based on introspection.
This is the underlying method used by most dialects to produce
table reflection. Direct usage is like::
resolved through any of the optional keyword arguments. This
ultimately makes usage of the :meth:`.get_bind` method for resolution.
- :param bind_arguments: dictionary of bind arguments. May include
+ :param bind_arguments: dictionary of bind arguments. May include
"mapper", "bind", "clause", other custom arguments that are passed
to :meth:`.Session.get_bind`.
``.bind`` property.
:param target:
- Optional, defaults to None. The target SchemaItem for the
- execute call. Will be passed to the ``on`` callable if any,
- and may also provide string expansion data for the
- statement. See ``execute_at`` for more information.
+ Optional, defaults to None. The target :class:`_schema.SchemaItem`
+ for the execute call. Will be passed to the ``on`` callable if any,
+ and may also provide string expansion data for the statement.
+ See ``execute_at`` for more information.
"""
set during the call to ``create()``, ``create_all()``,
``drop()``, ``drop_all()``.
- If the callable returns a true value, the DDL statement will be
+ If the callable returns a True value, the DDL statement will be
executed.
:param state: any value which will be passed to the callable\_
def sort_tables(
tables, skip_fn=None, extra_dependencies=None,
):
- """sort a collection of :class:`_schema.Table` objects based on dependency
- .
+ """Sort a collection of :class:`_schema.Table` objects based on
+ dependency.
This is a dependency-ordered sort which will emit :class:`_schema.Table`
objects such that they will follow their dependent :class:`_schema.Table`
def sort_tables_and_constraints(
tables, filter_fn=None, extra_dependencies=None, _warn_for_cycles=False
):
- """sort a collection of :class:`_schema.Table` /
+ """Sort a collection of :class:`_schema.Table` /
:class:`_schema.ForeignKeyConstraint`
objects.
@classmethod
def and_(cls, *clauses):
- """Produce a conjunction of expressions joined by ``AND``.
+ r"""Produce a conjunction of expressions joined by ``AND``.
E.g.::
times against a statement, which will have the effect of each
clause being combined using :func:`.and_`::
- stmt = (
- select([users_table]).
- where(users_table.c.name == 'wendy').
- where(users_table.c.enrolled == True)
- )
+ stmt = select([users_table]).\
+ where(users_table.c.name == 'wendy').\
+ where(users_table.c.enrolled == True)
The :func:`.and_` construct must be given at least one positional
argument in order to be valid; a :func:`.and_` construct with no
:param implicit_returning: True by default - indicates that
RETURNING can be used by default to fetch newly inserted primary key
values, for backends which support this. Note that
- create_engine() also provides an implicit_returning flag.
+ :func:`_sa.create_engine` also provides an ``implicit_returning``
+ flag.
:param include_columns: A list of strings indicating a subset of
columns to be loaded via the ``autoload`` operation; table columns who
:ref:`server_defaults` - complete discussion of server side
defaults
- :param server_onupdate: A :class:`.FetchedValue` instance
- representing a database-side default generation function,
- such as a trigger. This
- indicates to SQLAlchemy that a newly generated value will be
- available after updates. This construct does not actually
- implement any kind of generation function within the database,
- which instead must be specified separately.
+ :param server_onupdate: A :class:`.FetchedValue` instance
+ representing a database-side default generation function,
+ such as a trigger. This
+ indicates to SQLAlchemy that a newly generated value will be
+ available after updates. This construct does not actually
+ implement any kind of generation function within the database,
+ which instead must be specified separately.
.. seealso::
def copy(self, **kw):
"""Create a copy of this ``Column``, uninitialized.
- This is used in ``Table.tometadata``.
+ This is used in :meth:`_schema.Table.tometadata`.
"""
or minvalue has been reached.
:param cache: optional integer value; number of future values in the
sequence which are calculated in advance.
- :param order: optional boolean value; if true, renders the
+ :param order: optional boolean value; if ``True``, renders the
ORDER keyword.
:param data_type: The type to be returned by the sequence.
.. versionadded:: 1.1.12
- :param order: optional boolean value; if true, renders the
+ :param order: optional boolean value; if ``True``, renders the
ORDER keyword, understood by Oracle, indicating the sequence is
definitively ordered. May be necessary to provide deterministic
ordering using Oracle RAC.
This list is either the original string arguments sent
to the constructor of the :class:`_schema.ForeignKeyConstraint`,
or if the constraint has been initialized with :class:`_schema.Column`
- objects, is the string .key of each element.
+ objects, is the string ``.key`` of each element.
.. versionadded:: 1.0.0
:param bind:
An Engine or Connection to bind to. May also be a string or URL
- instance, these are passed to create_engine() and this MetaData will
+ instance, these are passed to :func:`_sa.create_engine` and
+ this :class:`_schema.MetaData` will
be bound to the resulting engine.
:param reflect:
Optional, automatically load all tables from the bound database.
- Defaults to False. ``bind`` is required when this option is set.
+ Defaults to False. :paramref:`_schema.MetaData.bind` is required
+ when this option is set.
:param schema:
The default schema to use for the :class:`_schema.Table`,
Optional, controls how this column should be persisted by the
database. Possible values are:
- * None, the default, it will use the default persistence defined
- by the database.
- * True, will render ``GENERATED ALWAYS AS ... STORED``, or the
- equivalent for the target database if supported
- * False, will render ``GENERATED ALWAYS AS ... VIRTUAL``, or the
+ * ``None``, the default, it will use the default persistence
+ defined by the database.
+ * ``True``, will render ``GENERATED ALWAYS AS ... STORED``, or the
equivalent for the target database if supported.
+ * ``False``, will render ``GENERATED ALWAYS AS ... VIRTUAL``, or
+ the equivalent for the target database if supported.
Specifying ``True`` or ``False`` may raise an error when the DDL
- is emitted to the target database if the databse does not support
+ is emitted to the target database if the database does not support
that persistence option. Leaving this parameter at its default
of ``None`` is guaranteed to succeed for all databases that support
``GENERATED ALWAYS AS``.
:attr:`_expression.Selectable.exported_columns` - the
:class:`_expression.ColumnCollection`
- that is used for the operation
+ that is used for the operation.
:meth:`_expression.ColumnCollection.corresponding_column`
- implementation
@util.memoized_property
def primary_key(self):
- """Return the collection of Column objects which comprise the
- primary key of this FromClause."""
+ """Return the collection of :class:`_schema.Column` objects
+ which comprise the primary key of this FromClause.
+ """
self._init_collections()
self._populate_column_collection()
return self.primary_key
@util.memoized_property
def foreign_keys(self):
- """Return the collection of ForeignKey objects which this
- FromClause references."""
+ """Return the collection of :class:`_schema.ForeignKey` objects
+ which this FromClause references.
+ """
self._init_collections()
self._populate_column_collection()
return self.foreign_keys