[sqlalchemy] Adding MapperExtensions after Mappers created

2009-03-18 Thread jarrod.ches...@gmail.com

How do i add a MapperExtension to a mapper after the mapper has been
created with the mapper() function
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SELECT statement inside in_

2009-03-18 Thread Glauco

Sanjay ha scritto:
 I got that the obvious way is just writing the string query, i.e.

 query.filter(col IN SELECT col FROM some_table)

   
something like this:

query.filter( col.in_( select([col],...).correlate(None) ))



Glauco




--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Adding MapperExtensions after Mappers created

2009-03-18 Thread Michael Bayer


theres a collection calledextension i believe, which has an append()
method (also unsure of that name).



jarrod.ches...@gmail.com wrote:

 How do i add a MapperExtension to a mapper after the mapper has been
 created with the mapper() function
 



--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SELECT statement inside in_

2009-03-18 Thread Michael Bayer

Sanjay wrote:

 Hi,

 I want to write something like

 query.filter(BizObj.col.in_(SELECT col FROM some_table)).

 Could not find out how to do it. The code on neither the above nor the
 below worked.

 query.filter(BizObj.col1.in_(sqlalchemy.sql.text(SELECT col1 FROM
 sometable))).


in_() is going to want a select() construct for that calling style.  if
you don't have a Table or mapped class for sometable, you can make an
ad-hoc table using table():

from sqlalchemy.sql import table, column

BizObj.col1.in_(select([table(sometable, column(col1)).c.col1]))



 Needing help.

 thanks,
 Sanjay
 



--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SELECT statement inside in_

2009-03-18 Thread Mike Conley
On Wed, Mar 18, 2009 at 11:00 AM, Michael Bayer mike...@zzzcomputing.comwrote:


 Sanjay wrote:
 
  Hi,
 
  I want to write something like
 
  query.filter(BizObj.col.in_(SELECT col FROM some_table)).
 
  Could not find out how to do it. The code on neither the above nor the
  below worked.
 
  query.filter(BizObj.col1.in_(sqlalchemy.sql.text(SELECT col1 FROM
  sometable))).


 in_() is going to want a select() construct for that calling style.  if
 you don't have a Table or mapped class for sometable, you can make an
 ad-hoc table using table():

 from sqlalchemy.sql import table, column

 BizObj.col1.in_(select([table(sometable, column(col1)).c.col1]))


and if I do have a mapped class, say SomeClass, is there an ORM-like syntax
to use  the class or do I drop into SQL-like syntax using
SomeClass.__table__ ?

query = session.query(BizObj).filter(BizObj.col1.in_(??))

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SELECT statement inside in_

2009-03-18 Thread Michael Bayer


col.in_(select([MyClass.col2]))

Mike Conley wrote:
 On Wed, Mar 18, 2009 at 11:00 AM, Michael Bayer
 mike...@zzzcomputing.comwrote:


 Sanjay wrote:
 
  Hi,
 
  I want to write something like
 
  query.filter(BizObj.col.in_(SELECT col FROM some_table)).
 
  Could not find out how to do it. The code on neither the above nor the
  below worked.
 
  query.filter(BizObj.col1.in_(sqlalchemy.sql.text(SELECT col1 FROM
  sometable))).


 in_() is going to want a select() construct for that calling style.  if
 you don't have a Table or mapped class for sometable, you can make an
 ad-hoc table using table():

 from sqlalchemy.sql import table, column

 BizObj.col1.in_(select([table(sometable, column(col1)).c.col1]))


 and if I do have a mapped class, say SomeClass, is there an ORM-like
 syntax
 to use  the class or do I drop into SQL-like syntax using
 SomeClass.__table__ ?

 query = session.query(BizObj).filter(BizObj.col1.in_(??))

 



--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] adding some sql function to several dialects

2009-03-18 Thread che

Hi,

i need to add several functions to all dialects that i'll plan to use
in order to be fully database-independent.
Does anybody have tips how to achieve this?
For example i want to add function year( date) to sqlite and postgres
dialects.

TIA,
Stefan
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: adding some sql function to several dialects

2009-03-18 Thread Michael Bayer


we'll be adding a feature for this soon.  here is a non-public way to do
it for now which will work throughout 0.5:

from sqlalchemy.sql.expression import ClauseElement

class year(ClauseElement):
__visit_name__ = 'year'
def __init__(self, value):
self.value = value

def _compiler_dispatch(self, compiler):
if compiler.dialect.name == 'postgres':
return pg_year(%s) % self.value
else:
return sqlite_year(%s) % self.value
year._compiler_dispatch = _compiler_dispatch


che wrote:

 Hi,

 i need to add several functions to all dialects that i'll plan to use
 in order to be fully database-independent.
 Does anybody have tips how to achieve this?
 For example i want to add function year( date) to sqlite and postgres
 dialects.

 TIA,
 Stefan
 



--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] interval tree table

2009-03-18 Thread bard stéphane

is there an easy way to represent an interval tree table in sqlAlchemy
Interval Tree is very common way to represent tree.
with right, left, level indices, node, leaf (left - right = 1) ?

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: interval tree table

2009-03-18 Thread az

On Wednesday 18 March 2009 22:31:37 bard stéphane wrote:
 is there an easy way to represent an interval tree table in
 sqlAlchemy Interval Tree is very common way to represent tree.
 with right, left, level indices, node, leaf (left - right = 1) ?

FIY see this thread with various tree rerpesentations (my or may not 
be there):
Adjacency List tree - inefficient reading
From: Kless jonas@googlemail.com
To: sqlalchemy 
Date: 2009-01-18 20:33

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: interval tree table

2009-03-18 Thread Michael Bayer

