Hi, there.
Just trying to make SA work with combined type field.
First, I have such a type in PGSQL:
CREATE TYPE mytype AS
(id integer,
flags integer,
degrees numeric[]);
Then I create a column in table 'mytable' as
ALTER TABLE mytable ADD COLUMN tmpcol mytype[];
Then I declare this column in mapper:
sa.Column("tmpcol", PGArray(PGmytype))
and define PGmytype in application library:
class PGmytype(sqltypes.TypeEngine, sqltypes.MutableType):
def __init__(self):
print "PGmytype.__init__"
But this makes it possible to only add or delete records into DB, but
not change. when I try to change a record in DB flush() returns
nothing.
What must be done for custom type to make it really mutable?
def copy_value(self, value):
print "copy_value - %s" % repr(value)
if value is None:
return None
else:
return value
def compare_values(self, x, y):
print "compare_values - %s %s" % (repr(x), repr(y))
return x == y
def is_mutable(self):
print "is_mutable"
return True
def bind_processor(self, dialect):
def process(value):
print "bproc"
return value
return process
def result_processor(self, dialect):
def process(value):
print "rproc"
return value
return process
def get_col_spec(self):
return 'mytype'
def get_dbapi_type(self, dbapi):
print "get_dbapi_type %s" % repr(dbapi)
dbapi.mytype
def dialect_impl(self, dialect):
print "dialect_impl %s" % repr(dialect)
return sqltypes.TypeEngine.dialect_impl(self, dialect)
class mytype(object):
def __init__(self):
self.id = None
self.flags = None
self.degrees = []
def __repr__(self):
degrees = ", ".join(["%s" % degree for degree in
self.degrees])
res = '(%s, %s, ARRAY[%s])::mytype' % (self.id, self.flags,
degrees)
return res
def __eq__(self, value):
print "__eq__"
return (self.id == value.id) and (self.flags == value.flags)
and (self.degrees == value.degrees)
def __cmp__(self, value):
print "__cmp__"
return 0 if ((self.id == value.id) and (self.flags ==
value.flags) and (self.degrees == value.degrees)) else 1
def __ne__(self, value):
return not((self.id == value.id) and (self.flags ==
value.flags) and (self.degrees == value.degrees))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---