[sqlalchemy] Re: *all* *new* *tutorials* !!!!

2007-08-07 Thread Alexandre CONRAD

This *IS* some piece of work ! Mike, you are the One ! :)

Regards,
-- 
Alexandre CONRAD


--~--~-~--~~~---~--~~
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: Reverse Foreign Key

2007-08-07 Thread Dave Marsh

Yes, that is what I am looking for.  Thanks

On Aug 6, 6:25 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Aug 6, 1:38 pm, Dave Marsh [EMAIL PROTECTED]
 wrote:



Currently, the solution is to query the database every time the
  page is reloaded so that the widget stays current.  I would like to
  convert to an event driven system (re-populate the widgets only when
  necessary) but have hit a snag.  In order to update the correct
  widgets, I would need to create a list of tables that rely on the
  table being added to/updated/deleted from.  I played around with the
  column objects but was unable to find a way to do what I needed.

 hi dave -

 its a little unclear to me what you're looking for exactly.  Is it
 that you'd like to determine, given a Table, what other Tables are
 dependent on it via foreign keys ?   An iterative approach through the
 MetaData object can be used to work up a dictionary of this
 information, if that's what you're looking for.

 - mike


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

2007-08-07 Thread Paul Colomiets

Michael Bayer wrote:
 i wonder though if theres some way that could get out of sync with  
 the actual number.  you'd have to be careful to establish this  
 update.  if you wanted to use a mapper extension to do it, then youd  
 have to issue the UPDATE directly, the change to the comment_count  
 attribute wont get picked up if its established within the flush itself.

Hi,

Thank you Michael for help, and for new great docs!

I've finally done first POC implementation of this feature.

Basic usage looks like:

import aggregator as a
mapper(Line, lines,
 extension=a.Quick(a.Count(blocks.c.lines),
a.Max(blocks.c.lastline, lines.c.id)))

(You also need foreign keys)

I've implemented two interfaces one
that counts like cnt = cnt+1 (called Quick)
second does query SELECT count(*) FROM 
at each insert/update/delete (called Accurate)

Well, Quick should be accurate as long as you either don't
update foreign keys involved in process, or have only one
Count aggregation on changable key (*), or use transactions.
So it covers most usecases I think. If you like to recalc you can
use Accurate which can be better in some edge cases.
A bit slower on updates but still fast on reads.

(*) - aggregations on update is not implemented yet, but it's
only a matter of time

For more comprehensive description look here:
http://www.mr-pc.kiev.ua/projects/SQLAlchemyAggregation

I have also two issues.

1. func.if_(...) - tries to sql function if_(...),
but func._if(...) - _i(...)
I believe is typo?

2.  If there a way, to handle functions in cross-database manner?

I've need to write something like this, for max function which
exists on sqlite but absent in mysql (and if() visa-versa):

if aggregator.mapper.local_table.\
metadata.bind.url.drivername == 'mysql':
return if_func(A  B, B, A)
else:
return func.max(A, B)

Is there a better way?
(Well, I will decrease number of dots it no better way exists :) )

--
Paul.


--~--~-~--~~~---~--~~
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: Microsoft Access Support

2007-08-07 Thread Michael Bayer

hi paul -

thanks much for this !  are we using pyodbc for this ?


On Aug 5, 7:20 pm, Paul Johnston [EMAIL PROTECTED] wrote:
 Hi,

 I have just committed Microsoft Access support in the 0.4 branch. It's
 pretty basic (e.g. a lot of unit tests fail) but it does have functional
 table reflection. For me, this is a big help in migrating legacy Access
 databases to newer formats.

 The table reflection is based on jet2sql.py by Matt Keranen, which has
 been a real help.

 I've included some info on Access support on the 
 wiki,http://www.sqlalchemy.org/trac/wiki/DatabaseNotes

 Enjoy,

 Paul


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

2007-08-07 Thread Michael Bayer



On Aug 7, 1:20 pm, Paul Colomiets [EMAIL PROTECTED] wrote:

 1. func.if_(...) - tries to sql function if_(...),
 but func._if(...) - _i(...)
 I believe is typo?

er, probably.  func is trying to sidestep various _ underscore
attributes i think.  do you need to say _if(...) ?

 2.  If there a way, to handle functions in cross-database manner?


