[sqlalchemy] orm query - join on inner query

2009-03-27 Thread jarrod.ches...@gmail.com

How can i implement the following query with sqlalchemy.orm objects?

SELECT columns.*
FROM columns AS col
JOIN
(
SELECT object_id, revision
FROM columns
GROUP BY id, revision
HAVING revision = 20
) AS lr ON col.object_id = lr.object_id AND col.revision =
lr.revision;


Non syntactically correct example :

from sqlalchemy import schema, types, orm, create_engine

# Setup everything

engine = create_engine('sqlite://:memory:')

metadata = schema.Metadata(bind=engine)

ColumnsTable = schema.Table('columns'
, schema.Column('id', types.Integer, primary_key=True)
, schema.Column('object_id', types.Integer)
, schema.Column('name', types.String)
, schema.Column('revision', types.Integer)
, metadata)

class ColumnOrm (object):
pass

metadata.create_all()

orm.mapper(ColumnOrm, ColumnsTable)

session = orm.create_session(bind=engine, autocommit=True)

# Now for the query
# lr means latest revision

SELECT columns.*
FROM columns AS col
JOIN
(
SELECT object_id, revision
FROM columns
GROUP BY id, revision
HAVING revision = 20
) AS lr ON col.object_id = lr.object_id AND col.revision =
lr.revision;
--~--~-~--~~~---~--~~
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] Adding MapperExtensions after Mappers created

2009-03-18 Thread jarrod.ches...@gmail.com

How do i add a MapperExtension to a mapper after the mapper has been
created with the mapper() function
--~--~-~--~~~---~--~~
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] Mapped Orm Object Notifier

2009-03-16 Thread jarrod.ches...@gmail.com

Hi
I've been reading through the documentation and i can't see an
existing feature for this.

The table i'm working with stores properties about part of my program.
I get a record from the session.queryone() function and i pass
that around.
The record is somewhere in a properties change dialog box and
somewhere else as a label.

Is there currently a way of having the class sets the label to
register a listener with the orm record so that when the record is
updated, It notifies the listener which updates the label?

Regards, Jar.


PS, I was thinking tonight that sqlAchemy would make an awesome
content for a university subject.
--~--~-~--~~~---~--~~
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: Mapped Orm Object Notifier

2009-03-16 Thread jarrod.ches...@gmail.com

class OrmRecord(object):

def _get_column_value(self, name):
# return self.__dict__[name]
return getattr(self, name)

def _set_column_value(self, name, value):
val = setattr(self, name, value)
self._notify_change_functions()

# Return result just because
return val

def add_change_function(self, instance, function):
 Add Change Function

Add a function to this record that will be modified
when this record is changed
This function will be called and passed the record it
wants to be notified about

instance
The instance of the object to be called back

function
The function to be called and passed the instance




try:
self._change_functions
except AttributeError:
self._change_functions = weakref.WeakKeyDictionary
()

self._change_functions[instance] = function

def _notify_change_functions(self):
try:
self._change_functions
except AttributeError:
return

for instance in self._change_functions:
self._change_functions[instance](self)



self._OrmRecord = OrmRecord

print 'Mapped ' + self.schema_table_name + '\n\t' + str
(self._OrmRecord) + '\n\t' + str(metadata.tables
[self.schema_table_name])
self._mapper = mapper(self._OrmRecord, self._metadata_table)



This is the code i put together
I set the value of the orm_record using the setter and getter
functions above.

Anyone know of a more sqlalchemy way of doing it?
--~--~-~--~~~---~--~~
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] SQLAlchemy Migrate

2009-03-05 Thread jarrod.ches...@gmail.com

Hi All

I'm writing a metadata based schema migration tool.

As SQLAlchemy doesn't support much schema modification. I will
implement a complete set of schema migration functions one way or
another for several of the SQLAlchemy supported databases.

My question is, Where should these function reside? Options are :
1) Branch SQLAlchemy and make the modifications
2) Branch SQLAlchemy Migrate and make the modifications
3) Write the code and not distribute it cause no one cares.
4) ? Suggestions ?



PS, Thanks Michael Bayer, SQLAlchemy is great.
--~--~-~--~~~---~--~~
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: SQLAlchemy Migrate

2009-03-05 Thread jarrod.ches...@gmail.com

Yes, Option 2 - However, From the example documentation, Its doesn't
implement everything.
Although its most of the way there - So option 2 is looking good to
me.

On Mar 6, 1:23 am, Lawrence Oluyede l.oluy...@gmail.com wrote:
 On Thu, Mar 5, 2009 at 10:03 AM, jarrod.ches...@gmail.com

 jarrod.ches...@gmail.com wrote:

  I'm writing a metadata based schema migration tool.

 Keep in mind there are some other projects like
 http://code.google.com/p/sqlalchemy-migrate/

 HTH

 --
 Lawrence Oluyede
 [eng]http://oluyede.org-http://twitter.com/lawrenceoluyede
 [ita]http://neropercaso.it-http://twitter.com/rhymes
--~--~-~--~~~---~--~~
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] Create tables with metadata

2008-12-11 Thread jarrod.ches...@gmail.com

Hi
I've scoured the documentation and i can't find any info on how to
create a column using metadata.

from sqlalchemy import engine
from sqlalchemy import schema
from sqlalchemy import types

_config_dbengine = engine.create_engine('sqlite:tmp/db')
_config_metadata = schema.MetaData(_config_dbengine, reflect=True)
table = _config_metadata.tables['table_name']
table.append_column(schema.Column('id', types.Integer,
primary_key=True, autoincrement=True))

This is the steps i'm using but the column doesn't get created.

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: Create tables with metadata

2008-12-11 Thread jarrod.ches...@gmail.com

Doesn't get created in the database.
How do i add columns to tables already defined in the database after i
have reflected them into the metadata



On Dec 12, 12:59 am, Empty mtr...@gmail.com wrote:
 Hi,

 On Thu, Dec 11, 2008 at 8:12 AM, jarrod.ches...@gmail.com 



 jarrod.ches...@gmail.com wrote:

  Hi
  I've scoured the documentation and i can't find any info on how to
  create a column using metadata.

  from sqlalchemy import engine
  from sqlalchemy import schema
  from sqlalchemy import types

  _config_dbengine = engine.create_engine('sqlite:tmp/db')
  _config_metadata = schema.MetaData(_config_dbengine, reflect=True)
  table = _config_metadata.tables['table_name']
  table.append_column(schema.Column('id', types.Integer,
  primary_key=True, autoincrement=True))

  This is the steps i'm using but the column doesn't get created.

 Doesn't get created where?  In the database?  That's not going to happen.
  Are you saying it's not included as part of the table definition?

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