]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
more docs for using psycopg2 range types, specifically instantiating models with...
authorChris Withers <chris@withers.org>
Sun, 25 May 2014 14:46:31 +0000 (15:46 +0100)
committerChris Withers <chris@withers.org>
Sun, 25 May 2014 14:46:31 +0000 (15:46 +0100)
doc/build/conf.py
doc/build/dialects/postgresql.rst

index 1b70bce70200188de2fef83e49957589f18975a7..6db777d96bc2a0e90a88633f7f81b3e1b9899af0 100644 (file)
@@ -324,4 +324,5 @@ epub_copyright = u'2007-2014, SQLAlchemy authors'
 
 intersphinx_mapping = {
     'alembic': ('http://alembic.readthedocs.org/en/latest/', None),
+    'psycopg2': ('http://pythonhosted.org/psycopg2', None),
 }
index 05b63506ee6de49b6d04a8f2fd91ac6c81b40423..c466f0377124e35db703b52edabf407e16c61903 100644 (file)
@@ -126,6 +126,33 @@ mixin:
   ``psycopg2``, it's recommended to upgrade to version 2.5 or later
   before using these column types.
 
+When instantiating models that use these column types, you should pass
+whatever data type is expected by the DBAPI driver you're using for
+the column type. For :mod:`psycopg2` these are
+:class:`~psycopg2.extras.NumericRange`,
+:class:`~psycopg2.extras.DateRange`,
+:class:`~psycopg2.extras.DateTimeRange` and
+:class:`~psycopg2.extras.DateTimeTZRange` or the class you've
+registered with :func:`~psycopg2.extras.register_range`.
+
+For example:
+
+.. code-block:: python
+
+  from psycopg2.extras import DateTimeRange
+  from sqlalchemy.dialects.postgresql import TSRANGE
+    
+  class RoomBooking(Base):
+
+      __tablename__ = 'room_booking'
+
+      room = Column(Integer(), primary_key=True)
+      during = Column(TSRANGE())
+
+  booking = RoomBooking(
+      room=101, 
+      during=DateTimeRange(datetime(2013, 3, 23), None
+  )
 
 PostgreSQL Constraint Types
 ---------------------------
@@ -140,7 +167,9 @@ For example::
 
   from sqlalchemy.dialects.postgresql import ExcludeConstraint, TSRANGE
 
-  class RoomBookings(Base):
+  class RoomBooking(Base):
+
+      __tablename__ = 'room_booking'
 
       room = Column(Integer(), primary_key=True)
       during = Column(TSRANGE())