[sqlalchemy] Re: Opinion on correct use of Sqlalchemy

2007-04-09 Thread Michael Bayer


On Apr 9, 2007, at 10:06 PM, Huy Do wrote:

>
> Michael Bayer wrote:
>> Particularly for your query you are doing an eager load between
>> "asset" and "location" yet a lot of your query criterion depends upon
>> "location", so in that sense yes you have to use custom SQL, since
>> query() will never involve eager loaded joins in the query criterion.
>
> Hi Michael,
>
> Everything you say makes perfect sense for 1:N relationships, but  
> in my
> case, and with alot of other cases where I need the order by or the
> criteria/filter on the joined table, it's a 1:1. In these cases I'm  
> not
> sure why SA can't generate the same type of SQL statement that I am
> above. It would make perfect sense for it to.
>
> I understand the eagerload problem with a list of child objects but  
> with
> 1:1 relations I think the query interface should be querying in the  
> same
> way that my manual SQL is.

sorry, i just dont think that the loader strategy should *ever* have  
any effect on the primary results...otherwise loader strategies  
become intertwined with querying, and mappers become brittle since  
you can no longer change eager/lazy loads without breaking the  
results of your query.  additionally for the eager loaders to guess  
when they should create non-aliased criterion and when they should  
create aliased criterion would be magical and complicated, and render  
improvements to eager loading impossible since people would be  
structutring their queries off of a now expected behavior which could  
then never change.   it also implies that a lazy-loading mapper setup  
would break when eager loading is enabled via options, since the  
eager loader "expects" that its going to be used in query criterion,  
doesnt apply its aliases, and then changes the results of the query.   
so it definitely breaks a lot of widely accepted behavior.

there are tools to join eager loads with query criterion which are  
contains_eager() and instances() or explcit select() objects passed  
to query.select().  id favor adding new mapper options to generate  
criterion that is simlar to that of the eager loader (such as, using  
contains_eager() with a Query-compiled query will add the columns in  
and the join for you) but loader strategies by default will never  
purposefully inject themselves into application query criterion.










--~--~-~--~~~---~--~~
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: Opinion on correct use of Sqlalchemy

2007-04-09 Thread Huy Do

Michael Bayer wrote:
> On Apr 7, 2007, at 8:11 AM, HD Mail wrote:
>
>   
>> Hi,
>>
>> I was after some opinions on the following use of SA.
>>
>> 1. Is there any problems using SA in this way ?
>> 2. Is there better ways of achieving this ?
>>
>> 
> ...
>   
>> query = db.query(model.Asset).options(contains_eager('location'),
>> contains_eager('type'))
>> r = query.instances(s.execute())
>> return r, count
>>
>> 
>
> that youve constructed exactly the query you want and used it via  
> instances() is exactly how i want people to use SQLAlchemy when they  
> know what non-trivial SQL they want to issue.  query() only creates a  
> very specific kind of SQL and it could never support figuring out how  
> to construct the SQL that you already know how to do.
>
> Particularly for your query you are doing an eager load between  
> "asset" and "location" yet a lot of your query criterion depends upon  
> "location", so in that sense yes you have to use custom SQL, since  
> query() will never involve eager loaded joins in the query criterion.
>
> however, theres a reason query follows this behavior, which is that  
> if you are loading Asset objects with an eager loaded list of  
> Location objects, but you have placed limiting criterion on the list  
> of Locations specifically, you will now have Asset objects whose  
> loaded list of Locations may not be complete compared to whats in the  
> database (and they will remain that way until those instances are  
> expire()d or similar).   So you should be aware that that is the  
> effect youre getting in your code.
>   

Hi Michael,

Everything you say makes perfect sense for 1:N relationships, but in my 
case, and with alot of other cases where I need the order by or the 
criteria/filter on the joined table, it's a 1:1. In these cases I'm not 
sure why SA can't generate the same type of SQL statement that I am 
above. It would make perfect sense for it to.

I understand the eagerload problem with a list of child objects but with 
1:1 relations I think the query interface should be querying in the same 
way that my manual SQL is.

