Is there a way to do what I want to do?
Thanks,
|>ouglas
I'm not sure exactly what hint would be appropriate to add in all inserts, but the general idea can be accompished using this technique (recent 0.5 and 0.6 versions):
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import expression
@compiles(expression.Insert)
def annotated_insert(insert, compiler, **kw):
return compiler.visit_insert(insert.prefix_with('/* foo */'), **kw)
that will register the annotated_insert function as the compiler for the Insert construct, globally for the whole application. Within annotated_insert you'd probably want to add rules such that your prefix_with() is only registered for the tables and conditions that you'd want. Such as, if you'd like to attach an attribute "my_prefixes" to your Table object, it would be detected as such:
@compiles(expression.Insert)
def annotated_insert(insert, compiler, **kw):
if getattr(insert.table, 'my_prefixes', None):
insert = insert.prefix_with('/* %s */' % insert.table.my_prefixes)
return compiler.visit_insert(insert, **kw)
When the ORM inserts rows, it uses the same insert() construct and the prefix logic above will take effect.
>
> Thanks,
> |>ouglas
>
> --
>
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>
>
> I'm not sure exactly what hint would be appropriate to add in all inserts
Ah, I should have been more clear: I want to have a default prefix_with
() for insertions on a specific table, not for insertions on *all*
tables.
I think that the second example that you included should work fine for
that purpose. Thanks!
|>ouglas