More range type docs

This commit is contained in:
Konsta Vesterinen
2014-01-14 12:42:21 +02:00
parent 962eebf6e7
commit 1b12d049f4
4 changed files with 71 additions and 18 deletions

View File

@@ -95,15 +95,3 @@ UUIDType
.. autoclass:: UUIDType
Range types
^^^^^^^^^^^
IntRangeType
------------
.. module:: sqlalchemy_utils.types.range
.. autoclass:: IntRangeType

View File

@@ -10,6 +10,7 @@ SQLAlchemy-Utils provides custom data types and various utility functions for SQ
coercion
data_types
range_data_types
aggregates
decorators
generic_relationship

30
docs/range_data_types.rst Normal file
View File

@@ -0,0 +1,30 @@
Range data types
================
.. automodule:: sqlalchemy_utils.types.range
DateRangeType
^^^^^^^^^^^^^
.. autoclass:: DateRangeType
DateTimeRangeType
^^^^^^^^^^^^^^^^^
.. autoclass:: DateRangeType
IntRangeType
^^^^^^^^^^^^
.. autoclass:: IntRangeType
NumericRangeType
^^^^^^^^^^^^^^^^
.. autoclass:: NumericRangeType

View File

@@ -1,3 +1,23 @@
"""
SQLAlchemy-Utils provides wide variety of range data types. All range data types return
Interval objects of intervals_ package. In order to use range data types you need to install intervals_ with:
::
pip install intervals
Intervals package provides good chunk of additional interval operators that for example psycopg2 range objects do not support.
Some good reading for practical interval implementations:
http://wiki.postgresql.org/images/f/f0/Range-types.pdf
.. _intervals: https://github.com/kvesteri/intervals
"""
intervals = None
try:
import intervals
@@ -119,7 +139,9 @@ class RangeType(types.TypeDecorator, ScalarCoercible):
class IntRangeType(RangeType):
"""
IntRangeType provides way for saving range of numbers into database.
IntRangeType provides way for saving ranges of integers into database. On
PostgreSQL this type maps to native INT4RANGE type while on other drivers
this maps to simple string column.
Example::
@@ -158,12 +180,7 @@ class IntRangeType(RangeType):
)
print total
# '30-140'
Good reading:
http://wiki.postgresql.org/images/f/f0/Range-types.pdf
"""
impl = INT4RANGE
def __init__(self, *args, **kwargs):
@@ -173,6 +190,23 @@ class IntRangeType(RangeType):
class DateRangeType(RangeType):
"""
DateRangeType provides way for saving ranges of dates into database. On
PostgreSQL this type maps to native DATERANGE type while on other drivers
this maps to simple string column.
Example::
from sqlalchemy_utils import DateRangeType
class Reservation(Base):
__tablename__ = 'user'
id = sa.Column(sa.Integer, autoincrement=True)
room_id = sa.Column(sa.Integer))
during = sa.Column(DateRangeType)
"""
impl = DATERANGE
def __init__(self, *args, **kwargs):