[sqlalchemy] Re: SQLAlchemy Sphinx Documentation Preview

2008-12-04 Thread Gaetan de Menten

Here are the suggestions that come to mind:

- You should either get rid of, or (preferably) expand/replace the
current top-level table of contents. As it is currently, there is
only one useful link in there (API reference) and the table of
contents block waste way too much space for just one link. I liked the
old condensed table of contents which fit entirely on the screen
without scrolling.

- The vertical spacing between the li is slightly too large to my
taste, making for too much scrolling. I'd prefer a spacing roughly
equivalent to the old doc site. This issue might become mostly
irrelevant if the first one is fixed.

- Inside the Object Relational Tutorial section, the TOC is flat.
The hierarchical one was better IMO.

- The new API reference TOC is better IMO than the old one because it
doesn't include all the classes. I always took a few sec to find what
I wanted because there was too much information in there.
- On the other hand, I find the TOC *inside* API reference sections to
be lacking a reference to all public classes of the module, like there
was in the old system, for example at:
http://www.sqlalchemy.org/docs/05/sqlalchemy_schema.html

Btw: there is no TOC in api/sqlalchemy/Database schema.


On Wed, Dec 3, 2008 at 19:06, Michael Bayer [EMAIL PROTECTED] wrote:

 We've created a new branch and are in the process of migrating all of
 our documentation over to Sphinx.   The process has gone well and we
 have a working demo of the full system online.  By converting to
 Sphinx, we get the huge advantage of being on a standardized platform
 that everyone can understand and contribute towards.  All kinds of
 wacky old code, some of it four or more years old, has been removed
 (and we thank it for its service).   The docs are now split into Main
 Documentation and API Reference.  Because Sphinx allows very
 flexible layout of docstring-generated documentation, Main
 Documentation is shrinking and the docstrings used by API
 Reference, which is an all new section that replaces the old
 straight down modules display, are growing dramatically, which means
 more documentation is centralized across the site/pydocs and there's
 less redundancy.

 What we are now looking for with regards to the demo is:

- comments/suggestions regarding layout, styling.  Some layout
 changes were forced by Sphinx,  and others (most) are improvements
 that Sphinx allowed us to achieve.  I'm not a CSS guru or a designer
 so suggested patches to the CSS and templates would be welcome.   If
 Todd Grimason is out there, feel free to chime in :) .

- proofreaders.  The content on the demo is maybe 60% of the way
 there and we're combing through finding issues related to the Sphinx
 conversion, as well as things that have just been wrong all along.
 We would love to get patches against the doc build correcting as many
 issues as possible.

- authors.   No excuses now , we're on the most standard platform
 there is for docs.  If you have better verbiage for sections or
 docstrings which aren't clear, are nonexistent (like many of the
 dialects) or are out of date (theres lots), we want to see
 suggestions.  More elaborate suggestions regarding new sections and
 organization are welcome too as the structure is completely open ended.

- people who understand LaTex to work on the PDF side of things.
 This one's totally over my head as far as how to get a pdf file out of
 this thing (pdflatex is fairly inscrutable on a mac).

 Sphinx 0.6 is required, which at the time of this writing is not yet
 released so you'll have to check out Sphinx from its mercurial
 repository if you want to do builds.

 View the content online at: http://www.sqlalchemy.org/docs/sphinxtest/
 Checkout the SVN branch and do a build:  
 http://svn.sqlalchemy.org/sqlalchemy/branches/sphinx


-- 
Gaëtan de Menten
http://openhex.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] Re: relation join problem

2008-12-04 Thread Dom

Thanks, that works.

But now, with the attribute_mapped_collection, every language is
queried and assigned to the dict (quite an overhead in my use-case).

how could i achieve to load only a selected language which is
dynamically assigned on the query?

i thought of something like a column_property which reads a param or
option passed to the query. is this possible?
or is another approach better?

Dom