this is ticket 615 which seems to be becoming very important, so i
think ill move it to 0.4xx milestone and increase priority.


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

2007-08-07 Thread sdobrev


 I've finally done first POC implementation of this feature.

 Basic usage looks like:

 import aggregator as a
 mapper(Line, lines,
  extension=a.Quick(a.Count(blocks.c.lines),
   a.Max(blocks.c.lastline, lines.c.id)))

 (You also need foreign keys)


hi, i have similar idea/need within dbcook, although on a somewhat 
higher level:
pre
cache_results/: (dbcook/SA) add-on for automaticaly-updated database 
denormalisation caches of intermediate results, each one depending on 
particular pattern of usage. Wishful syntax:

class SomeCacheKlas( Base):
fieldname = cache_aggregator( klas.field, AggrFilterCriteria)
#e.g.
#class Cache4averagePerson( Base):
#age= cache_agregators.Average( Person.age, Filter1 )
#salary = cache_agregators.Sum( Person.salary, Filter2 )
/pre
i was thinking on using triggers and/or sql-functions but then this is 
just one way to do it - and the idea is to hide the implementation.

Can your implementation be extended to use: 
 a) more complex aggregator expressions (e.g. average(), that is 
sum() / count(), and similar dependencies)
 b) more complex filters - e.g. not max() on all rows, but on some 
subset/select

think of generic report calculations/aggregations, and putting those 
into some cacheing table. 
Eventualy getting the report being built on-the-run - distributing the 
big wait over the atomary updates.


 http://www.mr-pc.kiev.ua/projects/SQLAlchemyAggregation
this gives me 404


--~--~-~--~~~---~--~~
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: Using SA to move data between databases

2007-08-07 Thread sdobrev

On Monday 06 August 2007 02:09:45 Paul Johnston wrote:
 Hi,

 I'm in the same process, and very interested in the answer !

 I've found what I think is the best solution, and it sounds quite
 obvious thinking about it. Define the table, do a select on the old
 database and an insert on the new database. This leverages all
 SQLAlchemy's cleverness in converting types, etc. and keeps the ORM
 out of the picture. The code I'm using is:

 model = __import__(sys.argv[1])
 if sys.argv[2] == 'copy':
 seng = create_engine(sys.argv[3])
 deng = create_engine(sys.argv[4])
 for tbl in model.metadata.table_iterator():
 deng.execute(tbl.insert(), [dict(x) for x in
 seng.execute(tbl.select())])

 All it relies on is that you call your MetaData metadata. At the
 moment, it chokes on names that contain a dash (or maybe it's ones
 that use key=), but I'm sure I can workaround that. When I'm done,
 I'll put this up as a recipe.

 Paul

heh, adding this raw-data-copy to the autoload.py
$ python autoload.py postgres://[EMAIL PROTECTED]/db1 | python - sqlite:///db2
which copyies the structure of input db1 database into the output db2.

makes quite a database-copier/migrator...

svil

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

2007-08-07 Thread Paul Colomiets

[EMAIL PROTECTED] wrote:=

   
 http://www.mr-pc.kiev.ua/projects/SQLAlchemyAggregation
 
 this gives me 404
   
Sorry:

http://www.mr-pc.kiev.ua/en/projects/SQLAlchemyAggregator




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

2007-08-07 Thread Paul Colomiets
Michael Bayer wrote:

 On Aug 7, 1:20 pm, Paul Colomiets [EMAIL PROTECTED] wrote:
   
 1. func.if_(...) - tries to sql function if_(...),
 but func._if(...) - _i(...)
 I believe is typo?
 

 er, probably.  func is trying to sidestep various _ underscore
 attributes i think.  do you need to say _if(...) ?

No I need to say IF but I can't say func.if() currently I use 
getattr('func','if') but It's ugly.

It strips last char when sees first underscore. But should ether strip 
first char, or check end of string for an underscore.

Patch attached :)

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

Index: lib/sqlalchemy/sql.py
===
--- lib/sqlalchemy/sql.py	(revision 3197)
+++ lib/sqlalchemy/sql.py	(working copy)
@@ -741,7 +741,7 @@
 except KeyError:
 raise AttributeError(name)
 
-elif name.startswith('_'):
+elif name.endswith('_'):
 name = name[0:-1]
 f = _FunctionGenerator(**self.opts)
 f.__names = list(self.__names) + [name]