[sqlalchemy] Re: Separating session and db/models definitions

2009-02-25 Thread King Simon-NFHD78
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of bsdemon Sent: 24 February 2009 20:22 To: sqlalchemy Subject: [sqlalchemy] Separating session and db/models definitions Hello. I have the following states of things: 1) I

[sqlalchemy] Re: Separating session and db/models definitions

2009-02-25 Thread Andrey Popp
Yes, it is really what I need. Thanks! I must read docs more careful. On Wed, Feb 25, 2009 at 12:40 PM, King Simon-NFHD78 simon.k...@motorola.com wrote: -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of bsdemon Sent: 24 February

[sqlalchemy] Re: Self Join via Join Table ?

2009-02-25 Thread az
u mean, the Bar is an association table of Foo to Foo? u have to use secondary_table and/or secondary_join in the relation setup. And probably specify remote_side or it may not know which Foo is what. On Wednesday 25 February 2009 03:39:20 Stef wrote: Hello Everyone, First of all, kudos

[sqlalchemy] Re: Problems with cursor, don't know what to do.

2009-02-25 Thread Timothy N. Tsvetkov
More info: I have MacOSX and use iODBC with FreeTDS driver. And looks like everything is OK: FreeTDS: [tu...@2kan-2:~/bigur]% tsql -S libra -p 1433 -U user locale is ru_RU.KOI8-R/UTF-8/ru_RU.KOI8-R/ru_RU.KOI8-R/ru_RU.KOI8-R/ ru_RU.KOI8-R locale charset is Password: 1 select * from tax 2 go

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Ashish Bhatia
sorry its resolved and working On Feb 25, 12:20 pm, Ash ashishsinghbha...@gmail.com wrote: Hello , I am trying to make query like select (a+b) from xyz; to do this xyz = sqlalchemy.Table('xyz',metadata) a = sqlalchemy.Column('a', sqlalchemy.Integer) xyz.append_column(a) b =

[sqlalchemy] Re: using relation in non-declarative table and class definitions (newbie problem)