bard stéphane wrote:

 is there an easy way to represent an interval tree table in sqlAlchemy
 Interval Tree is very common way to represent tree.
 with right, left, level indices, node, leaf (left - right = 1) ?

there's no restriction using the SQL expression language.   The ORM can do
it too, see the example examples/nested_sets/nested_sets.py in the tar.gz
distribution for a recipe.



--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Any one tried to use SqlAlchemy with XML RPC?

2009-03-18 Thread 一首诗

This is my ORM class definition:

#=
class User(Base):
__tablename__ = 'b_taa_user'

user_id = Column(Integer, primary_key=True, autoincrement=True,
nullable=False) # 用户ID
user_name = Column(Unicode(255), unique=True, nullable=False,
server_default=) # 用户名称
user_password = Column(Unicode(255), nullable=False,
server_default=) # 用户密码
email = Column(Unicode(255), nullable=False, server_default=) # 邮
箱
mobile = Column(Unicode(255), nullable=False, server_default=) #
手机
phone = Column(Unicode(255), nullable=False, server_default=) # 电
话

def __init__(self, user_name = ):
self.user_name = username
#=

I made some debug by the code below:

#=

#!/usr/bin/python

import xmlrpclib
from blf.model import User

u = User('333')
s = xmlrpclib.dumps((u,), methodresponse=True, allow_none=True)
print s
#=

Finally, I found that the first problem is :  xmlrpclib only serialize
type *instance*.
But to my surprise, when I check type of u, it's a *class* object.
Don't know why ...




On Mar 18, 6:50 pm, Noah Gift noah.g...@gmail.com wrote:
 On Wed, Mar 18, 2009 at 11:46 PM, 一首诗 newpt...@gmail.com wrote:

  Hi,

  I am trying to pass SqlAlchemy objects to client with XML RPC, but it
  seems that that's not very easy.

 It depends on what you are trying to do, and what error messages you are
 getting, for anyone to help.  I am using XML RPC with SQLAlchemy right now,
 and I am, in fact, passing objects in.  I wrote a metaclass that calls back
 to XML RPC, and takes the ugly nested dictionary and returns back a nifty
 class pre-populated with attributes I need to fill out.  When I set each
 attribute, it then populates __dict__.  At that point, I simply pass that
 back to XML RPC.  Works great.



  The reason why I have to do this is that my client is written in
  javascript and running on a web page.  So it could not use anything
  other than text based protocols, such as XML RPC, SOAP, or JSON.

  I tried pyamf, and it works pretty good with SA,  but I can't use amf
  with javascript.

  Is there any possible solutions with my problem?

 --
 Cheers,

 Noah
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Any one tried to use SqlAlchemy with XML RPC?

2009-03-18 Thread Andreas Jung
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 19.03.2009 5:24 Uhr, 一首诗 wrote:
 This is my ORM class definition:
 
 #=
 class User(Base):
 __tablename__ = 'b_taa_user'
 
 user_id = Column(Integer, primary_key=True, autoincrement=True,
 nullable=False) # 用户ID
 user_name = Column(Unicode(255), unique=True, nullable=False,
 server_default=) # 用户名称
 user_password = Column(Unicode(255), nullable=False,
 server_default=) # 用户密码
 email = Column(Unicode(255), nullable=False, server_default=) # 邮
 箱
 mobile = Column(Unicode(255), nullable=False, server_default=) #
 手机
 phone = Column(Unicode(255), nullable=False, server_default=) # 电
 话
 
 def __init__(self, user_name = ):
 self.user_name = username
 #=
 
 I made some debug by the code below:
 
 #=
 
 #!/usr/bin/python
 
 import xmlrpclib
 from blf.model import User
 
 u = User('333')
 s = xmlrpclib.dumps((u,), methodresponse=True, allow_none=True)
 print s
 #=
 
 Finally, I found that the first problem is :  xmlrpclib only serialize
 type *instance*.
 But to my surprise, when I check type of u, it's a *class* object.
 Don't know why ...
 
 

Sending mapped instances over XMLRPC is basically nonsense. XMLRPC is
designed for transporting elementary datatypes over the wire in order to
invoke a remote method. It is not designed for sending instances of some
class and not for sending Python pickles. No idea what you are trying to
accomplish. Consider converting a mapped instance to dict and sending
this dict serialized in JSON format to a remote XMLRPC server.

- -aj
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAknB17UACgkQCJIWIbr9KYwARgCeJ1VuU6Gi9p+GVkYQzZiVWMd3
aJoAoMwJUc8lIyOBhDwJVq3/L3QzuRoK
=aihX
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd.  Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:i...@zopyx.com
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard



[sqlalchemy] Re: Any one tried to use SqlAlchemy with XML RPC?

2009-03-18 Thread Andreas Jung
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 19.03.2009 6:49 Uhr, Arthur Pemberton wrote:

 
 SQLAlchemy needs a concept of Data Transfer Objects so that it can be
 easily transmitted and reconstituted as necessary and everyone doesn't
 have to reimplemented the idea themselves. There are many cases where
 one might want to transfer a model from a data source on a server side
 to a client, and vice verse.

Which usecases? If you want to transfer objects over the wire from one
app to another, you can also attach the database directly. You you work
with serialized
versions of the objects in some way...should be sufficient enough for most
cases.

- -aj

- -- 
ZOPYX Ltd.  Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany
Web: www.zopyx.com - Email: i...@zopyx.com - Phone +49 - 7071 - 793376
Registergericht: Amtsgericht Stuttgart, Handelsregister A 381535
Gesch
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAknB3j4ACgkQCJIWIbr9KYysHQCfTuXFRZDIF4IBsL6UGA7ZYbEO
CPIAoOFK4wA3mAmfuoR6byTWh9ngUpGc
=U7aQ
-END PGP SIGNATURE-

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd.  Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:i...@zopyx.com
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard