Re: [sqlalchemy]why I can't use custom type by form_statement method??
by the way I read some document about how to use text() but it seems when I use text().I got records from database,not instances of class object. I want to get instance anyone can help me ? 2010/4/20 Cancer k.cancer.2...@gmail.com Hi Michael~ thank you very much for your answer~ can you give me an example? I really don't know..how to use it... thanks a lot~ 2010/4/20 Michael Bayer mike...@zzzcomputing.com use a text() construct as the argument to your from_statement() call, and specify a typemap of {'birthday':NormalDate} along with it. http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html?highlight=text#sqlalchemy.sql.expression.text On Apr 19, 2010, at 5:38 AM, Rita Liang wrote: I have a custom type NormalDate which uses to convert Integer Date type to String Date type. but when I use form_statement to query the date.it did't work! however,it will work, if I use a query method... for example. crew = query.from_statement(SELECT * from crew_member where + rtrim(crew_member.lastname) || rtrim(crew_member.firstname) + like '% + crew_name + %').first() this will not work. crew.birthday shows 41274135 but user = query.filter(CrewMember.last_name.like(u'%j %'.encode('gbk'))).first() works well. and the crew.birthday shows 1969/06/23 this is want I want anybody any suggestion? -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- Rita Liang -- Rita Liang -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy]why I can't use custom type by form_statement method??
o yeah! I solved the question~ these are codes.hope it's useful to someone who have the same question~ crew = query.from_statement(text(SELECT * from crew_member where + rtrim(crew_member.lastname) || rtrim(crew_member.firstname) + like '% + crew_name + %', typemap = {'birthday' : NormalDate})).first() by the way...I want to know ..why it be like this? what is difference between from_statement query and filter query? 2010/4/20 Cancer k.cancer.2...@gmail.com by the way I read some document about how to use text() but it seems when I use text().I got records from database,not instances of class object. I want to get instance anyone can help me ? 2010/4/20 Cancer k.cancer.2...@gmail.com Hi Michael~ thank you very much for your answer~ can you give me an example? I really don't know..how to use it... thanks a lot~ 2010/4/20 Michael Bayer mike...@zzzcomputing.com use a text() construct as the argument to your from_statement() call, and specify a typemap of {'birthday':NormalDate} along with it. http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html?highlight=text#sqlalchemy.sql.expression.text On Apr 19, 2010, at 5:38 AM, Rita Liang wrote: I have a custom type NormalDate which uses to convert Integer Date type to String Date type. but when I use form_statement to query the date.it did't work! however,it will work, if I use a query method... for example. crew = query.from_statement(SELECT * from crew_member where + rtrim(crew_member.lastname) || rtrim(crew_member.firstname) + like '% + crew_name + %').first() this will not work. crew.birthday shows 41274135 but user = query.filter(CrewMember.last_name.like(u'%j %'.encode('gbk'))).first() works well. and the crew.birthday shows 1969/06/23 this is want I want anybody any suggestion? -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- Rita Liang -- Rita Liang -- Rita Liang -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] case sensitive Unicode and String columns
Michael Bayer wrote: Please let me know if there's a better way! you should use TypeDecorator.load_dialect_impl(dialect), check the name of the dialect, Why the name rather than doing: if isinstance(dialect,MySQLDialect): ? then return either MSString(arguments) or super.load_dialect_impl(). Okay, but where do I get the arguments from? super(CaseSensitiveUnicode,self).load_dialect_impl(dialect) leads to: 263 if isinstance(self.impl, TypeDecorator): 264 return self.impl.dialect_impl(dialect) 265 else: 266 return dialect.type_descriptor(self.impl) ...which then ends up in some adapt_type stuff that looked pretty hairy. All I want to do is insert a collation argument when the dialect is MySQL... cheers, Chris -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] SQLAlchemy 0.6.0 released
Yes, Congratulations Thank-you! --diana On Sun, Apr 18, 2010 at 8:02 PM, Michael Bayer mike...@zzzcomputing.com wrote: The first official 0.6 release of SQLAlchemy is now available. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] docs for TypeDecorators
Hi All, Are there any other docs for using and creating TypeDecorators than these: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html#custom-types The following sections: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html#sqlalchemy.types.TypeDecorator.__init__ ...are a little less detailed than they could be ;-) Chris -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: SQLAlchemy 0.6.0 released
Congratulations Mike and contributors. This is an important milestone in the evolution of SQLAlchemy. Thanks for all the hard work. -Gerry On Sun, Apr 18, 2010 at 8:02 PM, Michael Bayer mike...@zzzcomputing.com wrote: The first official 0.6 release of SQLAlchemy is now available. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] case sensitive Unicode and String columns
Chris Withers wrote: Michael Bayer wrote: Please let me know if there's a better way! you should use TypeDecorator.load_dialect_impl(dialect), check the name of the dialect, Why the name rather than doing: if isinstance(dialect,MySQLDialect): you could do that too, though the name is more solid then return either MSString(arguments) or super.load_dialect_impl(). Okay, but where do I get the arguments from? you have to stick them on your custom type.i.e. your typedecorator object. super(CaseSensitiveUnicode,self).load_dialect_impl(dialect) leads to: 263 if isinstance(self.impl, TypeDecorator): 264 return self.impl.dialect_impl(dialect) 265 else: 266 return dialect.type_descriptor(self.impl) ...which then ends up in some adapt_type stuff that looked pretty hairy. All I want to do is insert a collation argument when the dialect is MySQL... this is the code: def load_dialect_impl(self, dialect): if dialect.name == 'mysql': return MSString(self.length, collation=self.collation_whatever) else: return super(MyType, self).load_dialect_impl(dialect) -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] bug in sqllite dialect?
Chris Withers wrote: Michael Bayer wrote: Chris Withers wrote: Michael Bayer wrote: Has anyone (hi, list, talking to you too!) already done a custom type for this specific problem? people do custom types for all sorts of things. In the case of the Decimal here I'd likely subclass sqlalchemy.databases.sqlite.SLNumeric which should ensure that your own bind_processor() and result_processor() methods can be called. Okay, but how do I make sure this is only used when sqlite this the engine? You can use a TypeDecorator to switch between implementations. I had a plan to add a pre-fab type for this to core that allows easy switching of implementations. Okay, this is what I've ended up with for this one: from decimal import Decimal from sqlalchemy import types from sqlalchemy.databases.sqlite import SQLiteDialect class Numeric(types.TypeDecorator): A numeric type that respects precision with SQLite - always returns Decimals - always rounds as necessary as a result impl = types.Numeric def bind_processor(self, dialect): if isinstance(dialect,SQLiteDialect): def process(value): if value is None: return None else: return float(value) return process else: return super(Numeric,self).bind_processor(dialect) def result_processor(self, dialect): if isinstance(dialect,SQLiteDialect): fstring = %%.%df % self.impl.scale def process(value): if value is None: return None else: return Decimal(fstring % value) return process else: return super(Numeric,self).result_processor(dialect) What should I have done differently and why? cheers, Chris PS: While looking into how to do this for 0.5.8, I saw this dire warning in 0.6: util.warn(Dialect %s+%s does *not* support Decimal objects natively, and SQLAlchemy must convert from floating point - rounding errors and other issues may occur. Please consider storing Decimal numbers as strings or integers on this platform for lossless storage. % (dialect.name, dialect.driver)) ...which I also saw applies to SQLite. What are the rounding errors and others issues that you allude to? What is the integer/string recommendation saying? Use a String column? Use an Integer column? Is this something I could work into a TypeDecorator? Should I? the whole ugly discussion is at http://www.sqlalchemy.org/trac/ticket/1759 cheers, Chris -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] docs for TypeDecorators
Chris Withers wrote: Hi All, Are there any other docs for using and creating TypeDecorators than these: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html#custom-types The following sections: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html#sqlalchemy.types.TypeDecorator.__init__ ...are a little less detailed than they could be ;-) Let me talk to one of our committers to see if they can help us. Hey Chris - want to beef up the docs for TypeDecorator ? ... I'll let you know what he says. Chris -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] docs for TypeDecorators
Michael Bayer wrote: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html#sqlalchemy.types.TypeDecorator.__init__ ...are a little less detailed than they could be ;-) Let me talk to one of our committers to see if they can help us. Hey Chris - want to beef up the docs for TypeDecorator ? I actually would love to, but I simply don't have the knowledge :-( Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] bug in sqllite dialect?
Michael Bayer wrote: the whole ugly discussion is at http://www.sqlalchemy.org/trac/ticket/1759 Speshul... *sigh* I'm glad I don't have your responsibilities ;-) Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] testing?
how do I run some self-testing in sqlalchemy? I found this doc, but it seems to be out of date?? http://svn.sqlalchemy.org/sqlalchemy/trunk/README.unittests just for fun, i'm trying to run these tests inside IronPython, so any pointers in that direction would be helpful also.. thx, HP -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] testing?
Please read the document: http://svn.sqlalchemy.org/sqlalchemy/trunk/README_MOVED_TO_MERCURIAL Harry Percival wrote: how do I run some self-testing in sqlalchemy? I found this doc, but it seems to be out of date?? http://svn.sqlalchemy.org/sqlalchemy/trunk/README.unittests just for fun, i'm trying to run these tests inside IronPython, so any pointers in that direction would be helpful also.. thx, HP -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] custom dialect with no join syntax support possible?
Hi, I'm writing a new custom dialect for a legacy database (Centura SQLBase 7.5.1) for use in migrating to a new system over time. Everything's gone pretty well, until I needed a join... Whereas most dialects would create a statement such as: SELECT T1.ID, T1.COL1, T2.COL2 FROM T1 JOIN T2 ON T1.ID = T2.ID WHERE T1.ID = 100 , (at least this flavor of) SQLBase expects it to be like so: SELECT T1.ID, T1.COL1, T2.COL2 FROM T1, T2 WHERE T1.ID = T2.ID AND T1.ID = 100 And in fact JOIN isn't even one of their reserved words, so sending it a statement like the first example will of course cause an error. I've subclassed sqlalchemy.sql.compiler.SQLCompiler in the hopes of overriding the visit_join method for my dialect, but I'm not sure it's possible to achieve what I'm after this way? I can of course replace the JOIN text with , but if I replace ON with WHERE then all of a sudden the final statement has two WHERE clauses and is thus invalid for a whole new reason. Is there a way to override the visit_join method to accomplish my goal or should I be looking somewhere else? (I assume I can add custom @properties to my data class, for instance. I'd like to solve the bigger problem here but if I can't then I really just need a way past this particular problem.) TIA, I really appreciate any help. Lance -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Custom ORM attributes to provide on-the-fly data conversion
I've run into some difficulty getting the ORM to fit into an existing code base with some, I suppose, non-standard conventions. One of the conventions is to not allow primary keys (auto-incremented integers) to be exposed on the front-end servlet or template but to maintain the original integer values inside 'logic' or 'back- end' code. We've been through a few methods of trying this, but they feel like we're fighting sqlalchemy and must be missing something. The plan is to flip a flag when the object passes through a pre- defined barrier, converting these columns only when they are asked for. The original implementation had us creating two columns, one of them being a synonym which provides the encryption behavior, but this means we have class that look like this: class Foo(Base): id, _id = build_id_column(Integer, primary_key=True) The second implementation is attempting to get rid of the dual columns by redefining the underlying descriptor, which children of ColumnProperty() provide (like SynonymProperty()) but basic ColumnProperty seems to ignore. So I had to sub-class ColumnProperty, redefine instrument_class() and then re-implement register_descriptor() to achieve. This is all getting very complicated. Is there any other way to get some control over getting of a column ? AttributeExtension handles the setting, I think, but there is no interface for getting. I'm hoping I'm missing something. (Using sqlalchemy 6beta1 and declarative) Thanks, Rhett -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] custom dialect with no join syntax support possible?
On Apr 20, 2010, at 4:47 PM, Lance Edgar wrote: Hi, I'm writing a new custom dialect for a legacy database (Centura SQLBase 7.5.1) for use in migrating to a new system over time. Everything's gone pretty well, until I needed a join... Whereas most dialects would create a statement such as: SELECT T1.ID, T1.COL1, T2.COL2 FROM T1 JOIN T2 ON T1.ID = T2.ID WHERE T1.ID = 100 , (at least this flavor of) SQLBase expects it to be like so: SELECT T1.ID, T1.COL1, T2.COL2 FROM T1, T2 WHERE T1.ID = T2.ID AND T1.ID = 100 And in fact JOIN isn't even one of their reserved words, so sending it a statement like the first example will of course cause an error. I've subclassed sqlalchemy.sql.compiler.SQLCompiler in the hopes of overriding the visit_join method for my dialect, but I'm not sure it's possible to achieve what I'm after this way? I can of course replace the JOIN text with , but if I replace ON with WHERE then all of a sudden the final statement has two WHERE clauses and is thus invalid for a whole new reason. Is there a way to override the visit_join method to accomplish my goal or should I be looking somewhere else? (I assume I can add custom @properties to my data class, for instance. I'd like to solve the bigger problem here but if I can't then I really just need a way past this particular problem.) TIA, I really appreciate any help. the Oracle dialect does this, when use_ansi =False. You should copy the code directly from there lib/sqlalchemy/dialects/oracle/base.py. The only big missing thing here is OUTER JOIN. Oracle 8 uses (+) to indicate an outer join, does SQLBase have something similar ? Lance -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Creating sequence
What is the preferred method to have metadata.create_all() create sequences? I tried to find something in the wiki but could not find anything. For indexes you can do this: schema.Index(public_event_idx, Event.workflow, Event.deleted) but a similar statement for a sequence: schema.Sequence(invoice_number, metadata=meta.metadata) does not do anything. From what I gather from the source Sequence is not derived from SchemaItem, so it is not picked up automatically. I could do a DDL construct like this (untested, but basic idea should work): from sqlalchemy.schema import DDL def sequenceSupported(event, schema_item, connection): return connection.dialect.sequence_supported: DDL(CREATE SEQUENCE invoice_number, on=sequenceSupported)\ .execute_at(after-create, metadata) but I would rather not have to hardcode the SQL statement, especially since SQLAlchemy is capable of generating the statement as well. Wichert. -- Wichert Akkerman wich...@wiggy.net It is simple to make things. http://www.wiggy.net/ It is hard to make things simple. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Custom ORM attributes to provide on-the-fly data conversion
On Apr 20, 2010, at 7:06 PM, Rhett wrote: I've run into some difficulty getting the ORM to fit into an existing code base with some, I suppose, non-standard conventions. One of the conventions is to not allow primary keys (auto-incremented integers) to be exposed on the front-end servlet or template but to maintain the original integer values inside 'logic' or 'back- end' code. We've been through a few methods of trying this, but they feel like we're fighting sqlalchemy and must be missing something. In Python, the closest thing we have to a private attribute is that it begins with an underscore. This is extremely easy to do, just name the mapped attribute _id or whatever name you'd like. This is documented at http://www.sqlalchemy.org/docs/mappers.html#customizing-column-properties . The plan is to flip a flag when the object passes through a pre- defined barrier, converting these columns only when they are asked for. The original implementation had us creating two columns, one of them being a synonym which provides the encryption behavior, but this means we have class that look like this: class Foo(Base): id, _id = build_id_column(Integer, primary_key=True) where does encryption come into play ? are you trying to just expose the primary key value as something else ? easy enough, just use a descriptor: class MyClass(object): def encrypted_id(self): return encrypt_my_id(self._super_secret_id_attribute) def set_encrypted_id(self, id): self._super_secret_id_attribute = unencrypt_id(id) encrypted_id = property(encrypted_id, set_encrypted_id) mapper(MyClass, mytable, properties={ '_super_secret_id_attribute':mytable.c.id }) if you want MyClass.encrypted_id to be available in queries at the class level, this would require a SQL function that does your encryption. See examples/derived_attributes/ for some techniques on that. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Creating sequence
Sequence has a create() method but doesn't yet link into metadata.create_all() without being assocaited with a Table. So yes you'd use DDL or in 0.6 the CreateSequence() construct. On Apr 20, 2010, at 7:26 PM, Wichert Akkerman wrote: What is the preferred method to have metadata.create_all() create sequences? I tried to find something in the wiki but could not find anything. For indexes you can do this: schema.Index(public_event_idx, Event.workflow, Event.deleted) but a similar statement for a sequence: schema.Sequence(invoice_number, metadata=meta.metadata) does not do anything. From what I gather from the source Sequence is not derived from SchemaItem, so it is not picked up automatically. I could do a DDL construct like this (untested, but basic idea should work): from sqlalchemy.schema import DDL def sequenceSupported(event, schema_item, connection): return connection.dialect.sequence_supported: DDL(CREATE SEQUENCE invoice_number, on=sequenceSupported)\ .execute_at(after-create, metadata) but I would rather not have to hardcode the SQL statement, especially since SQLAlchemy is capable of generating the statement as well. Wichert. -- Wichert Akkerman wich...@wiggy.net It is simple to make things. http://www.wiggy.net/ It is hard to make things simple. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Custom ORM attributes to provide on-the-fly data conversion
On Apr 20, 2010, at 7:32 PM, Michael Bayer wrote: if you want MyClass.encrypted_id to be available in queries at the class level, this would require a SQL function that does your encryption. See examples/derived_attributes/ for some techniques on that. correction, you'd probably want to implement a custom comparator for in-query functionality, i.e. at http://www.sqlalchemy.org/docs/mappers.html#custom-comparators . -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Custom ORM attributes to provide on-the-fly data conversion
On Tue, Apr 20, 2010 at 4:32 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 20, 2010, at 7:06 PM, Rhett wrote: I've run into some difficulty getting the ORM to fit into an existing code base with some, I suppose, non-standard conventions. One of the conventions is to not allow primary keys (auto-incremented integers) to be exposed on the front-end servlet or template but to maintain the original integer values inside 'logic' or 'back- end' code. We've been through a few methods of trying this, but they feel like we're fighting sqlalchemy and must be missing something. In Python, the closest thing we have to a private attribute is that it begins with an underscore. This is extremely easy to do, just name the mapped attribute _id or whatever name you'd like. This is documented at http://www.sqlalchemy.org/docs/mappers.html#customizing-column-properties . The plan is to flip a flag when the object passes through a pre- defined barrier, converting these columns only when they are asked for. The original implementation had us creating two columns, one of them being a synonym which provides the encryption behavior, but this means we have class that look like this: class Foo(Base): id, _id = build_id_column(Integer, primary_key=True) where does encryption come into play ? are you trying to just expose the primary key value as something else ? easy enough, just use a descriptor: I probably should have said 'obfuscation'. You are correct, we're trying to make the primary key not expose the actual size/distribution of the underlying table. class MyClass(object): def encrypted_id(self): return encrypt_my_id(self._super_secret_id_attribute) def set_encrypted_id(self, id): self._super_secret_id_attribute = unencrypt_id(id) encrypted_id = property(encrypted_id, set_encrypted_id) mapper(MyClass, mytable, properties={ '_super_secret_id_attribute':mytable.c.id }) if you want MyClass.encrypted_id to be available in queries at the class level, this would require a SQL function that does your encryption. See examples/derived_attributes/ for some techniques on that. So the point is that this should be done outside of the core ORM as a standard property as opposed to getting the ORM to do it for me. The downside being that the syntax isn't quite as clean as using declarative. This would be much easier, I could potentially be what we go with. I think this is similar to my 'original implementation' I just found the syntax to be a bit bothersome since the person creating the table has to know they are creating two columns... or not using declarative. These ids are (and foreign keys) mean you'll be doing something like this multiple times on every table in our system, so I want it to be a streamline and foolproof as possible. Thanks for your help, Rhett -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.