2009-02-25 Thread kindly
You add the relation to the propoties on mapper. Look at http://www.sqlalchemy.org/docs/05/mappers.html#basic-relational-patterns On Feb 24, 4:10 pm, Marcin Krol mrk...@gmail.com wrote: Hello everyone, I've been following tutorialhttp://www.sqlalchemy.org/docs/05/ormtutorial.htmlwhich

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Ashish Bhatia
The problem is still their. The two seprate list of columns = List of sqlalchem object operator = ['+'','-'] using join to join them will convert the columns object to string which is not desirable. Any way to fix this. On Feb 25, 3:54 pm, Ashish Bhatia ashishsinghbha...@gmail.com wrote:

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread King Simon-NFHD78
Could you use the python 'operator' module (http://docs.python.org/library/operator.html)? Eg. (untested): import operator operations = { '+': operator.add, '-': operator.sub, # etc. } def combine_columns(op, *cols): return operations[op](*cols) sum_column =

[sqlalchemy] dynamic relation filtering

2009-02-25 Thread Vladimir Iliev
hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like part.documents.filter(Part.documents.of_type(CADDocument)) but i'm getting ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement or string

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Gunnlaugur Thor Briem
Whoops, premature send, sorry. For an arbitrary list of columns, such as t.c (the column collection) or other SQL selectables, such as the above binary expressions, you can use sum(columns). E.g.: t = Table('bobloblaw', MetaData(), Column('a', Integer), Column('b', Integer), Column('c', Integer))

[sqlalchemy] Re: Use with multiple Processes

2009-02-25 Thread Daniel
Hi, your suggestion sounds really reasonable but the point is that these processes are running on different machines and I don't want to put a lot of effort in synchronizing these threads. Isn't there any easy solution for having multiple processes working on the same database table? Thanks.

[sqlalchemy] Re: dynamic relation filtering

2009-02-25 Thread az
thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to instances of a given class, including the subclasses ? i tried something like

[sqlalchemy] export and import JSON from database (JSON type)

2009-02-25 Thread Gregg Lind
How does one create a TypeDecorator to export and import JSON to a database using SA? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

[sqlalchemy] Re: dynamic relation filtering

2009-02-25 Thread Vladimir Iliev
InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25 February 2009 15:43:54 Vladimir Iliev wrote: hi, how can i filter dynamic relation's query to

[sqlalchemy] Re: Problems with cursor, don't know what to do.

2009-02-25 Thread Michael Bayer
what happens if you try your stuff without using freeTDS at all ? lots of problems are reported with FreeTDS and I had my own negative experience with it recently. On Feb 25, 2009, at 5:35 AM, Timothy N. Tsvetkov wrote: More info: I have MacOSX and use iODBC with FreeTDS driver. And

[sqlalchemy] Re: Use with multiple Processes

2009-02-25 Thread Michael Bayer
entirely different machines, then youd have to partition out rows from the table yourself. you'd select some range of rows using LIMIT/ OFFSET on each machine to be processed. the exact count would depend on the total rows in the table and the total number of machines. On Feb 25, 2009,

[sqlalchemy] Re: dynamic relation filtering

2009-02-25 Thread Michael Bayer
with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion a...@svilendobrev.com написа: thequery().with_polymorphic( list of classes ) ? On Wednesday 25

[sqlalchemy] Re: dynamic relation filtering

2009-02-25 Thread Vladimir Iliev
so it's not possible to reuse relation's query definition ? Michael Bayer написа: with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError: Query.with_polymorphic() being called on a Query with existing criterion

[sqlalchemy] Ordering results of a WHERE x in y query by y

2009-02-25 Thread Gunnlaugur Briem
Hi all, having a x IN y query, with y supplied as input to the query: session.query(C).filter(C.someattr.in_(valuelist)) is there a way to tell SQLAlchemy to order the results according to valuelist? I.e. not by the natural order of someattr, but by the arbitrary order seen in valuelist?

[sqlalchemy] Connecting with Windows Auth?

2009-02-25 Thread Adam Pletcher
Is it possible to connect to a server using Windows Authentication using sqlalchemy? I have a MSSQL server database where my Windows account is needed to create tables. I didn’t turn up anything on the connection syntax for this when I searched. Thanks in advance. - Adam

[sqlalchemy] Re: dynamic relation filtering

2009-02-25 Thread Michael Bayer
not currently no On Feb 25, 2009, at 10:46 AM, Vladimir Iliev wrote: so it's not possible to reuse relation's query definition ? Michael Bayer написа: with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote: InvalidRequestError:

[sqlalchemy] Re: export and import JSON from database (JSON type)

2009-02-25 Thread Roger Demetrescu
On Wed, Feb 25, 2009 at 11:39, Gregg Lind gregg.l...@gmail.com wrote: How does one create a TypeDecorator to export and import JSON to a database using SA? I did something like that recently: - from sqlalchemy import types import simplejson class

[sqlalchemy] Re: export and import JSON from database (JSON type)

2009-02-25 Thread Gregg Lind
Thank you, that's simpler than my attempts, for sure! On Wed, Feb 25, 2009 at 10:27 AM, Roger Demetrescu roger.demetre...@gmail.com wrote: On Wed, Feb 25, 2009 at 11:39, Gregg Lind gregg.l...@gmail.com wrote: How does one create a TypeDecorator to export and import JSON to a database

[sqlalchemy] Re: dynamic relation filtering

2009-02-25 Thread Michael Bayer
so...workaround, use a new query against the target object and call with_parent(), given the parent object. I didnt realize earlier this was with a dynamic relation. this is something we should try to support. with_polymorphic() is tricky since it implies a potential filtering to be

[sqlalchemy] Re: dynamic relation filtering

2009-02-25 Thread Vladimir Iliev
ok, thanks Michael Bayer написа: not currently no On Feb 25, 2009, at 10:46 AM, Vladimir Iliev wrote: so it's not possible to reuse relation's query definition ? Michael Bayer написа: with_polymorphic() needs to be called first. On Feb 25, 2009, at 9:54 AM, Vladimir Iliev wrote:

[sqlalchemy] single table inheritance and changing object's type

2009-02-25 Thread Vladimir Iliev
how can i change the type of mapped object using single table inheritance? thanks --~--~-~--~~~---~--~~ 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

[sqlalchemy] Re: export and import JSON from database (JSON type)

2009-02-25 Thread Roger Demetrescu
On Wed, Feb 25, 2009 at 13:40, Gregg Lind gregg.l...@gmail.com wrote: Thank you, that's simpler than my attempts, for sure! You're welcome. Note that this implementation is very simple. Depending of your use case, you probably should take a look at MutableType [1] and

[sqlalchemy] Re: single table inheritance and changing object's type

2009-02-25 Thread Michael Bayer
update the type column directly , expunge the old object and then reload - or use merge() in a similar way if that suits the use case better. the ORM doesn't support in place type changes currently. On Feb 25, 2009, at 11:55 AM, Vladimir Iliev wrote: how can i change the type of mapped

[sqlalchemy] Re: dynamic relation filtering

2009-02-25 Thread Michael Bayer
also if you're using single table inheritance, you should be able to get away without needing with_polymorphic to query on subclasses. On Feb 25, 2009, at 11:41 AM, Vladimir Iliev wrote: ok, thanks Michael Bayer написа: not currently no On Feb 25, 2009, at 10:46 AM, Vladimir Iliev

[sqlalchemy] Re: Self Join via Join Table ?

2009-02-25 Thread Stephen Telford
Hello Az, Yes, Bar is the association table of Foo to Foo. In essence, this is a self join through a join table.. I have tried and hit my head on this for (quite literally) hours. In the end, and for the record, I ended up creating a method on the model itself such as ; def

[sqlalchemy] Re: Self Join via Join Table ?

2009-02-25 Thread Michael Bayer
check out the association proxy extension if you're looking to have Bar be hidden as an association object. it will ultimately use Foo/Bar for querying but attribute access would be proxied through the names you confgure. On Feb 25, 2009, at 4:11 PM, Stephen Telford wrote: Hello Az,

[sqlalchemy] Re: Self Join via Join Table ?

2009-02-25 Thread Stephen Telford
Okay, that sounds like a plan but., not to sound too much like a broken record, does anyone have an -actual- example ? looking at pages with a lot of API's is not really going to help me too much :( This maybe slightly off-topic and it's really NOT meant as flamebait but.. I remember a while ago

[sqlalchemy] Re: Self Join via Join Table ?

2009-02-25 Thread Bobby Impollonia
I am doing something similar. The following code works for me in SQLA .4.8 class Foo(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) bar_table = Table('bar', Base.metadata, Column('parent_id', Integer, ForeignKey('foo.id'), nullable=False), Column('child_id',

[sqlalchemy] Re: Self Join via Join Table ?

2009-02-25 Thread Stephen Telford
Thank you Bobby!! That does make things more easier, and it shows then that I am being a -real- moron here.. from sqlalchemy import * from sqlalchemy.orm import sessionmaker, mapper, relation meta = MetaData() meta.bind = 'postgres://root:sxta...@192.168.2.198/compass_master' engine =

[sqlalchemy] Re: Self Join via Join Table ?

2009-02-25 Thread Stephen Telford
and of course, both the passwords -are- the same (duh ;) .. the 'get()' works fine (obviously ;) Regards Stef On Wed, Feb 25, 2009 at 7:53 PM, Stephen Telford stelford1...@gmail.comwrote: Thank you Bobby!! That does make things more easier, and it shows then that I am being a -real- moron

[sqlalchemy] Re: app memory leak - execute() with SA 0.5.2, PG 8.3, Psycopg2

2009-02-25 Thread Peter Hansen
Allen Bierbaum wrote: On Tue, Feb 24, 2009 at 4:44 AM, Chris Miles miles.ch...@gmail.com wrote: On Feb 22, 6:08 am, Allen Bierbaum abierb...@gmail.com wrote: Python 2.5 and later will free up garbage collected memory, handing it back to the system. Previous versions of Python would never

[sqlalchemy] Re: Self Join via Join Table ?

2009-02-25 Thread Michael Bayer
page 199 of the SQLAlchemy oreilly book talks about association proxy ;) On Feb 25, 2009, at 6:12 PM, Stephen Telford wrote: Okay, that sounds like a plan but., not to sound too much like a broken record, does anyone have an -actual- example ? looking at pages with a lot of API's is not

[sqlalchemy] Re: app memory leak - execute() with SA 0.5.2, PG 8.3, Psycopg2

2009-02-25 Thread Allen Bierbaum
I hadn't described the details be there is not much to the work around and pretty application specific. The summary is that I moved some application level filtering that was being done in python code on the results into the query so less results are returned. This saves a great deal of memory

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Ashish Bhatia
This works fine But in the mine case columns = [a,b,c] operator = ['+','-'] comes in the list And it can go to n number. So while adding it creates a problem My approach looping on columns i append it in to the table and hence making the object i can join them with operator to form the

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Ashish Bhatia
This works fine Thanks for the idea i will try it for the case and get back to here in the case of problem On Feb 25, 6:32 pm, King Simon-NFHD78 simon.k...@motorola.com wrote: Could you use the python 'operator' module (http://docs.python.org/library/operator.html)? Eg. (untested): import

[sqlalchemy] An instance's attributes lost while the other updated.

2009-02-25 Thread 一首诗
Hi all, I have 2 user instance in a session and after I have update one of it like this --- u = session.merge(u) session.commit session.refresh(u)

[sqlalchemy] What's the use of expunge?

2009-02-25 Thread 一首诗
The document says: Expunge removes an object from the Session, sending persistent instances to the detached state, and pending instances to the transient state: I hoped that if an

[sqlalchemy] Re: An instance's attributes lost while the other updated.

2009-02-25 Thread 一首诗
A little more code to explain: Before commit, print u2 doesn't do trigger query. After commit, print u2 trigger a query, even if it has different primary key with u1. So this means : when u update one instance, the other instance of the same type will be in expired state.