[sqlalchemy] How do I create a custom column type that exposes multiple attributes to the class

2012-03-12 Thread Paddy Mullen
I am trying to create a column that stores sha1sums of content, and
allows easy programatic access of that content.  I would like my table
definition to look like this

class Picture(Base):
   content = sa.Column('content_sha1sum', DataColumn(se))

I would like to be able to create instances of pictures like this

p = Picture()
p.content(binary_image_string)

I only want to save the sha1sum to the database, DataColumn takes care
of computing the sha1sum, and actually saving the content to s3 or the
filesystem.  I also want DataColumn to be a deferred column, I can do
that with deferred

All good so far.

What I can't do, or can't do cleanly is figure out how to access the
sha1sum behind content

p = s.query(Picture).all().first()

p.content_sha1sum
p.content_direct_url

Where direct_url is a function of the sha1sum.  The problem with a
custom column is, I can't make sha1sum loading eager and the call to
s3/filesystem lazy, this means that every re-hydration of a Picture
requires a read from the filesystem.

There are a couple of ways that I could go.  First would be to store
the sha1sum directly as a regular String column, and create properties
of names "content" and "content_direct_url".  Another method would be
to use a mixin, but that is a bit ugly.

What I really want is a way to add all 3 properties with a single
line.  I'm willing to modify DeclarativeMeta .

Any thoughts?

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/FH1NBMZj-mgJ.
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] Returning a simple list?

2012-03-12 Thread Michael Hipp
Doing a simple query like this, I just want to get a list of the pkeys in the 
table:


  q = select([mytable.c.id,])
  pkey_list = engine.execute(q).fetchall()

What I get back looks like:
   [(1,), (2,)]

But what I need is just:
   [1, 2]

It's easy enough to make that happen in Python, but was wondering if SQLA could 
return it directly?


Thanks,
Michael

--
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] How to return query results and their number at the same time

2012-03-12 Thread Eduard Ruchos
Hi,
I am trying to find a way to extract both the number of results and their
number. If I apply the operator all() first I can count all results
thereafter but this approach takes significant amount of time in the case
of large amount of results. I see that results are retrieved much faster if
offset and limit are provided too. Is there any way to get the results and
their number with one stroke.
Thanks
Eduardo

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



Re: [sqlalchemy] Inverting the like() operation

2012-03-12 Thread Matthew Pounsett
On Monday, 12 March 2012 01:35:10 UTC-4, Michael Bayer wrote:
>
> both the left and right sides of an expression are ultimately represented 
> as SQLAlchemy ColumnElements.   When you say "somecol == 'somestr'", the 
> 'somestr' part is coerced into a "literal" object as a result of it being 
> pulled into the "binary" expression (that is, an expression with a left, 
> right and an operator in the middle).   You can do this explicitly so that 
> you can call operators from either side:
>
> literal("foobar").like(foo.bar)
>
Thanks!  That looks like exactly what I need.  I don't see any reference to 
that method in the documentation pdf, and even searching for it 
specifically it's not very prominent in the google results, so I guess it's 
no wonder I didn't find it on my own.  Now that I know what I'm looking for 
it's easy to find in pydoc though.

I'll be able to give this a test tonight.

Thanks again!

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/gh4ytYd_cNMJ.
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.



Re: [sqlalchemy] Turning a Query instance into SQL (with parameters), need help w/ LIMIT/OFFSET in 0.7.x

2012-03-12 Thread Randy Syring

I added the new recipe to the wiki.

-
Randy Syring
Development&  Executive Director
Level 12 Technologies    (formerly Intelicom)
Direct: 502-276-0459
Office: 502-212-9913

Intelicom is now Level 12 Technologies,learn more about our name change  
.
Please update your address book with my new email address.

Principled People, Technology that Works


On 03/09/2012 09:24 PM, Michael Bayer wrote:
i haven't followed this closely, worth updating the recipe on the SQLA 
wiki ?




On Mar 9, 2012, at 2:06 PM, Randy Syring wrote:

I checked out that function and it turns out that I actually do have 
problems with:


q = db.sess.query(Blog).filter(Blog.title == u'foo').limit(10).offset(5)

results in:

SELECT blogs.id, blogs.createdts, blogs.updatedts, blogs.title, 
blogs.ident

FROM blogs
WHERE blogs.title = ?
 LIMIT ? OFFSET ?

However, I was mistaken in my original post.  The problem was not 
with the helper function but with the way I was doing my testing.  
The full implementation of the helper function is here:


http://stackoverflow.com/a/5698357/182111

-
Randy Syring
Development&  Executive Director
Level 12 Technologies    (formerly Intelicom)
Direct: 502-276-0459
Office: 502-212-9913

Intelicom is now Level 12 Technologies,learn more about our name change  
.
Please update your address book with my new email address.

Principled People, Technology that Works

On 03/09/2012 03:25 AM, Alex K wrote:

We use this recipe and in 0.7.5 it works ok with limit and offset.

http://www.sqlalchemy.org/trac/wiki/UsageRecipes/old/DebugInlineParams


On Fri, Mar 9, 2012 at 10:32 AM, Randy Syring > wrote:


I found a recipe on stackoverflow for turning a query instance
into a string, including parameters.  I only do this for testing
purposes and the implementation is here:


https://bitbucket.org/rsyring/sqlalchemybwc/src/292597b37736/sqlalchemybwc/lib/testing.py

However, I just upgraded to 0.7.5 and it would appear this
recipe does not handle LIMIT/OFFSET becoming parameterized.  I
get the following when using the function:

"...persons.last_name AS persons_last_name FROM persons LIMIT
:param_1 OFFSET :param_2"

I'm in over my head on SA internals on this one and would
appreciate suggestions.

Thanks in advance.
-- 
You received this message because you are subscribed to the

Google Groups "sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/ryYu6nVG-RQJ.
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.


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


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


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


--
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: Attribute modified but object not in session.dirty

2012-03-12 Thread Andrea
Problem solved!
Thanks a lot Michael,

Andrea

On 10 Mar, 03:23, Michael Bayer  wrote:
> this is in-place mutation so you need to send SQLAlchemy a signal that 
> something has changed using the Mutable interface, which involves subclassing 
> array.array.  See the docs 
> athttp://docs.sqlalchemy.org/en/latest/orm/extensions/mutable.htmlfor how 
> this works.
>
> On Mar 9, 2012, at 5:11 AM, Andrea wrote:
>
>
>
>
>
>
>
> > Hi all,
> > athttp://pastebin.com/jYsZwj10an extract of my code.
> > I create a custom type HexString that extends TypeDecorator. When I
> > modify an
> > object of this type on a persisted instance, changes don't affect
> > session.
> > I need some help, tnx.
>
> > Andrea
>
> > --
> > 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 
> > athttp://groups.google.com/group/sqlalchemy?hl=en.

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