> also the separate "count()" step may be problematic since consider it  
> wont return just the number of Asset objects loaded, but the number  
> of rows total, which is Asset * Location * AssetType object rows.  if  
> you want just the number of Asset's returned youd just return len(r).
>   
You're right, but because the the joins are 1:1, len(r) and count() will 
give me the same result.

Thanks

Huy
> >   


--~--~-~--~~~---~--~~
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: problems with threadlocal strategy and ResultProxy

2007-04-09 Thread Michael Bayer

id very much prefer a test case that isnt using Twisted since Ive no  
idea what twisted does with threads.  it looks like the result proxy  
is being shared between threads (which i believe is an effect of the  
twisted reactor anyway?).

if youre playing with threads to that degree the "threadlocal"  
strategy may be too simplistic.


On Apr 9, 2007, at 5:41 PM, Manlio Perillo wrote:

>
> Hi.
>
> I have found some problems with threadlocal strategy and the  
> ResultProxy.
>
> Here is the code that reproduces the problem, Twisted and  
> PostgreSQL are
> required.
>
> I'm using SQLAlchemy 0.3.6-1 from Debian Etch.
>
> I don't know if this is a bug of SQLAlchemy.
> Is the ResultProxy thread safe?
>
>
>
> #! /usr/bin/env python
> import sys
>
> from twisted.python import log
> from twisted.internet import defer, threads, reactor
>
> import sqlalchemy as sq
>
>
> def callback(result, i):
>  # Is the ResultProxy thread safe?
>  if USE_CURSOR:
>  rows = list(result)
>
>  log.msg('callback', i)
>
> def errback(reason):
>  log.err(reason)
>
> def f():
>  l = []
>
>  for i in range(N):
>  log.msg('request', i)
>  d = threads.deferToThread(db.execute, QUERY)
>  d.addCallbacks(callback, errback, callbackArgs=(i,))
>  l.append(d)
>
>  return defer.DeferredList(l)
>
> def main():
>  return f().addCallbacks(lambda _: None, lambda r: log.err(r)
>  ).addBoth(lambda _: reactor.stop())
>
>
> POOL_SIZE = 1
> N = 10
> QUERY = 'SELECT CURRENT_TIMESTAMP'
> URL = 'postgres://manlio:[EMAIL PROTECTED]/test'
> STRATEGY = 'threadlocal'
> USE_CURSOR = False
>
>
> reactor.suggestThreadPoolSize(POOL_SIZE)
> db = sq.create_engine(URL, pool_size=POOL_SIZE, strategy=STRATEGY,
>echo_pool=False)
>
> log.startLogging(sys.stdout)
> reactor.callWhenRunning(main)
>
> reactor.run()
>
>
>
> When USE_CURSOR is False, I got (at random) the error:
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line  
> 718,
> in execute
>  connection = self.contextual_connect 
> (close_with_result=True)
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/threadlocal.py",
> line 148, in contextual_connect
>  return self.session.get_connection(**kwargs)
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/threadlocal.py",
> line 21, in get_connection
>  return TLConnection(self,  
> close_with_result=close_with_result)
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/threadlocal.py",
> line 63, in __init__
>  base.Connection.__init__(self, session.engine,
> close_with_result=close_with_result)
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line  
> 368,
> in __init__
>  self.__connection = connection or engine.raw_connection()
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/threadlocal.py",
> line 127, in raw_connection
>  return self.connection_provider.get_connection()
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/default.py", line
> 19, in get_connection
>  return self._pool.connect()
>File "/usr/lib/python2.4/site-packages/sqlalchemy/pool.py",
> line 150, in connect
>  return
> self._threadconns[thread.get_ident()].connfairy().checkout()
>  exceptions.AttributeError: 'NoneType' object has no attribute
> 'checkout'
>
>
> When USE_CURSOR is True, I obtain (at random) any of these two errors:
>File "./concurrency.twisted.py", line 12, in callback
>  rows = list(result)
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line  
> 921,
> in __iter__
>  row = self.fetchone()
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line  
> 997,
> in fetchone
>  self.close()
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line  
> 862,
> in close
>  self.cursor.close()
>File "/usr/lib/python2.4/site-packages/sqlalchemy/pool.py",
> line 312, in close
>  if self in self.__parent._cursors:
>  exceptions.TypeError: iterable argument required
>
>
> and:
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line  
> 719,
> in execute
>  return connection.execute(statement, *multiparams,  
> **params)
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line  
> 444,
> in execute
>  return Connection.executors[c](self, object,  
> *multiparams,
> **params)
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line  
> 458,
> in execute_text
>  cursor = self._execute_raw(statement, parameters)
>File
> "/usr/lib/python2.4/site-packages/sqlalchemy/engine/

