[sqlalchemy] Re: Tipo Money con Postgres
Hola a todos... Estoy intentando utilizar en una bd postgres el tipo Money, debido a que estoy haciendo una migracion de una bd vieja y necesito mantener ese tipo de datos. Pero veo que SQLAlchemy no lo posee, y no esta definido como tipo nativo de Postgres. Entonces, cual seria la mejor forma de usarlo? Creando un nuevo tipo de datos? Como seria eso? Si no me he expresado bien, me avisan y reformulo mi consulta. Cualquier ayuda que reciba, desde ya la agradezco Maybe is better you answer in English, however I will answer you in Portuguese. Eu estou utilizando Numeric(18,4) creio que deva ser este o tipo interno utilizado no money, eu mesmo iria pesquisar ou perguntar aqui no grupo a respeito disso. --- May someone have a best solution to postgresql Money datatype? or I need to use Numeric? thank's -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Tipo Money con Postgres
Em Qui, 2008-01-17 às 10:40 -0800, Marcos escreveu: Thank's Alexandre for the tip, but in my first and only one answer, y received a pair of solutions in spanish, so I tried first to ask in my language. As you can see, I'm not very good writing in english. But you are right. I will try to ask in this language from now. And thanks for the solution. That's works for me. ( E graças pela solução, isso funcionou para mim ) -- I used a translator for that : ) Marcos Alcázar No problems, my English is very bad too, because it's not my fist language and I learn more from internet and working with it. about your question, I think numeric will work for you. more one tip, I've found at postgresql documentation this note: Note: The money type is deprecated. Use numeric or decimal instead, in combination with the to_char function. from 7.3 to 8.2... and maybe others in http://www.postgresql.org/docs/7.3/interactive/datatype-money.html and http://www.postgresql.org/docs/8.2/interactive/datatype-money.html I suggest, if you can, change the datatype in next versions of your software. Att, -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] postgresql truncate table
someone know why when I execute a session.execute(truncate table some_table cascade) in a postgresql database nothing happens? I need to put some extra parameter? -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: postgresql truncate table
you probably need to begin/commit a transaction since the PG dialect doesnt pick up truncate as an autocommit keyword. exactly, thank you for reply Att -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] parent table
Hello all, Can I get the parent table from an inherited table? something like: table_a = Table() table_b = Table() mapper(TableA, table_a) mapper(TableB, table_b, inherits=TableA) table_b.get_parent() the reason I need it, is that I need to get information about the master table, because when I get the table from an fk, the table.c atribute get just columns from that table, and not all columns including the master tables, in other words, getting table by this way fk_table = column.foreign_keys[0].column.table I get a shema.Table object and not the join object that represents the entire fk table. any suggestion? Att -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: SQLAlchemy and SQLRelay
Is it possible to use SA with SQLRelay? I Think yes if you are using MySQL or PostgreSQL, they have a Client Native API Wrapper, so you can try it. For others, I suggest the SA Core team to write the driver fot that client API, because it can be very useful in many cases. Att -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Get default value
Em Sex, 2008-01-11 às 08:54 +0200, [EMAIL PROTECTED] escreveu: either put the correct polymorphic_on=resource.c.poly, or remove it alltogether, it comes from the inherited base-mapper. Exactly, works fine leaving poly on resource and mapping all polymorphic_on=resource.c.poly cookbook helps me to, but just this change make my model working Thank you a lot, and thank's to all replies. follow the correct mapping to anyone wants: -code---8--code- from sqlalchemy import create_engine, MetaData, Table, Column, types, ForeignKey from sqlalchemy.orm import mapper, relation, backref, create_session from sqlalchemy.sql.expression import outerjoin, join from sqlalchemy import String, Unicode, Integer, DateTime, Numeric, Boolean, UnicodeText db = create_engine('sqlite:///sa.db') metadata = MetaData() metadata = MetaData(db) metadata.bind = db session = create_session(bind=db) resource_table = Table('resource', metadata, Column('id',Integer, primary_key=True), Column('name', String(30)), Column('poly', String(31), nullable=True) ) person_table = Table('person', metadata, Column('id',Integer, ForeignKey('resource.id'), primary_key=True,), ) material_table = Table('material', metadata, Column('id',Integer, ForeignKey('resource.id'), primary_key=True,), ) employee_table = Table('employee', metadata, Column('id',Integer, ForeignKey('person.id'), primary_key=True), ) technical_table = Table('technical', metadata, Column('id',Integer, ForeignKey('person.id'), primary_key=True), ) class Resource(object): def __init__(self, name): self.name = name def __repr__(self): return Resource id=%d ,name=%s % (self.id,self.name) class Person(Resource): def __repr__(self): return Person id=%d ,name=%s % (self.id,self.name) class Material(Resource): def __repr__(self): return Material id=%d ,name=%s % (self.id,self.name) class Employee(Person): def __repr__(self): return Employee id=%d ,name=%s % (self.id,self.name) class Technical(Person): def __repr__(self): return Technical id=%d ,name=%s % (self.id,self.name) mapper(Resource, resource_table, polymorphic_on=resource_table.c.poly, polymorphic_identity='resource', ) mapper(Person, person_table, inherits=Resource, polymorphic_identity='person', polymorphic_on= resource_table.c.poly, ) mapper(Material, material_table, inherit_condition= material_table.c.id == resource_table.c.id, inherits=Resource, polymorphic_identity='material' ) mapper(Employee, employee_table, inherit_condition= employee_table.c.id == person_table.c.id, inherits=Person, polymorphic_identity='employee', ) mapper(Technical, technical_table, inherit_condition= technical_table.c.id == person_table.c.id, inherits=Person, polymorphic_identity='technical', ) metadata.create_all(bind=db) r = Resource('resource name') p = Person('person name') m = Material('material name') e = Employee('employee name') t = Technical('technical name') session.save(r) session.save(p) session.save(m) session.save(e) session.save(t) session.flush() session.clear() print LIST FROM RESOURCES # for o in session.query(Resource).all(): print o, o.poly print LIST FROM PERSONS # for o in session.query(Person).all(): print o, o.poly -code---8--code- results are: LIST FROM RESOURCES # Resource id=1 ,name=resource name resource Person id=2 ,name=person name person Material id=3 ,name=material name material Employee id=4 ,name=employee name employee Technical id=5 ,name=technical name technical LIST FROM PERSONS # Person id=2 ,name=person name person Employee id=4 ,name=employee name employee Technical id=5 ,name=technical name technical Thanks again, Att -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: filter() on inherited class doesn't point to the correct table
I think I understand what you trying to do in fact polymorphic objects are load correctly in my test, I think it is an approach to your case. follow the code I used before to ask about polymorphic inheritance, note to the Catalog class, this class have a resource list (catalog_id on Resource), and I am inserting different types of resources, than when select, each resource is loaded correctly with their type ---code--8--code- from sqlalchemy import create_engine, MetaData, Table, Column, types, ForeignKey from sqlalchemy.orm import mapper, relation, backref, create_session from sqlalchemy.sql.expression import outerjoin, join from sqlalchemy import String, Unicode, Integer, DateTime, Numeric, Boolean, UnicodeText db = create_engine('sqlite:///:memory:') metadata = MetaData() metadata = MetaData(db) metadata.bind = db session = create_session(bind=db) resource_table = Table('resource', metadata, Column('id',Integer, primary_key=True), Column('name', String(30)), Column('catalog_id', Integer, ForeignKey('catalog.id')), Column('poly', String(31), nullable=True) ) person_table = Table('person', metadata, Column('id',Integer, ForeignKey('resource.id'), primary_key=True,), ) material_table = Table('material', metadata, Column('id',Integer, ForeignKey('resource.id'), primary_key=True,), ) employee_table = Table('employee', metadata, Column('id',Integer, ForeignKey('person.id'), primary_key=True), ) technical_table = Table('technical', metadata, Column('id',Integer, ForeignKey('person.id'), primary_key=True), ) catalog_table = Table('catalog', metadata, Column('id',Integer, primary_key=True), ) catalog_resources = Table('catalog_resources', metadata, Column('id', Integer, primary_key=True), Column('resource_id',Integer, ForeignKey('resource.id')), ) class Resource(object): def __init__(self, name): self.name = name def __repr__(self): return Resource id=%d ,name=%s % (self.id,self.name) class Person(Resource): def __repr__(self): return Person id=%d ,name=%s % (self.id,self.name) class Material(Resource): def __repr__(self): return Material id=%d ,name=%s % (self.id,self.name) class Employee(Person): def __repr__(self): return Employee id=%d ,name=%s % (self.id,self.name) class Technical(Person): def __repr__(self): return Technical id=%d ,name=%s % (self.id,self.name) class Catalog(object): def __repr__(self): return catalog id=%d resources=%s % (self.id,str([str(r)+',' for r in self.resources])) mapper(Resource, resource_table, polymorphic_on=resource_table.c.poly, polymorphic_identity='resource', ) mapper(Person, person_table, inherits=Resource, polymorphic_identity='person', polymorphic_on= resource_table.c.poly, ) mapper(Material, material_table, inherit_condition= material_table.c.id == resource_table.c.id, inherits=Resource, polymorphic_identity='material' ) mapper(Employee, employee_table, inherit_condition= employee_table.c.id == person_table.c.id, inherits=Person, polymorphic_identity='employee', ) mapper(Technical, technical_table, inherit_condition= technical_table.c.id == person_table.c.id, inherits=Person, polymorphic_identity='technical', ) mapper(Catalog, catalog_table, properties={ 'resources':relation(Resource) }) metadata.create_all(bind=db) r = Resource('resource name') p = Person('person name') m = Material('material name') e = Employee('employee name') t = Technical('technical name') x = Catalog() x.resources = [p,m,e,t] session.save(r) session.save(p) session.save(m) session.save(e) session.save(t) session.save(x) session.flush() session.clear() print LIST FROM RESOURCES # for o in session.query(Resource).all(): print o, o.poly print LIST FROM PERSONS # for o in session.query(Person).all(): print o, o.poly print Catalog # y= session.query(Catalog).one() print y ---code--8--code- I Hope it helps you Att -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Depreciation warning
Sorry previous message, I've pressed a magic combination keys here and message was sent. however The least problem with the warning is that it not inform what table and column are wrong the traceback returns: /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.2p3dev_r4036-py2.5.egg/sqlalchemy/databases/sqlite.py:389: SADeprecationWarning: Using String type with no length for CREATE TABLE is deprecated; use the Text type explicitly colspec = self.preparer.format_column(column) + + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec() my model is divided along many files to modularization, each file have more than 10 tables, the model seems to have just one wrong column, is not so dificult to me find the wrong colum, but if model was greater it could be. maybe you can include this information at traceback. Att, -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Get default value
Hello all, is there a way that I can get the default value defined on Column(default=something) ? the default I get is a ColumDefault, and I don't know how to get it's value. any suggestion? -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Get default value
Em Qui, 2008-01-10 às 17:13 -0800, jason kirtland escreveu: col.default.arg Yes, exactly this. another question How many levels I can inherit classes/tables without get something wrong? let me show a simplest sample hierarchy: resource / \ person material / \ employeecustomer now, I am creating a type column on resource to map persons and materials, them I am creating another type column on person, to get mapped the various types of persons. by this way, I could get a employee instance, just selecting a resource but something is going wrong, because the column type on resource is not filled with correct value, and I am getting NOT NULL CONSTRAINT by insert an employee. the tables resource_table = Table( Column('id',Integer, primary_key=True), Column('poly', String(31), nullable=False) ) person_table = Table( Column('id',Integer, primary_key=True, ForeignKey('resource.id'), primary_key=True)), Column('poly', String(31), nullable=False) ) employee_table = Table( Column('id',Integer, primary_key=True, ForeignKey('person.id'), primary_key=True)), ) the classes class Resource(object): pass class Person(Resource): pass class Employee(Person): pass mappers mapper(Resource, resource_table, polymorphic_on=resource_table.c.poly, polymorphic_identity='resource' ) mapper(Person, person_table, polymorphic_on=person_table.c.poly, inherits=Resource, polymorphic_identity='person' ) mapper(Employee employee_table, inherits=Person, polymorphic_identity='employee', ) is all, now when I create an instance of Employee and try to save, I get back an integrity error, that resource.poly cannot be null any suggestion? thank's for previous replies. -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Get default value
Em Qui, 2008-01-10 às 21:20 -0500, Rick Morrison escreveu: You're mixing single-table inheritance (using the discriminator column), with concrete inheritance (using multiple tables). You have to pick one scheme or the other. Either use a single inheritance chain, or separate the two class hierarchies into two separate chains that don't inherit from each other. In the separate scheme, each chain can use it's own discriminator column, but you cannot combine two class hierarchies that each use a different discriminator column. hum, so something is wrong here, I recreate a simple test case and all is working properly, using the exactly model suggested on my previous message. I will debug my application to find where is the error, but for now, I don't know if this should work, but is working. here is the test case and results: code-8--code-- from sqlalchemy import create_engine, MetaData, Table, Column, types, ForeignKey from sqlalchemy.orm import mapper, relation, backref, create_session from sqlalchemy import String, Unicode, Integer, DateTime, Numeric, Boolean, UnicodeText db = create_engine('sqlite:///:memory:') metadata = MetaData() metadata = MetaData(db) metadata.bind = db session = create_session(bind=db) resource_table = Table('resource', metadata, Column('id',Integer, primary_key=True), Column('name', String(30)), Column('poly', String(31), nullable=True) ) person_table = Table('person', metadata, Column('id',Integer, ForeignKey('resource.id'), primary_key=True,), Column('poly', String(31), nullable=False) ) material_table = Table('material', metadata, Column('id',Integer, ForeignKey('resource.id'), primary_key=True,), ) employee_table = Table('employee', metadata, Column('id',Integer, ForeignKey('person.id'), primary_key=True), ) technical_table = Table('technical', metadata, Column('id',Integer, ForeignKey('person.id'), primary_key=True), ) class Resource(object): def __init__(self, name): self.name = name def __repr__(self): return Resource id=%d ,name=%s % (self.id,self.name) class Person(Resource): def __repr__(self): return Person id=%d ,name=%s % (self.id,self.name) class Material(Resource): def __repr__(self): return Material id=%d ,name=%s % (self.id,self.name) class Employee(Person): def __repr__(self): return Employee id=%d ,name=%s % (self.id,self.name) class Technical(Person): def __repr__(self): return Technical id=%d ,name=%s % (self.id,self.name) mapper(Resource, resource_table, polymorphic_on=resource_table.c.poly, polymorphic_identity='resource' ) mapper(Person, person_table, polymorphic_on=person_table.c.poly, inherits=Resource, polymorphic_identity='person' ) mapper(Material, material_table, inherits=Resource, polymorphic_identity='material' ) mapper(Employee, employee_table, inherits=Person, polymorphic_identity='employee', ) mapper(Technical, technical_table, inherits=Person, polymorphic_identity='technical', ) metadata.create_all(bind=db) r = Resource('resource name') p = Person('person name') m = Material('material name') e = Employee('employee name') t = Technical('technical name') session.save(r) session.save(p) session.save(m) session.save(e) session.save(t) session.flush() print LIST FROM RESOURCES # for o in session.query(Resource).all(): print o print LIST FROM PERSONS # for o in session.query(Person).all(): print o code-8--code-- The results: LIST FROM RESOURCES # Resource id=1 ,name=resource name Person id=2 ,name=person name Material id=3 ,name=material name Employee id=4 ,name=employee name Technical id=5 ,name=technical name LIST FROM PERSONS # Person id=2 ,name=person name Employee id=4 ,name=employee name Technical id=5 ,name=technical name I think it is working properly. but I will try to remove the type columns Thank's for help -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Get default value
Em Qui, 2008-01-10 às 21:20 -0500, Rick Morrison escreveu: You're mixing single-table inheritance (using the discriminator column), with concrete inheritance (using multiple tables). You have to pick one scheme or the other. Either use a single inheritance chain, or separate the two class hierarchies into two separate chains that don't inherit from each other. In the separate scheme, each chain can use it's own discriminator column, but you cannot combine two class hierarchies that each use a different discriminator column. In fact I am doing what is sugested here: http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_inheritance_joined It works fine with one level inheritance class-subclass but the third subclassing don't working, it was because objects was in cache... savint to db and tryin to load again the identity is lost. how do you suggest to I do this? or I cannot? -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] polymorphic inheritance
Hello all, sa developers, is too dificult try to implement inheritance works by that form? I don't know the SA core, so I think is no so difficult to make this working. for now, I accept this code changed to work properly, as it works removing the session.clear() thank's a lot code---8--code-- from sqlalchemy import create_engine, MetaData, Table, Column, types, ForeignKey from sqlalchemy.orm import mapper, relation, backref, create_session from sqlalchemy import String, Unicode, Integer, DateTime, Numeric, Boolean, UnicodeText db = create_engine('sqlite:///:memory:') metadata = MetaData() metadata = MetaData(db) metadata.bind = db session = create_session(bind=db) resource_table = Table('resource', metadata, Column('id',Integer, primary_key=True), Column('name', String(30)), Column('poly', String(31), nullable=True) ) person_table = Table('person', metadata, Column('id',Integer, ForeignKey('resource.id'), primary_key=True,), Column('poly', String(31), nullable=False) ) material_table = Table('material', metadata, Column('id',Integer, ForeignKey('resource.id'), primary_key=True,), ) employee_table = Table('employee', metadata, Column('id',Integer, ForeignKey('person.id'), primary_key=True), ) technical_table = Table('technical', metadata, Column('id',Integer, ForeignKey('person.id'), primary_key=True), ) class Resource(object): def __init__(self, name): self.name = name def __repr__(self): return Resource id=%d ,name=%s % (self.id,self.name) class Person(Resource): def __repr__(self): return Person id=%d ,name=%s % (self.id,self.name) class Material(Resource): def __repr__(self): return Material id=%d ,name=%s % (self.id,self.name) class Employee(Person): def __repr__(self): return Employee id=%d ,name=%s % (self.id,self.name) class Technical(Person): def __repr__(self): return Technical id=%d ,name=%s % (self.id,self.name) mapper(Resource, resource_table, polymorphic_on=resource_table.c.poly, polymorphic_identity='resource' ) mapper(Person, person_table, polymorphic_on=person_table.c.poly, inherits=Resource, polymorphic_identity='person' ) mapper(Material, material_table, inherits=Resource, polymorphic_identity='material' ) mapper(Employee, employee_table, inherits=Person, polymorphic_identity='employee', ) mapper(Technical, technical_table, inherits=Person, polymorphic_identity='technical', ) metadata.create_all(bind=db) r = Resource('resource name') p = Person('person name') m = Material('material name') e = Employee('employee name') t = Technical('technical name') session.save(r) session.save(p) session.save(m) session.save(e) session.save(t) session.flush() session.clear() print LIST FROM RESOURCES # for o in session.query(Resource).all(): print o, o.poly print LIST FROM PERSONS # for o in session.query(Person).all(): print o code---8--code-- Att, -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: broken relationship
I am not sure, but, I think after you save feed, in this case you don't need to call session.flush() maybe it is clearing the sessionand the feed object too. try to remove it or test if is none after session.flush() session.save (feed) session.flush () post= Post ( -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) gedit-todo http://alexandredasilva.wordpress.com/gedit-todo-list-plugin/ MicroDB http://www.assembla.com/space/microdb Open Sales Force System http://www.assembla.com/space/osfs opencomanche ([stopped] mail-me to get the latest source code) http://sourceforge.net/projects/opencomanche/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Emptying out the session of new objects
Is there an easy way of flushing all objects that are categorised as new in the session ?? I think you can use session.clear(), it will remove objects from session, and persistent objects will stay on database. Att Alexandre --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] get related table object via mapped class
Hello all, is there any way to access class related by an relationship? sample: # Table definition ommited class Person(object): pass class Address(object): pass mapper(Person, person_table, properties=dict( address=relation(Address, uselist=False) ) ) now I want to access the Address class (and/or address_table) through a Person object, any sugestion? -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) gedit-todo http://alexandredasilva.wordpress.com/gedit-todo-list-plugin/ MicroDB http://www.assembla.com/space/microdb Open Sales Force System http://www.assembla.com/space/osfs opencomanche ([stopped] mail-me to get the latest source code) http://sourceforge.net/projects/opencomanche/ -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) gedit-todo http://alexandredasilva.wordpress.com/gedit-todo-list-plugin/ MicroDB http://www.assembla.com/space/microdb Open Sales Force System http://www.assembla.com/space/osfs opencomanche ([stopped] mail-me to get the latest source code) http://sourceforge.net/projects/opencomanche/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: get related table object via mapped class
Person.address._get_target_class() thank you for reply, it is always more readable that Person.address.property.mapper.class_ Thank's for all -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) gedit-todo http://alexandredasilva.wordpress.com/gedit-todo-list-plugin/ MicroDB http://www.assembla.com/space/microdb Open Sales Force System http://www.assembla.com/space/osfs opencomanche ([stopped] mail-me to get the latest source code) http://sourceforge.net/projects/opencomanche/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: get related table object via mapped class
using the Person class directly: Person.address.property.mapper.class_ Person.address.property.mapper.mapped_table Thank you so much, works like a charm -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) gedit-todo http://alexandredasilva.wordpress.com/gedit-todo-list-plugin/ MicroDB http://www.assembla.com/space/microdb Open Sales Force System http://www.assembla.com/space/osfs opencomanche ([stopped] mail-me to get the latest source code) http://sourceforge.net/projects/opencomanche/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Execute query without a mapper
http://www.sqlalchemy.org/docs/04/sqlexpression.html yes, I've already been read that, but I am using TurboGears and using session if you mean that youd like to execute using the Session itself, use the execute() method on Session and you probably want to bind your Session to the engine directly: http://www.sqlalchemy.org/docs/04/session.html#unitofwork_sql I see at documentation that Session.execute() is deprecated and now we need to use Session.query(Class/Mapper).from_statement(stmt) instead so it requires a mapper or a Class as parameter, and I don´t have sucess trying to do it witout a class. like a flat SQL file ? just read the file and execute each linefor line in file('myfile.txt'): engine.execute(line) Yes like a flat SQL file, and for simple inserts and/or updates I do exactly this, but it is not so usefull if I need to execure multiline statements, like: CREATE OR REPLACE FUNCTION. $ function body .. .. $... to do it properly I think I need to write all in one line. otherwise I already no tried to create any database function using this method. if that is no way to do similar thigs I will maintain my old flat sql files and execute direct to database, I just ask it because if I have this feature, I can do things like, create a single sql file to each database object related to one table, like an after insert trigger, or any other kind of object I need. for now, to perform default data inserts I will import my model and use session.query(Class).from_statement(stmt).all(), it is working properly thank you very much for reply Alexandre --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Execute query without a mapper
Is there any way to execute a database query without a mapper or class? it would be useful to perform arbitrary inserts on database. and another question, is there any way to execute a sql file from sqlalchemy session, the reason is the same as above, make arbitrary inserts and/or updates on database. Thanks for any help -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) gedit-todo http://alexandredasilva.wordpress.com/gedit-todo-list-plugin/ MicroDB http://www.assembla.com/space/microdb Open Sales Force System http://www.assembla.com/space/osfs opencomanche ([stopped] mail-me to get the latest source code) http://sourceforge.net/projects/opencomanche/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Session.execute (PostgreSQL) function not doing anything?
What is missing there? Any tips/pointers would be greatly appreciated! I not tested here if is solve your problem, but, are you calling the commit() after execution? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: get mapped class
what u need? I need the list of mapped Classes, if mapper_registry have all classes I can use it. all tables? see metadata. all mappers? see the mapper_registry the relations inbetween? u have to dig the individual mappers, walk the polymorphisms and inheritances. I just want a list containing the relation class-table and table-class, but I think it's not available, so I will create my own. probably no, the relation is directional in the other way,. mapper-table; one may have many mappers linked in a way or another to same table. i'm not sure if u can have 2 separate clasess with 2 primary mappers using same table - probably can. Creating my own mapping list I will get what I need for now. and, why u need all this? At my development scenario I want to create a Form on application just defining some properties at Mapped Class, and just what I need is a list with the links table-class, to get one or other depends where am I, other thing I need/want is create some database additional objects (triggers, procedures, etc) just creating a staticmethod at mapped class, i.e get_addit_metadata() that's all for now I will implement my own mapper function, and it will inside add the class-table to a list to keep tracking and inside call the sqlalchemy mapper method. Thank's for all replies Best Regards, Alexandre --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Default data and table related database objects
database trigger syntax is pretty database specific so we dont have a generic DDL construct for that right now. you can issue the DDL using a textual execute like engine.execute(CREATE TRIGGER ...). for inserting of data you usually would use a table.insert() construct. ok, it helps if I have an after_create event on mapper or mapped class, than I will able to create all additional objects related with table at moment I call metadata.create_all() you've lost me here. I don't see the connection between a trigger in your database and a method on one of your mapped classes. it would be just a Method like after_create_execute(SOME DATABASE SPECIFIC SQL), and this method should be called after creation of table, but just on creation... would be usefull have an before_drop_execute(SOME STATEMENT) to make users able to drop these related object in case of automatic database recreation in the same method after_create_execute() users can put insert statements to insert default data to tables, it can be very usefull in some cases. you'd have to show me what you mean, I don't understand why you need to scroll through all your classes just to set up triggers in your schema. The schema exists independently of any ORM configuration which uses that schema. if the feature above is not ready, I will put a staticmethod on each mapped class to define my default data and related objects, and will call it for each mapped class. the methods can contain something like this: def get_trigger_metadata(): return CREATE OR REPLACE TRIGGER def initialize_table(): return INSERT INTO TABLE_NAME VALUES (1,Lorem Ipsun,foo,bar) All this to setup initial additional objects to database i.e. on application setup --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Default data and table related database objects
we have a ticket in the works for this: http://www.sqlalchemy.org/trac/ticket/903 ok, I will look at this ticket. note that this feature applies to Table objects, not ORM mapped classes. A central tenet of SQLAlchemy is that the object relational mapper is an optional package which is completely decoupled from database schema definition. If you're looking to define mapped classes and schema declaration together theres a tool called Elixir that does that. Yes, I know Elixir, but I prefer to use sqlalchemy directly to get more flexibility. Thank you for reply. Alexandre --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] get mapped class
Hello Again, I am already trying go get the list of mapped tables. I currently got a list from sqlalchemy.org.mapper from the weakref mapper_registry, but I don't know if that values are useful for my context. I also have another question, I have some way to access the mapped class from the table object? something like: user_table = Table(...) class User(object) pass mapper(User, user_table) I have some method like user_table.getclass? or another way to get it from orm? thank's for help -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) gedit-todo http://alexandredasilva.wordpress.com/gedit-todo-list-plugin/ MicroDB http://www.assembla.com/space/microdb Open Sales Force System http://www.assembla.com/space/osfs opencomanche ([stopped] mail-me to get the latest source code) http://sourceforge.net/projects/opencomanche/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---