On Dec 3, 7:13 pm, Simon [EMAIL PROTECTED] wrote:
 That would be

 desc = session.query(I18Product).filter_by(id=1183, lang=en).one()

 The Problem with your query is that you query() for Product, not for
 I18NProduct, so regardless of and filter and join functions you
 specify, you will always receice Product objects. Think of query
 (Product) as a final filter which creates Product objects from the
 returned rows, and ignores everything which is not a column of
 Product.

 For x.i18n (a property of Product) to work as you described, have a
 look 
 athttp://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_relatio...
 . You'd basically want to setup your relation() as a dict using the
 lang column as key.

 Simon

 On 3 Dez., 16:33, Dom [EMAIL PROTECTED] wrote:

  Hi

  i tried the following example, but i cant get the join to work:

  CREATE TABLE product (

     id                INTEGER,
     price           NUMERIC(15,2) NOT NULL,

     PRIMARY KEY(id)
  );

  CREATE TABLE i18n_product (
     id                       INTEGER,
     lang                   VARCHAR(2),
     description        VARCHAR(150) NOT NULL,

     PRIMARY KEY(id, lang),
     FOREIGN KEY(id) REFERENCES product(id)
  );

  python:

  class Product(Base):
      __table__ = Table('product', Base.metadata, autoload=True)

  class I18NProduct(Base):
      __table__ = Table('i18n_product', Base.metadata, autoload=True)
      product = relation(Product, backref=backref('i18n'))

  x=session.query(Product).filter(Product.id==1183).join('i18n').filter
  (I18NProduct.lang=='en').one()

  the sql looks of the JOIN looks good, but if i access x.i18n, another
  queries is build which returns all of my language entry for one
  product, what i try to get is one product description in the given
  language.

  please tell me how to do that correctly, thank you :)

  cheers
  Dom


--~--~-~--~~~---~--~~
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: Abstract base class

2008-12-04 Thread Guillaume



On Dec 3, 7:39 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Dec 3, 2008, at 1:26 PM, Guillaume wrote:



  Hello,

  is there a way with the ORM layer to have abstract base class like in
  django ?
  http://docs.djangoproject.com/en/dev/topics/db/models/#abstract-base-
  classes

 sure, just pass along cls=MyBaseClass along to declarative_base().
 You can also make your own metaclass if you wanted, and pass it in as
 metaclass=MyMetaClass, or you can use the individual components within
 declarative_base explicitly if you wanted to roll it yourself.   This
 is all in the docstrings for declarative.

So:
class A(object): pass
Base = declarative_base(cls=A)
class B(Base):
  __tablename__ = 'b'
  id = Column(Integer, primary_key=True)
b = B()
if isinstance(b, A):
  print 'Success !'

completes successfully, great !

  Another somehow related question is there any plan for declarative
  base to support inheritance ala django ?

 declarative supports all three of SQLA's table inheritance forms
 fully.It pretty much happens automatically when you make a
 subclass, and you just need to pass along polymorphic_on/
 polymorphic_identity into __mapper_args__.   If Django supported some
 kind of inheritance scenario that we don't I'd be very interested to
 see that :) .

The problem is not directly in the inheritance scenario, but rather
creating an association to an abstract class.

Let's say I have the following classes: CorporateCustomer and
PrivateCustomer inheriting from the abstract class Customer. On the
database side, I have the two following table: corporate_customer(id,
customer_info, corporate_info) and private_customer(id, customer_info,
private_info) (ids are generated by a unique sequence for all the
database). Now I have also Order objects associated to Customer
objects; the table looks like order(id, customer_id, order_info). Can
I map this scenario directly in SQLA without creating some dummy view
customer in the database ?

(Just checked how I did it with Django: with a set of ugly wrapper
method and views.)

Regards,
  Guillaume

--~--~-~--~~~---~--~~
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] QueuePool Problem

2008-12-04 Thread Jürgen Hauptmann

Hello

I am running an application with cherrypy, sqlalchemy and mysql. All is
working fine but sometimes after inserting many data i get the following
messages.