[sqlalchemy] Re: handing SELECT ... FOR UPDATE

2007-04-09 Thread Jonathan LaCour

Jonathan LaCour wrote:

> What would be the best way to approach using `SELECT ... FOR UPDATE`?

Answering my own question, it appears that there is a `lockmode`
kwarg you can pass when creating a query that supports 'update' and
'update_nowait' as values:

 query = session.query(Queue, lockmode='update')

Just to make sure: is this what I need to be using, or am I missing
something?  I found this by digging through the source since its not
mentioned in the docs, and it looks like it does what I want.

--
Jonathan LaCour
http://cleverdevil.org




--~--~-~--~~~---~--~~
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] problems with threadlocal strategy and ResultProxy

2007-04-09 Thread Manlio Perillo

Hi.

I have found some problems with threadlocal strategy and the ResultProxy.

Here is the code that reproduces the problem, Twisted and PostgreSQL are
required.

I'm using SQLAlchemy 0.3.6-1 from Debian Etch.

I don't know if this is a bug of SQLAlchemy.
Is the ResultProxy thread safe?



#! /usr/bin/env python
import sys

from twisted.python import log
from twisted.internet import defer, threads, reactor

import sqlalchemy as sq


def callback(result, i):
 # Is the ResultProxy thread safe?
 if USE_CURSOR:
 rows = list(result)

 log.msg('callback', i)

def errback(reason):
 log.err(reason)

def f():
 l = []

 for i in range(N):
 log.msg('request', i)
 d = threads.deferToThread(db.execute, QUERY)
 d.addCallbacks(callback, errback, callbackArgs=(i,))
 l.append(d)

 return defer.DeferredList(l)

def main():
 return f().addCallbacks(lambda _: None, lambda r: log.err(r)
 ).addBoth(lambda _: reactor.stop())


POOL_SIZE = 1
N = 10
QUERY = 'SELECT CURRENT_TIMESTAMP'
URL = 'postgres://manlio:[EMAIL PROTECTED]/test'
STRATEGY = 'threadlocal'
USE_CURSOR = False


reactor.suggestThreadPoolSize(POOL_SIZE)
db = sq.create_engine(URL, pool_size=POOL_SIZE, strategy=STRATEGY,
   echo_pool=False)

log.startLogging(sys.stdout)
reactor.callWhenRunning(main)

reactor.run()



When USE_CURSOR is False, I got (at random) the error:
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 718,
in execute
 connection = self.contextual_connect(close_with_result=True)
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/threadlocal.py",
line 148, in contextual_connect
 return self.session.get_connection(**kwargs)
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/threadlocal.py",
line 21, in get_connection
 return TLConnection(self, close_with_result=close_with_result)
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/threadlocal.py",
line 63, in __init__
 base.Connection.__init__(self, session.engine,
close_with_result=close_with_result)
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 368,
in __init__
 self.__connection = connection or engine.raw_connection()
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/threadlocal.py",
line 127, in raw_connection
 return self.connection_provider.get_connection()
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/default.py", line
19, in get_connection
 return self._pool.connect()
   File "/usr/lib/python2.4/site-packages/sqlalchemy/pool.py",
line 150, in connect
 return
self._threadconns[thread.get_ident()].connfairy().checkout()
 exceptions.AttributeError: 'NoneType' object has no attribute
'checkout'


