[sqlalchemy] non-sql storage

2006-10-19 Thread Monty Taylor

So this may sound like a crazy question...

If I wanted to implement an interface to a non-SQL based backend (or I
wanted to use a direct API to the db bypassing the SQL layer) is there
an appropriate place to plug such a thing in and if so where? For it
to make sense, I would want to such code in a place that it could take
advantage of the meta-information defined for a class, bypass the sql
generation step, but still expose the right interface to calling code.

Any thoughts?

Monty

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



[sqlalchemy] Re: Mapping with eagerload from arbitrary ResultSet?

2006-10-19 Thread Michael Bayer

since i was working on this anyway, i added a feature that will make  
this possible, although i want to improve upon it.

what you can do right now is:

class User(object):pass
class Address(object):pass

mapper(User, user_table, properties={
 'addresses':relation(Address, lazy=False)
})

mapper(Address, address_table)

selectquery = users.outerjoin(addresses).select(use_labels=True)
q = create_session().query(User)
result = q.options(contains_eager('addresses')).instances 
(selectquery.execute())

I think from this I can see a way to make it so that by default you  
wouldnt need the contains_eager() option, and it would work the way  
you expect (i.e., no aliasing by default).  but this is something you  
can try for now in the trunk.

On Oct 18, 2006, at 9:54 PM, James Taylor wrote:


 I expected to be able to map both sides of the relationship from a
 resultset with the proper columns. However it appears to still lazy
 load all the child objects. Short example (works against trunk):

 import pkg_resources
 pkg_resources.require( sqlalchemy )
 pkg_resources.require( pysqlite )

 from sqlalchemy import *

 # Setup classes, tables, mappers

 metadata = BoundMetaData( 'sqlite:tmp/test.db' )
 metadata.engine.echo = True

 class A( object ):
  pass

 class B( object ):
  pass

 A.table = Table( table_a, metadata,
  Column( id, Integer, primary_key=True),
  Column( name, String(20) ) )

 B.table = Table( table_b, metadata,
  Column( id, Integer, primary_key=True),
  Column( name, String(20) ),
  Column( table_a_id, Integer, ForeignKey( table_a.id ) ) )

 mapper( B, B.table )
 mapper( A, A.table, properties=dict( bs=relation( B, backref=a ) ) )

 metadata.create_all()

 # Insert some stuff

 session = create_session()

 for i in range( 10 ):
  a = A()
  a.name = A_%d % i
  session.save( a )
  for j in range( 10 ):
  b = B()
  b.name= B_%d % i
  b.a = a
  session.save( b )
 session.flush()
 session.clear()

 # Map from select

 results = select( [ A.table, B.table ], A.c.id == B.c.table_a_id,
 use_labels=True ).execute()
 some_as = class_mapper( A ).instances( results, session, with_options=
 [eagerload('bs')] )

 # At this point many queries against 'b_table'

 for a in some_as:
  list( a.bs )

 


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



[sqlalchemy] Re: Bind Parameters, MySQL and Full text search.

2006-10-19 Thread Lee McFadden

Ah, such a simple little thing.  Thanks, that works great now. :)

Lee

On 10/18/06, Michael Bayer [EMAIL PROTECTED] wrote:

 id say drop the quotes around the bind parameter.  bind parameters dont
 require any quotes as the value is sent as a separate field in the
 database conversation.


 



-- 
Lee McFadden

blog: http://www.splee.co.uk
work: http://fireflisystems.com

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



[sqlalchemy] Re: session.flush() closing connection

2006-10-19 Thread François Wautier

Thanks for the patch... it works... so far

And sorry for the double post... my original email was held for a very long 
time on some google host

Cheers,
François


 thats a bug.  its because the flush() is closing the connection you
 passed to your session.

 heres a patch that fixes it, which i will try to commit later today but
 i want to work up some test cases:

 Index: lib/sqlalchemy/orm/session.py
 ===
 --- lib/sqlalchemy/orm/session.py   (revision 1852)
 +++ lib/sqlalchemy/orm/session.py   (working copy)
 @@ -37,7 +37,7 @@
  e = connectable.engine
  c = connectable.contextual_connect()
  if not self.connections.has_key(e):
 -self.connections[e] = (c, c.begin())
 +self.connections[e] = (c, c.begin(), c is not connectable)
  return self.connections[e][0]
  def commit(self):
  if self.parent is not None:
 @@ -58,7 +58,8 @@
  if self.parent is not None:
  return
  for t in self.connections.values():
 -t[0].close()
 +if (t[2]):
 +t[0].close()
  self.session.transaction = None

  class Session(object):




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



[sqlalchemy] How to use SQL length in sqlalchemy

2006-10-19 Thread Kevin anew

I want use sql like this:
select * from mytb order by length(mytxt) ASC

how to use it by sqlalchemy


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



[sqlalchemy] Re: PassiveDefaults and PostgreSQL 8.2's INSERT RETURNING syntax

2006-10-19 Thread Karsten Hilbert

On Thu, Oct 19, 2006 at 12:10:34PM -0400, Michael Bayer wrote:

 the whole thing falls under the category of optimization so its not  
 urgently needed, but its something we should put in the queue.   
 pretty weird to have an Insert return a result set ..
If I am not mistaken it's straight from the SQL standard, so there.

Karsten
-- 
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

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



[sqlalchemy] Anticipated changes in 0.3?

2006-10-19 Thread Robin Munn

It may be a little early to be asking this. But I'm going to be
teaching SQLAlchemy to about fifteen to twenty people in precisely
three weeks, and I'm preparing my lesson plan now. And I'm starting to
wonder whether my lesson plan (currently based on 0.2.8) will need
drastic tweaking, or minor tweaking, or no changes at all, when you
release 0.3. There were enough changes between 0.1 and 0.2 that a few
sections of my step-by-step tutorial needed a rewrite -- such as the
new create_engine() syntax, and passing a metadata object instead of
an engine object to the Table() constructor. (Incidentally, for anyone
who's interested, that tutorial is at
http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html). Do you know
yet what changes you're planning to make in 0.3? At least, well enough
to give me a hint or two like I'm planning to completely overhaul the
ActiveMapper plugin or something like that?

-- 
Robin Munn
[EMAIL PROTECTED]
GPG key 0xD6497014

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