On 4/24/15 9:09 AM, Dimitris Theodorou wrote:
Hi,
I am using psycopg2 and trying to put together a new daterange type
that combines the following:
1. A custom daterange class which provides various useful helpers
(backwards/forwards iteration, intersection).
2. The psycopg2 DateRange that fills in with some helpers of its own
(contains, comparisons) and takes care of marshaling the object
from/to the db
3. The DATERANGE sqlalchemy/postgres type to take care of emiting of
SQL operators and DDL, and so that I can use it both when querying and
when declaring Columns()
So my naive approach is the following, going by the guideline at
http://docs.sqlalchemy.org/en/latest/core/compiler.html#subclassing-guidelines:
|
|
|frompsycopg2.extras importDateRange
fromsqlalchemy.dialects.postgresql importDATERANGE
classMyDateRange(TypeDecorator,DateRange):
impl =DATERANGE
defintersection():
#...
|
|
|
OK well the type object we make here represents the type, not the value,
so psycopg2's DateRange would not be part of the class declaration.
SQLAlchemy's DATERANGE type was written to integrate with psycopg2
pretty much, does do a lot of operations, including overlaps,
containment, etc. the operators are here:
http://docs.sqlalchemy.org/en/rel_1_0/dialects/postgresql.html#sqlalchemy.dialects.postgresql.ranges.RangeOperators.comparator_factory
, if you're just looking to add new comparison operators to this class,
you'd follow the guidelines at
http://docs.sqlalchemy.org/en/rel_1_0/core/custom_types.html#redefining-and-creating-new-operators.
Also, always let us know what crashes means, e.g. stack trace, error
message, so that we know what it's doing and we can provide more
information.
|
|This crashes when emitting a table.create() statement.
When I look at the documentation on how to create/modify types I am
left dumfounded and I realize I would need a significant trial and
error investment to figure out how things work. Does anyone else have
experience with such an attempt? I'd rather not become an expert in
sqlalchemy type extension before I can make this work.
Thanks,
Dimitris
--
You received this message because you are subscribed to the Google
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com
mailto:sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.