[storm] Questions about inserts
BožoDragojevič
bozo.dragojevic at gmail.com
Fri Jun 13 07:31:02 BST 2008
David Koblas <koblas at ...> writes:
>
> I've got two issues, the first is that I have a column that is basically
> a random number.. But, I cant quite figure out how to get in inserted
> correctly, what I thought would work is something akin to the following
> code:
>
> inv = schema.Invite()
> inv.invite_id = SQL("MD5(UUID())")
> inv.account_id = acct.id
> inv.email = unicode(toaddr)
>
> store.add(inv)
>
> Of course, first I get an exception that 'invite_id' is not unicode
> (since it's defined as Unicode() column). Of course a quick cast to
> unicode(...) yeilds nothing but trouble. So, is there a way I can pass
> a SQL expression into an add(...) statement?
>
> I'm finding it a bit tidious to constantly be casting from str(...) to
> unicode(...) to keep the database happy. Is there really a best
> practice for how to have VARCHAR columns that are should be treated as
> RawStr() for purposes of development?
>
> Thanks
>
>
I did this:
class AsciiVariable(storm.variables.Variable):
def parse_set(self, value, from_db):
if from_db:
if not isinstance(value, (str, unicode)):
raise TypeError("Expected unicode or string full of ascii, found
%r: %r"
% (type(value), value))
else:
if not isinstance(value, (str, unicode, )):
raise TypeError("Expected unicode or string full of ascii, found
%r: %r"
% (type(value), value))
return value.encode('ascii')
def parse_get(self, value, to_db):
if to_db:
return value.decode('ascii')
else:
return value
class Ascii(storm.properties.SimpleProperty):
variable_class = AsciiVariable
Bozzo
More information about the storm
mailing list