I am using an scoped_session and remove the session if i don't need it. I
only see 3 databases processe in the mysql database.

br
Jürgen Hauptmann

  
  
   500 Internal Server Error
  
   The server encountered an unexpected condition which prevented
 it
  from
   fulfilling the request.
  
   Traceback (most recent call last):
 File
 /usr/lib/python2.4/site-packages/cherrypy/_cprequest.py,
  line
   551, in respond
   cherrypy.response.body = self.handler()
 File
 /usr/lib/python2.4/site-packages/cherrypy/_cpdispatch.py,
  line
   24, in __call__
   return self.callable(*self.args, **self.kwargs)
 File server.py, line 60, in view
   fall = session.query(Fall).filter_by(id=id).one()
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/orm/query.py,
   line 924, in one
   ret = list(self[0:2])
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/orm/query.py,
   line 938, in __iter__
   return self._execute_and_instances(context)
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/orm/query.py,
   line 941, in _execute_and_instances
   result = self.session.execute(querycontext.statement,
   params=self._params, mapper=self.mapper,
   instance=self._refresh_instance)
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/orm/session.py,
   line 628, in execute
   return self.__connection(engine,
   close_with_result=True).execute(clause, params or {})
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/orm/session.py,
   line 600, in __connection
   return self.transaction.get_or_add(engine)
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/orm/session.py,
   line 217, in get_or_add
   conn = bind.contextual_connect()
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/engine/base.py,
   line 1239, in contextual_connect
   return Connection(self, self.pool.connect(),
   close_with_result=close_with_result, **kwargs)
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/pool.py,
   line 170, in connect
   agent = _ConnectionFairy(self)
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/pool.py,
   line 323, in __init__
   rec = self._connection_record = pool.get()
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/pool.py,
   line 180, in get
   return self.do_get()
 File
  
 
 /usr/lib/python2.4/site-packages/SQLAlchemy-0.4.7p1-py2.4.egg/sqlal
  chemy/pool.py,
   line 604, in do_get
   raise exceptions.TimeoutError(QueuePool limit of size %d
  overflow %d
   reached, connection timed out, timeout %d % (self.size(),
   self.overflow(), self._timeout))
   TimeoutError: QueuePool limit of size 30 overflow 10 reached,
  connection
   timed out, timeout 30
  



--~--~-~--~~~---~--~~
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: SQLAlchemy Sphinx Documentation Preview

2008-12-04 Thread Michael Bayer


On Dec 4, 2008, at 4:21 AM, Gaetan de Menten wrote:


 Here are the suggestions that come to mind:

 - You should either get rid of, or (preferably) expand/replace the
 current top-level table of contents. As it is currently, there is
 only one useful link in there (API reference) and the table of
 contents block waste way too much space for just one link.

I agree - unfortunately this so far seems to be a limitation of  
Sphinx.   I like the table of contents on individual documentation  
pages where its meaningful, and since every page uses the same  
template, you have no choice but to display the ${toc} variable, which  
is provided by Sphinx as a string with the full ulli structure  
inside of it.  If you take a look at the sidebar on docs.python.org,  
you'll see its the exact same thing.I can perhaps make the display  
of ${toc} conditional based on the name of the page (i.e. index).   I  
really wish Sphinx would provide the ${toc} as a Python structure  
which can be manipulated.

 I liked the
 old condensed table of contents which fit entirely on the screen
 without scrolling.

yeah we don't have a lot of options for that and the index page is  
where I've been the most frustrated.



 - The vertical spacing between the li is slightly too large to my
 taste, making for too much scrolling. I'd prefer a spacing roughly
 equivalent to the old doc site. This issue might become mostly
 irrelevant if the first one is fixed.

I was trying to get the li to be exactly the same and was not  
successful.  I'm not that good at CSS to figure it out (though we're  
trying not to use any pixel sizes...maybe we need to just do that).

 - Inside the Object Relational Tutorial section, the TOC is flat.
 The hierarchical one was better IMO.

