[sqlalchemy] Feedback appreciated (again :)

2014-03-15 Thread Konsta Vesterinen
Hi,

Lately I've been spending a lot of time improving some SQLAlchemy 
extensions. I'd appreciate any feedback for the new features I've made.

Some of the stuff I've been working on:

* Generic relationship support has been added for SQLAlchemy-Utils: 
http://sqlalchemy-utils.readthedocs.org/en/latest/generic_relationship.html. 
This is yet another implementation of polymorphic associations pattern 
(http://techspot.zzzeek.org/2007/05/29/polymorphic-associations-with-sqlalchemy/).
 
It would be very nice to see this kind of implementation in the core of 
SQLAlchemy some day. What is still needed for the generic_relationship is 
support for dependency processors and support for different loading 
strategies. 

* I added full support for PostgreSQL range data types for SA-Utils: 
http://sqlalchemy-utils.readthedocs.org/en/latest/range_data_types.html. To 
be able to handle these datatypes in pythonic way I also created a separate 
package for handling interval objects on the python 
side: https://github.com/kvesteri/intervals

* Some new database 
helpers: http://sqlalchemy-utils.readthedocs.org/en/latest/database_helpers.html

* http://sqlalchemy-searchable.readthedocs.org/en/latest/ - Humanized 
search string parsing for PostgreSQL full text search vectors

* Lots of new features and tweaks for 
SQLAlchemy-Continuum: http://sqlalchemy-continuum.readthedocs.org/en/latest/, 
one especially useful feature is the ActivityPlugin 
(http://sqlalchemy-continuum.readthedocs.org/en/latest/plugins.html#module-sqlalchemy_continuum.plugins.activity)
 
which uses the generic relationships of SA-Utils.

Also thanks Mike for all the hard work you've put into SA 0.9! I love all 
the new features in the 0.9 series. 

- Konsta

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Could someone please give an example of this paragraph in the Documentation -- Using the session?

2014-03-15 Thread Bao Niu
I've read this paragraph 
(http://docs.sqlalchemy.org/en/latest/orm/session.html#unitofwork-cascades) 
many many times and still can't think of a practical example of what is 
being discussed.

save-update cascade also cascades the *pending history* of the target 
 attribute, meaning that objects which were removed from a scalar or 
 collection attribute whose changes have not yet been flushed are also 
 placed into the target session. This is because they may have foreign key 
 attributes present which will need to be updated to no longer refer to the 
 parent.


I don't think my English is the main stumbling block here because I 
understand the meaning of each word, but as soon as I'm putting them 
together I'm completely lost. Could someone give a simple example here to 
illustrate the main point in this paragraph please? Highly appreciated. 
Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Could someone please give an example of this paragraph in the Documentation -- Using the session?

2014-03-15 Thread Michael Bayer
you have every reason to be confused by that paragraph, which is using way too 
much terminology to express what's important there.   at some point, we had to 
add a behavior which I thought would be confusing to people, so that paragraph 
tries badly to explain what it is.  I should replace it with just a simple 
sentence and an example.  Here's the example:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class A(Base):
__tablename__ = 'a'

id = Column(Integer, primary_key=True)
bs = relationship(B)

class B(Base):
__tablename__ = 'b'

id = Column(Integer, primary_key=True)
a_id = Column(Integer, ForeignKey('a.id'))

e = create_engine(sqlite://, echo=True)
Base.metadata.create_all(e)

sess = Session(e)
a1 = A()
b1 = B()

a1.bs = [b1]

sess.add(a1)
sess.commit()

a1.bs  # refresh a1.bs
sess.close()  # close out - sess is no longer associated with a1, b1

# all new session
sess2 = Session(e)

a1.bs.remove(b1)

sess2.add(a1)

# b1 was removed from a1.bs, but
# is in sess2 anyway! surprising!
assert b1 in sess2

# because we need it for the flush, it's still here:
from sqlalchemy import inspect
print inspect(a1).attrs.bs.history.deleted






On Mar 15, 2014, at 5:26 AM, Bao Niu niuba...@gmail.com wrote:

 I've read this paragraph 
 (http://docs.sqlalchemy.org/en/latest/orm/session.html#unitofwork-cascades) 
 many many times and still can't think of a practical example of what is being 
 discussed.
 
 save-update cascade also cascades the pending history of the target 
 attribute, meaning that objects which were removed from a scalar or 
 collection attribute whose changes have not yet been flushed are also placed 
 into the target session. This is because they may have foreign key attributes 
 present which will need to be updated to no longer refer to the parent.
 
 I don't think my English is the main stumbling block here because I 
 understand the meaning of each word, but as soon as I'm putting them together 
 I'm completely lost. Could someone give a simple example here to illustrate 
 the main point in this paragraph please? Highly appreciated. Thanks.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Could someone please give an example of this paragraph in the Documentation -- Using the session?

2014-03-15 Thread Gery .
I also appreciate such example! Hope simple terminology with a simple example 
can replace the sometimes complicated documentation.

Sent from my i386

On Mar 15, 2014, at 16:31, Michael Bayer mike...@zzzcomputing.com wrote:

you have every reason to be confused by that paragraph, which is using way too 
much terminology to express what’s important there.   at some point, we had to 
add a behavior which I thought would be confusing to people, so that paragraph 
tries badly to explain what it is.  I should replace it with just a simple 
sentence and an example.  Here’s the example:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class A(Base):
__tablename__ = 'a'

id = Column(Integer, primary_key=True)
bs = relationship(B)

class B(Base):
__tablename__ = 'b'

id = Column(Integer, primary_key=True)
a_id = Column(Integer, ForeignKey('a.id'))

e = create_engine(sqlite://, echo=True)
Base.metadata.create_all(e)

sess = Session(e)
a1 = A()
b1 = B()

a1.bs = [b1]

sess.add(a1)
sess.commit()

a1.bs  # refresh a1.bs
sess.close()  # close out - sess is no longer associated with a1, b1

# all new session
sess2 = Session(e)

a1.bs.remove(b1)

sess2.add(a1)

# b1 was removed from a1.bs, but
# is in sess2 anyway! surprising!
assert b1 in sess2

# because we need it for the flush, it's still here:
from sqlalchemy import inspect
print inspect(a1).attrs.bs.history.deleted






On Mar 15, 2014, at 5:26 AM, Bao Niu niuba...@gmail.com wrote:

 I've read this paragraph 
 (http://docs.sqlalchemy.org/en/latest/orm/session.html#unitofwork-cascades) 
 many many times and still can't think of a practical example of what is being 
 discussed.
 
 save-update cascade also cascades the pending history of the target 
 attribute, meaning that objects which were removed from a scalar or 
 collection attribute whose changes have not yet been flushed are also placed 
 into the target session. This is because they may have foreign key 
 attributes present which will need to be updated to no longer refer to the 
 parent.
 
 I don't think my English is the main stumbling block here because I 
 understand the meaning of each word, but as soon as I'm putting them together 
 I'm completely lost. Could someone give a simple example here to illustrate 
 the main point in this paragraph please? Highly appreciated. Thanks.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Could someone please give an example of this paragraph in the Documentation -- Using the session?

2014-03-15 Thread Michael Bayer
well thats my contribution for today, this is mostly rewritten: 
http://sqlalchemy.readthedocs.org/en/rel_0_9/orm/session.html#cascades


On Mar 15, 2014, at 12:07 PM, Gery . gameji...@hotmail.com wrote:

 I also appreciate such example! Hope simple terminology with a simple example 
 can replace the sometimes complicated documentation.
 
 Sent from my i386
 
 On Mar 15, 2014, at 16:31, Michael Bayer mike...@zzzcomputing.com wrote:
 
 you have every reason to be confused by that paragraph, which is using way 
 too much terminology to express what's important there.   at some point, we 
 had to add a behavior which I thought would be confusing to people, so that 
 paragraph tries badly to explain what it is.  I should replace it with just a 
 simple sentence and an example.  Here's the example:
 
 from sqlalchemy import *
 from sqlalchemy.orm import *
 from sqlalchemy.ext.declarative import declarative_base
 
 Base = declarative_base()
 
 class A(Base):
 __tablename__ = 'a'
 
 id = Column(Integer, primary_key=True)
 bs = relationship(B)
 
 class B(Base):
 __tablename__ = 'b'
 
 id = Column(Integer, primary_key=True)
 a_id = Column(Integer, ForeignKey('a.id'))
 
 e = create_engine(sqlite://, echo=True)
 Base.metadata.create_all(e)
 
 sess = Session(e)
 a1 = A()
 b1 = B()
 
 a1.bs = [b1]
 
 sess.add(a1)
 sess.commit()
 
 a1.bs  # refresh a1.bs
 sess.close()  # close out - sess is no longer associated with a1, b1
 
 # all new session
 sess2 = Session(e)
 
 a1.bs.remove(b1)
 
 sess2.add(a1)
 
 # b1 was removed from a1.bs, but
 # is in sess2 anyway! surprising!
 assert b1 in sess2
 
 # because we need it for the flush, it's still here:
 from sqlalchemy import inspect
 print inspect(a1).attrs.bs.history.deleted
 
 
 
 
 
 
 On Mar 15, 2014, at 5:26 AM, Bao Niu niuba...@gmail.com wrote:
 
 I've read this paragraph 
 (http://docs.sqlalchemy.org/en/latest/orm/session.html#unitofwork-cascades) 
 many many times and still can't think of a practical example of what is 
 being discussed.
 
 save-update cascade also cascades the pending history of the target 
 attribute, meaning that objects which were removed from a scalar or 
 collection attribute whose changes have not yet been flushed are also placed 
 into the target session. This is because they may have foreign key 
 attributes present which will need to be updated to no longer refer to the 
 parent.
 
 I don't think my English is the main stumbling block here because I 
 understand the meaning of each word, but as soon as I'm putting them 
 together I'm completely lost. Could someone give a simple example here to 
 illustrate the main point in this paragraph please? Highly appreciated. 
 Thanks.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Could someone please give an example of this paragraph in the Documentation -- Using the session?

2014-03-15 Thread Bao Niu
Thanks a lot Michael! Just a trivial question here, I noticed in your first
reply you used:
 # refresh a1.bs

Why do we need to refresh it? I tried it in my terminal and it doesn't emit
any sql. Is this one if those secret techniques that differentiate a
sqlalchemy ninja and a newbie?;)
On Mar 15, 2014 8:31 AM, Michael Bayer mike...@zzzcomputing.com wrote:

 you have every reason to be confused by that paragraph, which is using way
 too much terminology to express what's important there.   at some point, we
 had to add a behavior which I thought would be confusing to people, so that
 paragraph tries badly to explain what it is.  I should replace it with just
 a simple sentence and an example.  Here's the example:

 from sqlalchemy import *
 from sqlalchemy.orm import *
 from sqlalchemy.ext.declarative import declarative_base

 Base = declarative_base()

 class A(Base):
 __tablename__ = 'a'

 id = Column(Integer, primary_key=True)
 bs = relationship(B)

 class B(Base):
 __tablename__ = 'b'

 id = Column(Integer, primary_key=True)
 a_id = Column(Integer, ForeignKey('a.id'))

 e = create_engine(sqlite://, echo=True)
 Base.metadata.create_all(e)

 sess = Session(e)
 a1 = A()
 b1 = B()

 a1.bs = [b1]

 sess.add(a1)
 sess.commit()

 a1.bs  # refresh a1.bs
 sess.close()  # close out - sess is no longer associated with a1, b1

 # all new session
 sess2 = Session(e)

 a1.bs.remove(b1)

 sess2.add(a1)

 # b1 was removed from a1.bs, but
 # is in sess2 anyway! surprising!
 assert b1 in sess2

 # because we need it for the flush, it's still here:
 from sqlalchemy import inspect
 print inspect(a1).attrs.bs.history.deleted






 On Mar 15, 2014, at 5:26 AM, Bao Niu niuba...@gmail.com wrote:

 I've read this paragraph (
 http://docs.sqlalchemy.org/en/latest/orm/session.html#unitofwork-cascades)
 many many times and still can't think of a practical example of what is
 being discussed.

 save-update cascade also cascades the *pending history* of the target
 attribute, meaning that objects which were removed from a scalar or
 collection attribute whose changes have not yet been flushed are also
 placed into the target session. This is because they may have foreign key
 attributes present which will need to be updated to no longer refer to the
 parent.


 I don't think my English is the main stumbling block here because I
 understand the meaning of each word, but as soon as I'm putting them
 together I'm completely lost. Could someone give a simple example here to
 illustrate the main point in this paragraph please? Highly appreciated.
 Thanks.

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.


  --
 You received this message because you are subscribed to a topic in the
 Google Groups sqlalchemy group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/sqlalchemy/MSiBcFB3cFI/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] sql expression performance is bad ?

2014-03-15 Thread Ni Wesley
So, that's the point,  my tcp server is single process.

Because I have a global dict keep active socket connections, where key is 
cell device token, and value is the active socket associated with the 
device.

the dict cannot be finely shared between multiple processes..

So, I just pull out db operation and throw into a process pool which only 
handle db operation.

在 2014年3月16日星期日UTC+8上午4时14分50秒,Michael Bayer写道:


 On Mar 14, 2014, at 9:18 PM, Ni Wesley nis...@gmail.com javascript: 
 wrote: 

  Seems sqlalchemy engine pool uses thread, eh? 

 SQLAlchemy doesn’t spawn any threads, it only provides library functions 
 which do the thing you ask it to do, synchronously. 






-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.