Re: [sqlalchemy] custom __init__ methods not being invoked

2013-01-07 Thread Michael van Tellingen
See http://docs.sqlalchemy.org/en/latest/orm/mapper_config.html#constructors-and-object-initialization On Mon, Jan 7, 2013 at 4:47 AM, RM ryan.mckil...@gmail.com wrote: I have a class which inherits from Base. My class has a metaclass which inherits from DeclarativeMeta. Among other things,

Re: [sqlalchemy] custom __init__ methods not being invoked

2013-01-07 Thread Ryan McKillen
Worked like a charm. Thanks. — RM On Mon, Jan 7, 2013 at 6:26 PM, Michael van Tellingen michaelvantellin...@gmail.com wrote: See http://docs.sqlalchemy.org/en/latest/orm/mapper_config.html#constructors-and-object-initialization On Mon, Jan 7, 2013 at 4:47 AM, RM ryan.mckil...@gmail.com

Re: [sqlalchemy] Array with custom types in SqlAlchemy 0.8b2

2013-01-07 Thread Hans Lellelid
I am looking to adapt this code for a related array/type issue. The code from https://gist.github.com/4433940 works just fine for me (as expected) when building/executing the stmt directly, but not when using the ORM. When row is created using ORM, like this: # snip s =

Re: [sqlalchemy] Array with custom types in SqlAlchemy 0.8b2

2013-01-07 Thread Michael Bayer
this is ticket http://www.sqlalchemy.org/trac/ticket/2648 and cannot be worked around at this time. If you're working with arrays of UUID I'd recommend using psycopg2 type processors, as the previous poster has had success with. On Jan 7, 2013, at 9:39 AM, Hans Lellelid wrote: I am

Re: [sqlalchemy] Array with custom types in SqlAlchemy 0.8b2

2013-01-07 Thread Michael Bayer
correction, this seems to work, though will try to improve: class UUID_ARRAY(TypeDecorator): impl = ARRAY(UUID, dimensions=1) def bind_expression(self, bindvalue): if bindvalue.callable: val = bindvalue.callable() else: val = bindvalue.value

Re: [sqlalchemy] Array with custom types in SqlAlchemy 0.8b2

2013-01-07 Thread Michael Bayer
change again, that doesn't work. Upon reflection, I think the case here is that there's no alternative but to make sure psycopg2 can properly format the contents of the ARRAY itself. This is because SQLAlchemy is producing a completed INSERT statement for preparation, without the parameters

Re: [sqlalchemy] Array with custom types in SqlAlchemy 0.8b2

2013-01-07 Thread Hans Lellelid
Thanks for the follow up. Upon further reading/reflection, I discovered that wrapping my string IP address values in the psycopg2.extras.Inet object and then passing that in -- and executing psycopg2.extras.register_inet() as with the UUID example -- seems to work fine for both ORM and

Re: [sqlalchemy] How to handle 'sub-commits'?

2013-01-07 Thread Michael Bayer
On Jan 7, 2013, at 1:11 AM, Ken Lareau wrote: Okay, this is what I suspected and feared. :) Creating new sessions isn't much of an issue, and I came up with a class to manage this for me before realizing my problem is going to end up being much deeper... My current library that uses

[sqlalchemy] how to create mysql database in sqlalchemy?

2013-01-07 Thread junepeach
I ran below code as a root user: import sqlalchemy engine = sqlalchemy.create_engine('mysql://user:password@server') # connect to server engine.execute(CREATE DATABASE mydb) #create db engine.execute(USE mydb) # select new db However the database couldn't be created. The error I got is: File

[sqlalchemy] Strange behaviour while trying to swap related records, or am I doing it wrong?

2013-01-07 Thread Alexey Vihorev
Hi all! I'm trying to use sqlalchemy.ext.orderinglist as per instructions here http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/orderinglist.html , and but I've encountered a loss of data while trying to swap positions of related records inside a related property list. I thought it was

Re: [sqlalchemy] MySQL has gone away

2013-01-07 Thread Diego Woitasen
On Thursday, December 27, 2012 10:22:08 PM UTC-3, Michael Bayer wrote: On Dec 27, 2012, at 6:28 PM, Diego Woitasen wrote: Hi, I know that this was discussed several times in the past but I can't solve the problem with the tip that I read in this list. Every morning my application dies

Re: [sqlalchemy] Strange behaviour while trying to swap related records, or am I doing it wrong?

2013-01-07 Thread Michael Bayer
On Jan 7, 2013, at 7:05 PM, Alexey Vihorev wrote: p.children[1], p.children[2] = p.children[2], p.children[1] print(p.children) #prints [Mary, Kenny, John] yeah, without looking too deeply I'm fairly certain this is this trac ticket: http://www.sqlalchemy.org/trac/ticket/1103

Re: [sqlalchemy] MySQL has gone away

2013-01-07 Thread Michael Bayer
On Jan 7, 2013, at 7:20 PM, Diego Woitasen wrote: I'm back to this :) My problem was that I'm not closing the session properly. My new question is... is there a way to autoclose the session? My example, at the end of the scope? What's the recommend way to do this? I've read

Re: [sqlalchemy] MySQL has gone away

2013-01-07 Thread Warwick Prince
On Jan 7, 2013, at 7:20 PM, Diego Woitasen wrote: I'm back to this :) My problem was that I'm not closing the session properly. My new question is... is there a way to autoclose the session? My example, at the end of the scope? What's the recommend way to do this? I've read

Re: [sqlalchemy] MySQL has gone away

2013-01-07 Thread Michael Bayer
On Jan 7, 2013, at 7:47 PM, Warwick Prince wrote: On Jan 7, 2013, at 7:20 PM, Diego Woitasen wrote: I'm back to this :) My problem was that I'm not closing the session properly. My new question is... is there a way to autoclose the session? My example, at the end of the scope?

RE: [sqlalchemy] Strange behaviour while trying to swap related records, or am I doing it wrong?

2013-01-07 Thread Alexey Vihorev
Tried to replace this with this, but results are the same temp1 = p.children[1] temp2 = p.children[2] p.children[2] = temp1 p.children[1] = temp2 From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Michael Bayer Sent: Tuesday, January 08, 2013 2:23 AM

[sqlalchemy] How to Use Alias in ORDER BY Caluse?

2013-01-07 Thread Ji Zhang
Hi, My SQL is like select host, count(*) as cnt from tbl group by host order by cnt desc How to achieve this using ORM? session.query(Tbl.host, func.count('*').label('cnt')).group_by(Tbl.host).order_by(???) I don't wanna type again func.count... in order_by(). Thanks. -- You received this

Re: [sqlalchemy] Strange behaviour while trying to swap related records, or am I doing it wrong?

2013-01-07 Thread Michael Bayer
assuming you can try 0.8 which provides inspect(), this will show what is happening: from sqlalchemy import inspect print p.children[2] = c2 print p.children print inspect(c2).attrs.parent.history print inspect(c3).attrs.parent.history print

Re: [sqlalchemy] How to Use Alias in ORDER BY Caluse?

2013-01-07 Thread Michael Bayer
On Jan 7, 2013, at 9:19 PM, Ji Zhang wrote: Hi, My SQL is like select host, count(*) as cnt from tbl group by host order by cnt desc How to achieve this using ORM? session.query(Tbl.host, func.count('*').label('cnt')).group_by(Tbl.host).order_by(???) I don't wanna type again

Re: [sqlalchemy] How to Use Alias in ORDER BY Caluse?

2013-01-07 Thread Ji Zhang
The second one is neat. Thanks~ On Tuesday, January 8, 2013 11:28:34 AM UTC+8, Michael Bayer wrote: On Jan 7, 2013, at 9:19 PM, Ji Zhang wrote: Hi, My SQL is like select host, count(*) as cnt from tbl group by host order by cnt desc How to achieve this using ORM?