thats a bug, i need to fix the headings in the tutorial

--~--~-~--~~~---~--~~
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: Abstract base class

2008-12-04 Thread Michael Bayer


On Dec 4, 2008, at 7:44 AM, Guillaume wrote:


 The problem is not directly in the inheritance scenario, but rather
 creating an association to an abstract class.

 Let's say I have the following classes: CorporateCustomer and
 PrivateCustomer inheriting from the abstract class Customer. On the
 database side, I have the two following table: corporate_customer(id,
 customer_info, corporate_info) and private_customer(id, customer_info,
 private_info) (ids are generated by a unique sequence for all the
 database). Now I have also Order objects associated to Customer
 objects; the table looks like order(id, customer_id, order_info). Can
 I map this scenario directly in SQLA without creating some dummy view
 customer in the database ?

sure this is called concrete table inheritance.   Though when you  
make a relation to Order, you need to declare these separately for  
CorporateCustomer and PrivateCustomer since the connection from a  
relational perspective is different.   When concrete inheritance uses  
an abc, it maps to a union of the subtables so that you can load  
polymorphically.  To do that with declarative you'd also have to  
create the Table objects separately and pull them in to each class  
using __table__.

So with those limitations, if it were me I wouldn't use the concrete  
inheritance feature unless i needed to load Customer objects  
generically, I'd instead use Customer as a mixin class stated after  
the declarative base class.


--~--~-~--~~~---~--~~
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: QueuePool Problem

2008-12-04 Thread Michael Bayer


On Dec 4, 2008, at 4:29 AM, Jürgen Hauptmann wrote:


 Hello

 I am running an application with cherrypy, sqlalchemy and mysql. All  
 is
 working fine but sometimes after inserting many data i get the  
 following
 messages.

 I am using an scoped_session and remove the session if i don't need  
 it. I
 only see 3 databases processe in the mysql database.

I've never seen that behavior before - if the pool claims to have  
checked out 40 connections, then 40 connections have been checked  
out.  If there's only 3 that are active, that would imply that 37 of  
those connections have been closed but are still checked out.

You would possibly get this behavior if you used the pool like this:

# get a connection
connection = pool.connect()

 # use the connection

 # bypass the pooling mechanism, close the DBAPI connection
 connection.connection.close()

where above, connection.close() has not been called so the connection  
is still checked out.  the underlying DBAPI connection has in fact  
been closed.


--~--~-~--~~~---~--~~
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: SQLAlchemy Sphinx Documentation Preview

2008-12-04 Thread Michael Bayer

I've made all of these changes up on the site.   The li issue was a  
pixel-based padding already so I just reduced that.

On Dec 4, 2008, at 9:25 AM, Michael Bayer wrote:



 On Dec 4, 2008, at 4:21 AM, Gaetan de Menten wrote:


 Here are the suggestions that come to mind:

 - You should either get rid of, or (preferably) expand/replace the
 current top-level table of contents. As it is currently, there is
 only one useful link in there (API reference) and the table of
 contents block waste way too much space for just one link.

 I agree - unfortunately this so far seems to be a limitation of
 Sphinx.   I like the table of contents on individual documentation
 pages where its meaningful, and since every page uses the same
 template, you have no choice but to display the ${toc} variable, which
 is provided by Sphinx as a string with the full ulli structure
 inside of it.  If you take a look at the sidebar on docs.python.org,
 you'll see its the exact same thing.I can perhaps make the display
 of ${toc} conditional based on the name of the page (i.e. index).   I
 really wish Sphinx would provide the ${toc} as a Python structure
 which can be manipulated.

 I liked the
 old condensed table of contents which fit entirely on the screen
 without scrolling.

 yeah we don't have a lot of options for that and the index page is
 where I've been the most frustrated.



 - The vertical spacing between the li is slightly too large to my
 taste, making for too much scrolling. I'd prefer a spacing roughly
 equivalent to the old doc site. This issue might become mostly
 irrelevant if the first one is fixed.

 I was trying to get the li to be exactly the same and was not
 successful.  I'm not that good at CSS to figure it out (though we're
 trying not to use any pixel sizes...maybe we need to just do that).

 - Inside the Object Relational Tutorial section, the TOC is flat.
 The hierarchical one was better IMO.

 thats a bug, i need to fix the headings in the tutorial

 


