[sqlalchemy] Re: Mapper Issue Upgrading to 0.4.5

2008-04-15 Thread Koen Bok

For anyone who needs this too, there is a small typo in the above
example. It should be:

mapper(PGUser, pg_user, properties={
'groups': relation(PGGroup, viewonly=True,
primaryjoin=pg_user.c.usesysid==func.any(pg_group.c.grolist),
foreign_keys=[pg_group.c.grolist],
_local_remote_pairs=[(pg_user.c.usesysid, 
pg_group.c.grolist)])})

On Apr 14, 11:26 pm, Koen Bok [EMAIL PROTECTED] wrote:
 Wow that is fast!

 Thanks man ;-)

 On Apr 14, 5:51 pm, Michael Bayer [EMAIL PROTECTED] wrote:

  On Apr 14, 2008, at 7:44 AM, Koen Bok wrote:

   Hey All,

   I was upgrading our app from 0.4.1 to 0.4.5 and this code broke:

   pg_user = Table('pg_user', metadata,
      Column('usesysid', Integer, primary_key=True),
      Column('usename', Unicode(), unique=True))

   pg_group = Table('pg_group', metadata,
      Column('grosysid', Integer, primary_key=True),
      Column('groname', Unicode(), unique=True),
      Column('grolist', PGArray(unicode)))

   mapper(PGUser, pg_user, properties={
      'groups': relation(PGGroup, viewonly=True,
              primaryjoin=pg_user.c.usesysid==func.any(pg_group.c.grolist),
              foreign_keys=[pg_group.c.grolist])})

  use the trunk and say:

  mapper(PGUser, pg_user, properties={
       'groups': relation(PGGroup, viewonly=True,
           primaryjoin=pg_user.c.usesysid==func.any(pg_group.c.grolist),
           foreign_keys=[pg_group.c.grolist],
           _local_remote_pairs=[pg_user.c.usesysid, pg_group.c.grolist]
           )})

  this doesn't yet handle the full blown functions/casts in primaryjoin  
  conditions ticket but its part of the way there.
--~--~-~--~~~---~--~~
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: Extension proposal

2008-04-15 Thread Paul Johnston
Hi,

the function so far seems pretty use-case specific.  (only works in
 one direction, is hardcoded to the obj.mapper convention, sort of


Ok, fair enough. It looks like Elixir will accept this, and Jonathan also
made the observation that my approach is one-way. For the time being, I've
updated the usage recipe which should keep Lele and Iain happy for now.

If you do change your mind, my offer to produce a patch with unit tests
stands.

Paul

--~--~-~--~~~---~--~~
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] Problem with the session of SQLAlchemy

2008-04-15 Thread Chugo

Hello, I am setting the SQLAlchemy to work with meetings, but not the
rollback, no mistake, it keeps the data bb.dd. As if there were no
rollback in the code.
We show the example:

model.py

from elixir import *
from turbogears.database import metadata
options_defaults['autosetup'] = False
metadata.bind = 'sqlite:///devdata.sqlite'
metadata.bind.echo = True

class Persona(Entity):
nombre = Field(Unicode(30))
compras_realizadas = OneToMany('Compra', inverse='cliente')
using_options(tablename='personas')
..
..
.

controllers.py

from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy  import create_engine
engine = create_engine('sqlite:///devdata.sqlite')
Session = sessionmaker(bind=engine, autoflush=False,
transactional=False)
sess = Session()

def procesar_compra(self, cliente, articulo, cantidad):

#Trae los objetos correspondientes a cada id que viene
aux_articulo = Articulo.get(articulo)
aux_cliente = Persona.get(cliente)

#calcula el valor de la compra
total = cantidad * float(aux_articulo.precio)

# Generamos la orden.
#elixir.session.begin()
sess.begin()
comp = Compra(cliente=aux_cliente, articulo=aux_articulo,
cantidad=cantidad,
total=total)
#sess.save(comp)
#elixir.session.flush()
sess.flush()

# Obtengo la cantidad en stock y la instancia stock para ese
articulo.
stock_cantidad = aux_articulo.stock.cantidad
stock = Stock.get(aux_articulo.stock.id)

#Calcula lo que va quedar en deposito(si acepto el pedido)
despues
#pregunto si es 0, o cual me dice que puedo aceptar el
pedido, si
#no es asi, debo hacer el rollback de la clase Compra, ya que
#cree la instancia, debuio a que no dispongo con el stcok
suficiente
#para responder al pedido realizado
restan = int(stock_cantidad) - int(cantidad)
if restan = 0:
print '/'*50
sess.rollback()
#sess.close()
#elixir.session.commit()
# session.close()
print '#'*50
flash('No hay stock disponible')
raise redirect('/index')

else:
stock.cantidad = restan
#elixir.session.commit()
sess.commit()
print '*'*50
print 'Quedan en deposito'
print stock.cantidad
print '*'*50

flash('Compra realizada con exito')
raise redirect('/index')

I wanted to ask if it's okay configuration of the meeting and if the
method procesar_compra is well used begin, flush, commit and
rollback.
Thank you and greetings.
An Embrace

--~--~-~--~~~---~--~~
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] sqlalchemy migration/schema creation

2008-04-15 Thread Lukasz Szybalski

Hello,
Is there maybe a feature in sqlalchemy that would allow me to autoload
table from one database, and move it over to another database?

1. I would like to print data structure from autoload table. (then
copy and paste it into new file  and use it to create new
table)(without typing every data structure)
2. And/or autoload via one engine and autoupload via different engine
and create_all()
3. Analyze csv files and create sqlalchemy definition like structure.

Ideas?

Lucas

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---