From: Mike Bayer Date: Mon, 28 Mar 2011 00:34:39 +0000 (-0400) Subject: - Documented SQLite DATE/TIME/DATETIME types. X-Git-Tag: rel_0_7b4~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d355a3be3b720764b9b5e2b3e1583a63b85c7766;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Documented SQLite DATE/TIME/DATETIME types. [ticket:2029] (also in 0.6.7) - add "currentmodule" directive to all the dialect type docs to ensure users import from the dialect package, not the "base" module --- diff --git a/CHANGES b/CHANGES index 15c0708701..5ec0dae420 100644 --- a/CHANGES +++ b/CHANGES @@ -50,6 +50,10 @@ CHANGES talking to cx_oracle. [ticket:2100] (Also in 0.6.7) +- documentation + - Documented SQLite DATE/TIME/DATETIME types. + [ticket:2029] (also in 0.6.7) + 0.7.0b3 ======= - general diff --git a/doc/build/dialects/drizzle.rst b/doc/build/dialects/drizzle.rst index 0857ca8598..ab1b703da3 100644 --- a/doc/build/dialects/drizzle.rst +++ b/doc/build/dialects/drizzle.rst @@ -17,6 +17,8 @@ valid with Drizzle are importable from the top level dialect:: Types which are specific to Drizzle, or have Drizzle-specific construction arguments, are as follows: +.. currentmodule:: sqlalchemy.dialects.drizzle + .. autoclass:: BIGINT :members: __init__ :show-inheritance: diff --git a/doc/build/dialects/mssql.rst b/doc/build/dialects/mssql.rst index 658ca8988f..3b67606021 100644 --- a/doc/build/dialects/mssql.rst +++ b/doc/build/dialects/mssql.rst @@ -20,6 +20,8 @@ they originate from :mod:`sqlalchemy.types` or from the local dialect:: Types which are specific to SQL Server, or have SQL Server-specific construction arguments, are as follows: +.. currentmodule:: sqlalchemy.dialects.mssql + .. autoclass:: BIT :members: __init__ :show-inheritance: diff --git a/doc/build/dialects/mysql.rst b/doc/build/dialects/mysql.rst index c8edbceab9..ff8f37bcb5 100644 --- a/doc/build/dialects/mysql.rst +++ b/doc/build/dialects/mysql.rst @@ -19,6 +19,8 @@ valid with MySQL are importable from the top level dialect:: Types which are specific to MySQL, or have MySQL-specific construction arguments, are as follows: +.. currentmodule:: sqlalchemy.dialects.mysql + .. autoclass:: BIGINT :members: __init__ :show-inheritance: diff --git a/doc/build/dialects/oracle.rst b/doc/build/dialects/oracle.rst index 363cebffd4..d5cd969ea4 100644 --- a/doc/build/dialects/oracle.rst +++ b/doc/build/dialects/oracle.rst @@ -19,6 +19,8 @@ they originate from :mod:`sqlalchemy.types` or from the local dialect:: Types which are specific to Oracle, or have Oracle-specific construction arguments, are as follows: +.. currentmodule:: sqlalchemy.dialects.oracle + .. autoclass:: BFILE :members: __init__ :show-inheritance: diff --git a/doc/build/dialects/postgresql.rst b/doc/build/dialects/postgresql.rst index 02e714b6a2..6e45992eb7 100644 --- a/doc/build/dialects/postgresql.rst +++ b/doc/build/dialects/postgresql.rst @@ -21,6 +21,8 @@ they originate from :mod:`sqlalchemy.types` or from the local dialect:: Types which are specific to PostgreSQL, or have PostgreSQL-specific construction arguments, are as follows: +.. currentmodule:: sqlalchemy.dialects.postgresql + .. autoclass:: ARRAY :members: __init__ :show-inheritance: diff --git a/doc/build/dialects/sqlite.rst b/doc/build/dialects/sqlite.rst index e331e7ba8e..21fd4e3aa5 100644 --- a/doc/build/dialects/sqlite.rst +++ b/doc/build/dialects/sqlite.rst @@ -17,6 +17,14 @@ they originate from :mod:`sqlalchemy.types` or from the local dialect:: INTEGER, NUMERIC, SMALLINT, TEXT, TIME, TIMESTAMP, \ VARCHAR +.. module:: sqlalchemy.dialects.sqlite + +.. autoclass:: DATETIME + +.. autoclass:: DATE + +.. autoclass:: TIME + Pysqlite -------- diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index eb7c6de21a..36357597cc 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -66,7 +66,6 @@ from sqlalchemy.types import BLOB, BOOLEAN, CHAR, DATE, DATETIME, DECIMAL,\ FLOAT, INTEGER, NUMERIC, SMALLINT, TEXT, TIME,\ TIMESTAMP, VARCHAR - class _DateTimeMixin(object): _reg = None _storage_format = None @@ -79,6 +78,41 @@ class _DateTimeMixin(object): self._storage_format = storage_format class DATETIME(_DateTimeMixin, sqltypes.DateTime): + """Represent a Python datetime object in SQLite using a string. + + The default string storage format is:: + + "%04d-%02d-%02d %02d:%02d:%02d.%06d" % (value.year, + value.month, value.day, + value.hour, value.minute, + value.second, value.microsecond) + + e.g.:: + + 2011-03-15 12:05:57.10558 + + The storage format can be customized to some degree using the + ``storage_format`` and ``regexp`` parameters, such as:: + + import re + from sqlalchemy.dialects.sqlite import DATETIME + + dt = DATETIME( + storage_format="%04d/%02d/%02d %02d-%02d-%02d-%06d", + regexp=re.compile("(\d+)/(\d+)/(\d+) (\d+)-(\d+)-(\d+)(?:-(\d+))?") + ) + + :param storage_format: format string which will be appled to the + tuple ``(value.year, value.month, value.day, value.hour, + value.minute, value.second, value.microsecond)``, given a + Python datetime.datetime() object. + + :param regexp: regular expression which will be applied to + incoming result rows. The resulting match object is appled to + the Python datetime() constructor via ``*map(int, + match_obj.groups(0))``. + """ + _storage_format = "%04d-%02d-%02d %02d:%02d:%02d.%06d" def bind_processor(self, dialect): @@ -108,6 +142,38 @@ class DATETIME(_DateTimeMixin, sqltypes.DateTime): return processors.str_to_datetime class DATE(_DateTimeMixin, sqltypes.Date): + """Represent a Python date object in SQLite using a string. + + The default string storage format is:: + + "%04d-%02d-%02d" % (value.year, value.month, value.day) + + e.g.:: + + 2011-03-15 + + The storage format can be customized to some degree using the + ``storage_format`` and ``regexp`` parameters, such as:: + + import re + from sqlalchemy.dialects.sqlite import DATE + + d = DATE( + storage_format="%02d/%02d/%02d", + regexp=re.compile("(\d+)/(\d+)/(\d+)") + ) + + :param storage_format: format string which will be appled to the + tuple ``(value.year, value.month, value.day)``, + given a Python datetime.date() object. + + :param regexp: regular expression which will be applied to + incoming result rows. The resulting match object is appled to + the Python date() constructor via ``*map(int, + match_obj.groups(0))``. + + """ + _storage_format = "%04d-%02d-%02d" def bind_processor(self, dialect): @@ -131,6 +197,40 @@ class DATE(_DateTimeMixin, sqltypes.Date): return processors.str_to_date class TIME(_DateTimeMixin, sqltypes.Time): + """Represent a Python time object in SQLite using a string. + + The default string storage format is:: + + "%02d:%02d:%02d.%06d" % (value.hour, value.minute, + value.second, + value.microsecond) + + e.g.:: + + 12:05:57.10558 + + The storage format can be customized to some degree using the + ``storage_format`` and ``regexp`` parameters, such as:: + + import re + from sqlalchemy.dialects.sqlite import TIME + + t = TIME( + storage_format="%02d-%02d-%02d-%06d", + regexp=re.compile("(\d+)-(\d+)-(\d+)-(?:-(\d+))?") + ) + + :param storage_format: format string which will be appled + to the tuple ``(value.hour, value.minute, value.second, + value.microsecond)``, given a Python datetime.time() object. + + :param regexp: regular expression which will be applied to + incoming result rows. The resulting match object is appled to + the Python time() constructor via ``*map(int, + match_obj.groups(0))``. + + """ + _storage_format = "%02d:%02d:%02d.%06d" def bind_processor(self, dialect):