--~--~-~--~~~---~--~~
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: Abstract base class

2008-12-04 Thread Guillaume


 sure this is called concrete table inheritance.   Though when you  
 make a relation to Order, you need to declare these separately for  
 CorporateCustomer and PrivateCustomer since the connection from a  
 relational perspective is different.   When concrete inheritance uses  
 an abc, it maps to a union of the subtables so that you can load  
 polymorphically.  To do that with declarative you'd also have to  
 create the Table objects separately and pull them in to each class  
 using __table__.

 So with those limitations, if it were me I wouldn't use the concrete  
 inheritance feature unless i needed to load Customer objects  
 generically, I'd instead use Customer as a mixin class stated after  
 the declarative base class.

Which prety much means no generic query for Customer objects ...

I'll go down the concrete inheritance path and create a couple of
views for handling my abstract classes.
--~--~-~--~~~---~--~~
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: Abstract base class

2008-12-04 Thread Michael Bayer


On Dec 4, 2008, at 11:18 AM, Guillaume wrote:



 sure this is called concrete table inheritance.   Though when you
 make a relation to Order, you need to declare these separately for
 CorporateCustomer and PrivateCustomer since the connection from a
 relational perspective is different.   When concrete inheritance uses
 an abc, it maps to a union of the subtables so that you can load
 polymorphically.  To do that with declarative you'd also have to
 create the Table objects separately and pull them in to each class
 using __table__.

 So with those limitations, if it were me I wouldn't use the concrete
 inheritance feature unless i needed to load Customer objects
 generically, I'd instead use Customer as a mixin class stated after
 the declarative base class.

 Which prety much means no generic query for Customer objects ...

 I'll go down the concrete inheritance path and create a couple of
 views for handling my abstract classes.

getting different concrete tables to connect to a common related  
table, with the configuration on the base class is definitely possible  
and its even clear where the code to do this would occur (right at the  
TODO in _adapt_inherited_property)...its just some complexity that I  
have balked on for now.


--~--~-~--~~~---~--~~
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] Can I write this query with SQLAlchemy?

2008-12-04 Thread Matt Wilson

Right now, I'm writing this query as a string.  I want to know if it
can be expressed with SQLAlchemy's expressions instead.

Here's the query:

select sh.employee_id, sum(st.stop_time - st.start_time) as hours
from shift sh, shift_time st
where sh.employee_id in (28630, 28648)
and sh.shift_time_id = st.id
and st.start_time between timestamp '2008-11-02 00:00:00' and
timestamp '2008-11-09 00:00:00'
group by sh.employee_id
order by hours desc;

Any ideas?

--~--~-~--~~~---~--~~
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: Can I write this query with SQLAlchemy?

2008-12-04 Thread Michael Bayer

hi matt -

here's that query generated using lexical tables, which are just like  
Table objects but require less boilerplace for SQL prototyping purposes:

from sqlalchemy import *
from sqlalchemy.sql import table, column
import datetime

shift = table('shift', column('employee_id', Integer),  
column('shift_time_id', Integer))
shift_time = table('shift_time', column('id', Integer),  
column('start_time', DateTime), column('stop_time', DateTime))

s = select([shift.c.employee_id, func.sum(shift_time.c.stop_time -  
shift_time.c.start_time).label('hours')]).\
 where(shift.c.employee_id.in_([28630, 28648])).\
 where(shift.c.shift_time_id==shift_time.c.id).\
 where(shift_time.c.start_time.between(
 datetime.datetime(2008, 11, 2, 0, 0, 0),
 datetime.datetime(2008, 11, 9, 0, 0, 0)
 )).\
 group_by(shift.c.employee_id).\
 order_by(desc(hours))

