Simon Laalo | 6 Aug 2011 01:24

Re: eagerly fetching joined objects

Thanks!  Sorry, my email filter moved this into a hidden folder.
I'll take a look :)  Here's hoping
-S

-----Original Message-----
From: Simon Cross [mailto:hodgestar <at> gmail.com] 
Sent: Thursday, July 21, 2011 1:32 AM
To: Simon Laalo
Cc: sqlobject-discuss <at> lists.sourceforge.net
Subject: Re: [SQLObject] eagerly fetching joined objects

Hi

On Thu, Jul 21, 2011 at 2:07 AM, Simon Laalo
<slaalo <at> resiliencesoftware.com> wrote:
> I'm currently trying to improve my DB performance by reducing the number of queries
> and associated overhead while grabbing some SQLObjects from the DB.  I would like
> to have SQLObject fully populate the object graph for the objects I'm using since all
> joined objects will be read every time this object is loaded.

I encountered a similar need in one of my own projects and wrote a
caching version of RelatedJoin that you could probably take ideas from
for a caching version of MultipleJoin / ForeignKey.  You can find the
code at http://sutekh.svn.sourceforge.net/viewvc/sutekh/trunk/sutekh/sutekh/core/CachedRelatedJoin.py?revision=2873&view=markup.

I considered contributing it back to SQLObject but it's a bit finicky
to use -- one has to manually initialize the cache (see init_cache
method) and then flush the cache (flush_cache) or just particular
items (invalidate_cache_item) from within one's application as needed.

Schiavo
(Continue reading)

Oleg Broytman | 8 Aug 2011 15:16
X-Face
Favicon
Gravatar

SQLObject 1.0.2

Hello!

I'm pleased to announce version 1.0.2, a bugfix release of branch 1.0
of SQLObject.

What is SQLObject
=================

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).

Where is SQLObject
==================

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

(Continue reading)

Oleg Broytman | 8 Aug 2011 15:17
X-Face
Favicon
Gravatar

SQLObject 1.1.2

Hello!

I'm pleased to announce version 1.1.2, a bugfix release of branch
1.1 of SQLObject.

What is SQLObject
=================

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).

Where is SQLObject
==================

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

(Continue reading)

Oleg Broytman | 9 Aug 2011 17:43
X-Face
Favicon
Gravatar

Vacation

Hi! I am taking a week off.

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
download at:  http://p.sf.net/sfu/wandisco-dev2dev
Daniel Fetchinson | 10 Aug 2011 18:38

Re: Vacation

Have fun Oleg!

Cheers,
Daniel

> Hi! I am taking a week off.
>
> Oleg.

--

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
download at:  http://p.sf.net/sfu/wandisco-dev2dev
Timo | 13 Aug 2011 15:43
Picon

Storing object from same table

Hello, sorry if I use the wrong terminology, I just started with SQLObject and databases in general.

This is my current class:
class Person(SQLObject):
    name = StringCol(notNone=True)
    father = StringCol(default='')
    mother = StringCol(default='')

This stores the names for the person's father and mother, but when I want to access their data, I need to fetch their names first and then lookup their objects from the database. What I actually want, is that father and mother are references to their own Person object. Is something like this possible? I read about SingleJoin/MultipleJoin, but it always references to another table.

Cheers,
Timo

------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy 
to use, easy to manage, easy to install, easy to extend. 
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Timo | 14 Aug 2011 10:28
Picon

Re: Storing object from same table

On 13-08-11 15:43, Timo wrote:
> Hello, sorry if I use the wrong terminology, I just started with 
> SQLObject and databases in general.
>
> This is my current class:
> class Person(SQLObject):
>     name = StringCol(notNone=True)
>     father = StringCol(default='')
>     mother = StringCol(default='')
Sorry about the fuzz, after some more searching and experimenting, I 
came up with the following which seems to work fine:

class Person(SQLObject):
     name = StringCol(notNone=True)
     father = ForeignKey('Person', default=None)
     mother = ForeignKey('Person', default=None)

p1 = Person(name='John')
print p1, p1.father, p1.mother
p2 = Person(name='Jane')
print p2, p2.father, p2.mother
p3 = Person(name='Jeff', father=p1, mother=p2)
print p3, p3.father, p3.mother

Cheers,
Timo

>
> This stores the names for the person's father and mother, but when I 
> want to access their data, I need to fetch their names first and then 
> lookup their objects from the database. What I actually want, is that 
> father and mother are references to their own Person object. Is 
> something like this possible? I read about SingleJoin/MultipleJoin, 
> but it always references to another table.
>
> Cheers,
> Timo

------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy 
to use, easy to manage, easy to install, easy to extend. 
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
Mark | 21 Aug 2011 01:15
Picon
Favicon

update and CONCAT

How would I do this in SQLObject? 

UPDATE
    Table
SET
    some_text = CONCAT(some_text, 'text')
WHERE
    id = 57

Is it just

table = Table.get(57)
table.some_text = table.some_text + "text"

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
Oleg Broytman | 21 Aug 2011 11:16
X-Face
Favicon
Gravatar

Re: UPDATE and CONCAT

On Sat, Aug 20, 2011 at 11:15:20PM +0000, Mark wrote:
> How would I do this in SQLObject? 
> 
> UPDATE
>     Table
> SET
>     some_text = CONCAT(some_text, 'text')
> WHERE
>     id = 57
> 
> Is it just
> 
> table = Table.get(57)
> table.some_text = table.some_text + "text"

   It depends on what you really want. Functionally, your SQL and python
code do the same thing but in different ways. SQL code works on the
server side and doesn't update the client side; python code performs
concatenation on the client side and sends an UPDATE like that:

UPDATE table SET some_text = new_text WHERE id = 57

   If you really want to call CONCAT or any other function do it in
SQLObject like this:

from sqlobject.sqlbuilder import Update, func
connection.query(
    Update(Table.sqlmeta.table,
        {'some_text': func.CONCAT(Table.q.some_text, 'text')},
        Test.q.id==57))

   You have to ask SQLObject to update the client side because
you updated the server side and you don't want python and SQL sides to
by desynchronized:

table.sync()

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
Mark | 25 Aug 2011 04:35
Picon
Favicon

Re: UPDATE and CONCAT

Oleg Broytman <phd <at> phdru.name> writes:

>    It depends on what you really want. Functionally, your SQL and python
> code do the same thing but in different ways. SQL code works on the
> server side and doesn't update the client side; python code performs
> concatenation on the client side and sends an UPDATE like that:

Great thanks, it makes perfect sense.

------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev

Gmane