When USE_CURSOR is True, I obtain (at random) any of these two errors:
   File "./concurrency.twisted.py", line 12, in callback
 rows = list(result)
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 921,
in __iter__
 row = self.fetchone()
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 997,
in fetchone
 self.close()
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 862,
in close
 self.cursor.close()
   File "/usr/lib/python2.4/site-packages/sqlalchemy/pool.py",
line 312, in close
 if self in self.__parent._cursors:
 exceptions.TypeError: iterable argument required


and:
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 719,
in execute
 return connection.execute(statement, *multiparams, **params)
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 444,
in execute
 return Connection.executors[c](self, object, *multiparams,
**params)
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 458,
in execute_text
 cursor = self._execute_raw(statement, parameters)
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 540,
in _execute_raw
 cursor = self.__engine.dialect.create_cursor(self.connection)
   File
"/usr/lib/python2.4/site-packages/sqlalchemy/databases/postgres.py",
line 277, in create_cursor
 return connection.cursor()
   File "/usr/lib/python2.4/site-packages/sqlalchemy/pool.py",
line 253, in cursor
 self.invalidate()
   File "/usr/lib/python2.4/site-packages/sqlalchemy/pool.py",
line 243, in invalidate
 raise exceptions.InvalidRequestError("This connection is
closed")
 sqlalchemy.exceptions.InvalidRequestError: This connection is
closed




Thanks and regards   Manlio Perillo


--~--~-~--~~-

[sqlalchemy] handing SELECT ... FOR UPDATE

2007-04-09 Thread Jonathan LaCour

So, at work, we have a particular use case where we need to be able
to do a `SELECT ... FOR UPDATE` in order to lock some rows.  In this
particular project we will be using the ORM package and some advanced
data mapping (including multiple table polymorphic inheritance).  What
would be the best way to approach using `SELECT ... FOR UPDATE`?

We were thinking about the possibility of creating a MapperExtension
to make this happen, but aren't really sure about how to go about
implementing that, and any direction would be useful.

Thanks!

--
Jonathan LaCour
http://cleverdevil.org




--~--~-~--~~~---~--~~
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] Selecting objects with null foreign keys

2007-04-09 Thread Ryan

Suppose I have a table/object called Node that maps to Host by
relation field 'host' on foreign key host_id that may be null.  Why
can't I do the following:

Query(Node).select_by(host=None)

When it seems obvious that I mean this:

Query(Node).select_by(Node.c.host_id==None)

I think the former would be cleaner, since I could just pass a 'host'
variable that may be None without having to check it manually first
before getting its id (however simple that might be).

Thanks.
Ryan


--~--~-~--~~~---~--~~
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: Dealing with undefined/NULL foreign keys

2007-04-09 Thread Brendan Arnold

Thanks thats brilliant.

Brendan

On 4/9/07, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
>
> On Apr 9, 2007, at 2:38 PM, Brendan Arnold wrote:
>
> >
> > Hi there,
> >
> >> of course theres another view of this, which is why does your
> >> application prefer a "blank" Address entry to None?  the latter is
> >> more semantically correct.
> >
> >
> > 
> >   Name:
> >   ${person.name}
> >   City:
> > % if person.address:
> > % city = person.address.city
> > % else:
> > % city = 'Not specified'
> >   ${city}
> > 
>
> gotya.  the None version is like:
>
> ${person.address and person.address.city or "Not Specified"}
>
> >
>

--~--~-~--~~~---~--~~
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: Dealing with undefined/NULL foreign keys

2007-04-09 Thread Michael Bayer


On Apr 9, 2007, at 2:38 PM, Brendan Arnold wrote:

>
> Hi there,
>
>> of course theres another view of this, which is why does your
>> application prefer a "blank" Address entry to None?  the latter is
>> more semantically correct.
>
>
> 
>   Name:
>   ${person.name}
>   City:
> % if person.address:
> % city = person.address.city
> % else:
> % city = 'Not specified'
>   ${city}
> 

gotya.  the None version is like:

${person.address and person.address.city or "Not Specified"}

--~--~-~--~~~---~--~~
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: Dealing with undefined/NULL foreign keys

2007-04-09 Thread Brendan Arnold

Hi there,

> of course theres another view of this, which is why does your
> application prefer a "blank" Address entry to None?  the latter is
> more semantically correct.

I'm exporting the Person object to a web-template and I prefer the following,


  Name:
  ${person.name}
  City:
  ${person.address.city or 'Not specified'}


to the following,


  Name:
  ${person.name}
  City:
% try:
% person.address.city
% except NameError:
% person.address = Address(city='Not specified')
  ${person.address.city}


or, perhaps better


  Name:
  ${person.name}
  City:
% if person.address:
% city = person.address.city
% else:
% city = 'Not specified'
  ${city}


Cheers!

Brendan

--~--~-~--~~~---~--~~
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: Dealing with undefined/NULL foreign keys

2007-04-09 Thread Michael Bayer


On Apr 9, 2007, at 11:25 AM, Brendan Arnold wrote:

> Is there a way I can ensure that an empty instance of my Address
> object is grafted onto the Person object even when corresponding data
> is not found in the people table?

you can either create a layer of abstraction between the actual  
mapped property and the publically accessible field by using a property:

class User(object):
def _get_address(self):
if self._address is None:
self._address = Address()
return self._address
address = property(_get_address)

mapper(User, users, properties={"_address":relation(Address)})


or you can use a MapperExtension and override create_instance():

class MyExt(MapperExtension):
def create_instance(self, mapper, selectcontext, row, class_):
instance = User()
if not row['address_id']:
instance.address = Address()
return instance

mapper(User, users, properties=..., extension=MyExt())

in both cases, flushing the User object will create a new address row  
in the DB since you have the blank address object there...to avoid  
that, you might have to add more layers of abstraction to the public  
"address" property.

of course theres another view of this, which is why does your  
application prefer a "blank" Address entry to None?  the latter is  
more semantically correct.

--~--~-~--~~~---~--~~
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: Putting Session.flush in a seperate thread

2007-04-09 Thread Michael Bayer


On Apr 9, 2007, at 11:54 AM, David Anderson wrote:

>
> On 4/9/07, Michael Bayer <[EMAIL PROTECTED]> wrote:
>>> I tried to build this already but I cannot figure out how to assign
>>> the shared connection to a thread. I always get 'No connection
>>> defined'.
>>
>> if youre on py2.4 check out threading.local().
>
> Just to be clear here, as I'm also having issues with SQA and
> threading : a connection is per-thread, so if I have 10 worker threads
> that each read/write to the db, I need to manually create 10
> connections and pass them into each thread? What would the elegant way
> to do this be?

the elegant way would be to not worry about the thread scope of a  
connection and just use connection pooling normally.  pull out a  
connection when needed, close it when complete (which is really just  
a return to the connection pool).  keep the scope of those two  
operations local to a single thread.

--~--~-~--~~~---~--~~
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: Support for ordered lists of child items

2007-04-09 Thread Michael Bayer

we dont have the capability to automatically update ordering columns  
when the elements of a list are moved around.  if you move the  
elements around, you need to execute some step that will update the  
index columns (or create a custom collection class that does this for  
you).

On Apr 9, 2007, at 12:42 PM, Aaron Digulla wrote:

>
> Hello,
>
> I'm looking for a feature but couldn't find it in the docs.
>
> I have a tree like structure where the user can specify the order of
> the children of a node. In DB lingo, I have a parentId and an index
> column. When I load children, they should be ordered by the index.
> This seems to be supported.
>
> Can SA also update the index column when I move children in the list
> around? Like:
>
> # ... parent has three children A, B C
> item = parent.children[0]
> del parent.children[0]
> parent.children.insert (1, item)
> # now, parent has three children B, A, C
>
> Regards,
>
>
> >


--~--~-~--~~~---~--~~
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] Support for ordered lists of child items

2007-04-09 Thread Aaron Digulla

Hello,

I'm looking for a feature but couldn't find it in the docs.

I have a tree like structure where the user can specify the order of
the children of a node. In DB lingo, I have a parentId and an index
column. When I load children, they should be ordered by the index.
This seems to be supported.

Can SA also update the index column when I move children in the list
around? Like:

# ... parent has three children A, B C
item = parent.children[0]
del parent.children[0]
parent.children.insert (1, item)
# now, parent has three children B, A, C

Regards,


--~--~-~--~~~---~--~~
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: Putting Session.flush in a seperate thread

2007-04-09 Thread David Anderson

On 4/9/07, Michael Bayer <[EMAIL PROTECTED]> wrote:
> > I tried to build this already but I cannot figure out how to assign
> > the shared connection to a thread. I always get 'No connection
> > defined'.
>
> if youre on py2.4 check out threading.local().

Just to be clear here, as I'm also having issues with SQA and
threading : a connection is per-thread, so if I have 10 worker threads
that each read/write to the db, I need to manually create 10
connections and pass them into each thread? What would the elegant way
to do this be?

Thanks,
- Dave

--~--~-~--~~~---~--~~
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] Dealing with undefined/NULL foreign keys

2007-04-09 Thread Brendan Arnold

Hi there,

I have a table of, say, people and another table of addresses. the
people table refers to addresses through a foreign key. It is optional
for each entry in the people table to have an address.

When I construct an object using
assign_mapper(session_context, Person, people_table, properties = {
'address' : relation(Address) })
and the foreign key in the people table is NULL (i.e. the address is
not specified) a None object is grafted onto the Person object instead
of an Address object. This causes all-sorts of errors later in the
code.

I remedied this by including an entry in the addresses table which
corresponds to an unspecified address, but this feels wrong somehow
(i.e. when listing addresses, need to parse out the 'unspecified'
entry etc.)

Is there a way I can ensure that an empty instance of my Address
object is grafted onto the Person object even when corresponding data
is not found in the people table?

Regards,

brendan Arnold

--~--~-~--~~~---~--~~
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: Putting Session.flush in a seperate thread

2007-04-09 Thread Michael Bayer


On Apr 9, 2007, at 5:18 AM, Koen Bok wrote:

>
> We are building a GUI app, and we were thinking about wrapping
> session.flush() in a thread with a timer that detects a timeout. That
> way we would have better performace and we can generate warnings if
> the connection goes down. Do you guys think this is smart, or are
> there complications?
>

we have logic for invalidating connections that have disconnected in  
the trunk, but it relies upon the DBAPI throwing exceptions.   
session.flush() is a very high level place to put connection timeout  
checking,  also what about selects/queries ?

> I tried to build this already but I cannot figure out how to assign
> the shared connection to a thread. I always get 'No connection
> defined'.

if youre on py2.4 check out threading.local().


--~--~-~--~~~---~--~~
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: Putting Session.flush in a seperate thread

2007-04-09 Thread Arun Kumar PG
may be a threadlocal strategy.

On 4/9/07, Koen Bok <[EMAIL PROTECTED]> wrote:
>
>
> We are building a GUI app, and we were thinking about wrapping
> session.flush() in a thread with a timer that detects a timeout. That
> way we would have better performace and we can generate warnings if
> the connection goes down. Do you guys think this is smart, or are
> there complications?
>
> I tried to build this already but I cannot figure out how to assign
> the shared connection to a thread. I always get 'No connection
> defined'.
>
>
> >
>

--~--~-~--~~~---~--~~
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: Ordering by field in related object

2007-04-09 Thread Norjee

Thanks a lot!! Grin the Django query object actually allows for this
sort of ordering so i just figured SqlAlchemy should allow it as
well :/ But never mind now I know the trick it's super easy to adjust
for it ;)



--~--~-~--~~~---~--~~
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] Putting Session.flush in a seperate thread

2007-04-09 Thread Koen Bok

We are building a GUI app, and we were thinking about wrapping
session.flush() in a thread with a timer that detects a timeout. That
way we would have better performace and we can generate warnings if
the connection goes down. Do you guys think this is smart, or are
there complications?

I tried to build this already but I cannot figure out how to assign
the shared connection to a thread. I always get 'No connection
defined'.


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