print s
print s.compile().params



On Dec 4, 2008, at 11:23 AM, Matt Wilson wrote:


 Right now, I'm writing this query as a string.  I want to know if it
 can be expressed with SQLAlchemy's expressions instead.

 Here's the query:

 select sh.employee_id, sum(st.stop_time - st.start_time) as hours
 from shift sh, shift_time st
 where sh.employee_id in (28630, 28648)
 and sh.shift_time_id = st.id
 and st.start_time between timestamp '2008-11-02 00:00:00' and
 timestamp '2008-11-09 00:00:00'
 group by sh.employee_id
 order by hours desc;

 Any ideas?

 


--~--~-~--~~~---~--~~
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: Can I write this query with SQLAlchemy?

2008-12-04 Thread Matt Wilson

Thanks!  This is really helpful.

On Dec 4, 11:43 am, Michael Bayer [EMAIL PROTECTED] wrote:
 hi matt -

 here's that query generated using lexical tables, which are just like  
 Table objects but require less boilerplace for SQL prototyping purposes:

 from sqlalchemy import *
 from sqlalchemy.sql import table, column
 import datetime

 shift = table('shift', column('employee_id', Integer),  
 column('shift_time_id', Integer))
 shift_time = table('shift_time', column('id', Integer),  
 column('start_time', DateTime), column('stop_time', DateTime))

 s = select([shift.c.employee_id, func.sum(shift_time.c.stop_time -  
 shift_time.c.start_time).label('hours')]).\
      where(shift.c.employee_id.in_([28630, 28648])).\
      where(shift.c.shift_time_id==shift_time.c.id).\
      where(shift_time.c.start_time.between(
          datetime.datetime(2008, 11, 2, 0, 0, 0),
          datetime.datetime(2008, 11, 9, 0, 0, 0)
      )).\
      group_by(shift.c.employee_id).\
      order_by(desc(hours))

 print s
 print s.compile().params

 On Dec 4, 2008, at 11:23 AM, Matt Wilson wrote:



  Right now, I'm writing this query as a string.  I want to know if it
  can be expressed with SQLAlchemy's expressions instead.

  Here's the query:

  select sh.employee_id, sum(st.stop_time - st.start_time) as hours
  from shift sh, shift_time st
  where sh.employee_id in (28630, 28648)
  and sh.shift_time_id = st.id
  and st.start_time between timestamp '2008-11-02 00:00:00' and
  timestamp '2008-11-09 00:00:00'
  group by sh.employee_id
  order by hours desc;

  Any ideas?
--~--~-~--~~~---~--~~
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] returning primary key of object without know what it is called.

2008-12-04 Thread Faheem Mitha


Hi,

I'm trying to figure out how to have an object return its primary key 
without knowing what it is called. The docs in 
http://www.sqlalchemy.org/docs/05/sqlalchemy_orm_mapper.html look 
relevant, for example the function identity_key_from_instance (see entry 
from docs below), but I'm not clear about usage. The functions on this 
page look like they are meant to be used as method functions of a mapper 
object, but how should I construct such a mapper object? In my schema 
file, I have lines like

Mapper(Foo, foo_table)

should I be returning an mapper object for use with functions? Ie should I 
be doing

foo_mapper = Mapper(Foo, foo_table)

or similar? The section module sqlalchemy.orm.mapper saya

This is a semi-private module; the main configurational API of the ORM is 
available in module sqlalchemy.orm.

Does this mean it is not meant to be used in this fashion?

Also, I don't understand what is meant by

This value is typically also found on the instance state under the
attribute name key.

in the docs for identity_key_from_instance below.

Please CC me on any reply.
   Thanks and regards, Faheem.




def identity_key_from_instance(self, instance)

Return the identity key for the given instance, based on its primary key 
attributes.

This value is typically also found on the instance state under the 
attribute name key.

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