summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-09-04 19:59:21 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-09-04 19:59:21 -0400
commitb42cbed42765cd00962868c248cee4b1b448c948 (patch)
tree755f90b6aa04f8d7bb8c45f0b293272eec4bab7b /lib/sqlalchemy
parenta315c5d431cf0598448a789d71aae7e2903dab32 (diff)
downloadsqlalchemy-b42cbed42765cd00962868c248cee4b1b448c948.tar.gz
almost through.
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/ext/compiler.py2
-rw-r--r--lib/sqlalchemy/ext/sqlsoup.py10
-rw-r--r--lib/sqlalchemy/orm/__init__.py3
-rw-r--r--lib/sqlalchemy/orm/interfaces.py13
-rw-r--r--lib/sqlalchemy/orm/query.py9
-rw-r--r--lib/sqlalchemy/orm/session.py72
-rw-r--r--lib/sqlalchemy/schema.py72
-rw-r--r--lib/sqlalchemy/types.py12
8 files changed, 111 insertions, 82 deletions
diff --git a/lib/sqlalchemy/ext/compiler.py b/lib/sqlalchemy/ext/compiler.py
index 12f1e443d..1bf4b1447 100644
--- a/lib/sqlalchemy/ext/compiler.py
+++ b/lib/sqlalchemy/ext/compiler.py
@@ -119,6 +119,8 @@ overriding routine and cause an endless loop. Such as, to add "prefix" to all
The above compiler will prefix all INSERT statements with "some prefix" when compiled.
+.. _type_compilation_extension:
+
Changing Compilation of Types
=============================
diff --git a/lib/sqlalchemy/ext/sqlsoup.py b/lib/sqlalchemy/ext/sqlsoup.py
index e54cde3ed..e8234e7c7 100644
--- a/lib/sqlalchemy/ext/sqlsoup.py
+++ b/lib/sqlalchemy/ext/sqlsoup.py
@@ -3,7 +3,15 @@ Introduction
============
SqlSoup provides a convenient way to access existing database tables without
-having to declare table or mapper classes ahead of time. It is built on top of the SQLAlchemy ORM and provides a super-minimalistic interface to an existing database.
+having to declare table or mapper classes ahead of time. It is built on top of
+the SQLAlchemy ORM and provides a super-minimalistic interface to an existing
+database.
+
+SqlSoup effectively provides a coarse grained, alternative interface to
+working with the SQLAlchemy ORM, providing a "self configuring" interface
+for extremely rudimental operations. It's somewhat akin to a
+"super novice mode" version of the ORM. While SqlSoup can be very handy,
+users are strongly encouraged to use the full ORM for non-trivial applications.
Suppose we have a database with users, books, and loans tables
(corresponding to the PyWebOff dataset, if you're curious).
diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py
index 9200b52fd..e59c5863b 100644
--- a/lib/sqlalchemy/orm/__init__.py
+++ b/lib/sqlalchemy/orm/__init__.py
@@ -1150,6 +1150,9 @@ def contains_eager(*keys, **kwargs):
See also :func:`eagerload` for the "automatic" version of this
functionality.
+ For additional examples of :func:`contains_eager` see
+ :ref:`contains_eager`.
+
"""
alias = kwargs.pop('alias', None)
if kwargs:
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index b71ec4db5..0a65c8a44 100644
--- a/lib/sqlalchemy/orm/interfaces.py
+++ b/lib/sqlalchemy/orm/interfaces.py
@@ -51,7 +51,7 @@ MANYTOMANY = util.symbol('MANYTOMANY')
class MapperExtension(object):
"""Base implementation for customizing ``Mapper`` behavior.
-
+
New extension classes subclass ``MapperExtension`` and are specified
using the ``extension`` mapper() argument, which is a single
``MapperExtension`` or a list of such. A single mapper
@@ -74,8 +74,9 @@ class MapperExtension(object):
when this symbol is returned. Like EXT_CONTINUE, it also
has additional significance in some cases that a default
mapper activity will not be performed.
-
+
"""
+
def instrument_class(self, mapper, class_):
"""Receive a class when the mapper is first constructed, and has
applied instrumentation to the mapped class.
@@ -185,7 +186,7 @@ class MapperExtension(object):
\**flags
extra information about the row, same as criterion in
``create_row_processor()`` method of
- :class:`~sqlalchemy.orm.interfaces.MapperProperty`
+ :class:`~sqlalchemy.orm.interfaces.MapperProperty`
"""
return EXT_CONTINUE
@@ -324,10 +325,10 @@ class MapperExtension(object):
def after_delete(self, mapper, connection, instance):
"""Receive an object instance after that instance is deleted.
-
- The return value is only significant within the ``MapperExtension``
+
+ The return value is only significant within the ``MapperExtension``
chain; the parent mapper's behavior isn't modified by this method.
-
+
"""
return EXT_CONTINUE
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index fdc426a07..41e9a4890 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -779,8 +779,13 @@ class Query(object):
def options(self, *args):
"""Return a new Query object, applying the given list of
- MapperOptions.
-
+ mapper options.
+
+ Most supplied options regard changing how column- and
+ relationship-mapped attributes are loaded. See the sections
+ :ref:`deferred` and :ref:`loading_toplevel` for reference
+ documentation.
+
"""
return self._options(False, *args)
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 4727de218..d906df2a3 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -446,71 +446,8 @@ class SessionTransaction(object):
class Session(object):
"""Manages persistence operations for ORM-mapped objects.
- The Session is the front end to SQLAlchemy's **Unit of Work**
- implementation. The concept behind Unit of Work is to track modifications
- to a field of objects, and then be able to flush those changes to the
- database in a single operation.
-
- SQLAlchemy's unit of work includes these functions:
-
- * The ability to track in-memory changes on scalar- and collection-based
- object attributes, such that database persistence operations can be
- assembled based on those changes.
-
- * The ability to organize individual SQL queries and population of newly
- generated primary and foreign key-holding attributes during a persist
- operation such that referential integrity is maintained at all times.
-
- * The ability to maintain insert ordering against the order in which new
- instances were added to the session.
-
- * An Identity Map, which is a dictionary keying instances to their unique
- primary key identity. This ensures that only one copy of a particular
- entity is ever present within the session, even if repeated load
- operations for the same entity occur. This allows many parts of an
- application to get a handle to a particular object without any chance of
- modifications going to two different places.
-
- When dealing with instances of mapped classes, an instance may be
- *attached* to a particular Session, else it is *unattached* . An instance
- also may or may not correspond to an actual row in the database. These
- conditions break up into four distinct states:
-
- * *Transient* - an instance that's not in a session, and is not saved to
- the database; i.e. it has no database identity. The only relationship
- such an object has to the ORM is that its class has a ``mapper()``
- associated with it.
-
- * *Pending* - when you ``add()`` a transient instance, it becomes
- pending. It still wasn't actually flushed to the database yet, but it
- will be when the next flush occurs.
-
- * *Persistent* - An instance which is present in the session and has a
- record in the database. You get persistent instances by either flushing
- so that the pending instances become persistent, or by querying the
- database for existing instances (or moving persistent instances from
- other sessions into your local session).
-
- * *Detached* - an instance which has a record in the database, but is not
- in any session. Theres nothing wrong with this, and you can use objects
- normally when they're detached, **except** they will not be able to
- issue any SQL in order to load collections or attributes which are not
- yet loaded, or were marked as "expired".
-
- The session methods which control instance state include :meth:`.Session.add`,
- :meth:`.Session.delete`, :meth:`.Session.merge`, and :meth:`.Session.expunge`.
-
- The Session object is generally **not** threadsafe. A session which is
- set to ``autocommit`` and is only read from may be used by concurrent
- threads if it's acceptable that some object instances may be loaded twice.
-
- The typical pattern to managing Sessions in a multi-threaded environment
- is either to use mutexes to limit concurrent access to one thread at a
- time, or more commonly to establish a unique session for every thread,
- using a threadlocal variable. SQLAlchemy provides a thread-managed
- Session adapter, provided by the :func:`~sqlalchemy.orm.scoped_session`
- function.
-
+ The Session's usage paradigm is described at :ref:`session_toplevel`.
+
"""
public_methods = (
@@ -529,8 +466,9 @@ class Session(object):
query_cls=query.Query):
"""Construct a new Session.
- Arguments to ``Session`` are described using the
- :func:`~sqlalchemy.orm.sessionmaker` function.
+ Arguments to :class:`.Session` are described using the
+ :func:`.sessionmaker` function, which is the
+ typical point of entry.
"""
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py
index 5b5983858..b01d815a9 100644
--- a/lib/sqlalchemy/schema.py
+++ b/lib/sqlalchemy/schema.py
@@ -450,8 +450,22 @@ class Table(SchemaItem, expression.TableClause):
def tometadata(self, metadata, schema=RETAIN_SCHEMA):
- """Return a copy of this ``Table`` associated with a different
- ``MetaData``."""
+ """Return a copy of this :class:`Table` associated with a different
+ :class:`MetaData`.
+
+ E.g.::
+
+ # create two metadata
+ meta1 = MetaData('sqlite:///querytest.db')
+ meta2 = MetaData()
+
+ # load 'users' from the sqlite engine
+ users_table = Table('users', meta1, autoload=True)
+
+ # create the same Table object for the plain metadata
+ users_table_2 = users_table.tometadata(meta2)
+
+ """
try:
if schema is RETAIN_SCHEMA:
@@ -1243,7 +1257,23 @@ class DefaultGenerator(SchemaItem):
class ColumnDefault(DefaultGenerator):
"""A plain default value on a column.
- This could correspond to a constant, a callable function, or a SQL clause.
+ This could correspond to a constant, a callable function,
+ or a SQL clause.
+
+ :class:`.ColumnDefault` is generated automatically
+ whenever the ``default``, ``onupdate`` arguments of
+ :class:`.Column` are used. A :class:`.ColumnDefault`
+ can be passed positionally as well.
+
+ For example, the following::
+
+ Column('foo', Integer, default=50)
+
+ Is equivalent to::
+
+ Column('foo', Integer, ColumnDefault(50))
+
+
"""
def __init__(self, arg, **kwargs):
@@ -1374,7 +1404,20 @@ class Sequence(DefaultGenerator):
class FetchedValue(object):
- """A default that takes effect on the database side."""
+ """A marker for a transparent database-side default.
+
+ Use :class:`.FetchedValue` when the database is configured
+ to provide some automatic default for a column.
+
+ E.g.::
+
+ Column('foo', Integer, FetchedValue())
+
+ Would indicate that some trigger or default generator
+ will create a new value for the ``foo`` column during an
+ INSERT.
+
+ """
def __init__(self, for_update=False):
self.for_update = for_update
@@ -1391,7 +1434,26 @@ class FetchedValue(object):
class DefaultClause(FetchedValue):
- """A DDL-specified DEFAULT column value."""
+ """A DDL-specified DEFAULT column value.
+
+ :class:`.DefaultClause` is a :class:`.FetchedValue`
+ that also generates a "DEFAULT" clause when
+ "CREATE TABLE" is emitted.
+
+ :class:`.DefaultClause` is generated automatically
+ whenever the ``server_default``, ``server_onupdate`` arguments of
+ :class:`.Column` are used. A :class:`.DefaultClause`
+ can be passed positionally as well.
+
+ For example, the following::
+
+ Column('foo', Integer, server_default="50")
+
+ Is equivalent to::
+
+ Column('foo', Integer, DefaultClause("50"))
+
+ """
def __init__(self, arg, for_update=False):
util.assert_arg_type(arg, (basestring,
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index f00cc2e3c..a3769dcd6 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -485,6 +485,14 @@ class TypeDecorator(AbstractType):
return self.impl.compare_values(x, y)
def is_mutable(self):
+ """Return True if the target Python type is 'mutable'.
+
+ When this method is overridden, :meth:`copy_value` should
+ also be supplied. The :class:`.MutableType` mixin
+ is recommended as a helper.
+
+ """
+
return self.impl.is_mutable()
def _adapt_expression(self, op, othertype):
@@ -562,7 +570,9 @@ class MutableType(object):
"""
def is_mutable(self):
- """Return True, mutable."""
+ """Return True if the target Python type is 'mutable'.
+
+ """
return True
def copy_value(self, value):