[sqlalchemy] How do I patch SQLAlchemy declarative model dynamically with Columns of different type?

2012-05-12 Thread gostones
I am running mysql in production but would like to run a simple tests
in a sqlite in memory db.

The legacy mysql db has tables with columns that are mysql specific
types, Which are declared in declarative models (subclassing
declarative_base). I would like to run some simple tests without going
to mysql and so would need to swap out the columns of the model.

How do I do this? I've tried writing a patcher/unpatcher to swap out
table in my model, but when I run some tests, I get

OperationalError: (OperationalError) near ): syntax error u'\nCREATE
TABLE my_table (\n)\n\n' ()

Which makes my think that I am not patching the columns properly.

Does anyone know how I can do this? What am I doing wrong?

Currently, I create new columns and attach brand new Table object to
__table__ and save the old table.

The DB is created, create_all() is and convert_columns is run in
setUp. drop_all() and revert_columns is run during tearDown in my
tests

mysql_sqlite_mapping = {INTEGER: Integer,
MEDIUMINT: Integer,
TEXT: text}

def convert_columns(self, my_class, mapping):
for column in my_class.__table__.columns:
if type(column.type) in mapping:
replacement_col = Column(column.name,
 mapping[type(column.type)],
 primary_key=column.primary_key,
 nullable=column.nullable,
 key=column.key,
 unique=column.unique)

converted_columns.append(replacement_col)

self.registry[my_class] = my_class.__table__

my_class.__table__.metadata.remove(my_class.__table__)
my_class.__table__ = Table(my_class.__table__.name,
   my_class.__table__.metadata)

for column in converted_columns:
my_class.__table__.append_column(column)

return my_class

def revert_columns(self, my_class):
saved_table = self.registry[my_class]

metadata = my_class.__table__.metadata
my_class.__table__.metadata.remove(my_class.__table__)

model_class.__table__ = Table(saved_table.name,
  metadata)

for column in saved_table.columns:
column.table = None
my_class.__table__.append_column(column)

self.registry.pop(my_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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Web-framework+db with the widest scalability?

2012-05-12 Thread Alec Taylor


Disclosure: I have posted this on 
stackoverflowhttp://stackoverflow.com/q/10562165and 
comp.lang.pythonhttps://groups.google.com/forum/#%21topic/comp.lang.python/gSAw5mLkUos
.

I am building a project requiring high performance and scalability, 
entailing:

   - Role-based 
authenticationhttp://en.wikipedia.org/wiki/Role-based_access_controlwith 
   
API-keyhttp://en.wikipedia.org/wiki/Application_programming_interface_keylicensing
 to access data of specific users
   - API 
http://en.wikipedia.org/wiki/Application_programming_interfaceexposed with 
   REST http://en.wikipedia.org/wiki/REST 
(XMLhttp://en.wikipedia.org/wiki/XML, 
   JSON http://en.wikipedia.org/wiki/JSON), 
XMLRPChttp://en.wikipedia.org/wiki/XMLRPC, 
   JSONRPC http://en.wikipedia.org/wiki/JSONRPC and 
SOAPhttp://en.wikipedia.org/wiki/SOAP
   - Easily configurable getters and 
settershttp://en.wikipedia.org/wiki/Mutator_methodto create APIs accessing 
the same data but with input/output in different 
   schemas http://en.wikipedia.org/wiki/Database_schema

A conservative estimate of the number of tables—often whose queries require 
joins—is: 20.

Which database type—e.g.: NoSQL http://en.wikipedia.org/wiki/NoSQL or 
DBMShttp://en.wikipedia.org/wiki/Database_management_system
—key-value data store http://en.wikipedia.org/wiki/Key-value_data_storeor 
object-relational 
database http://en.wikipedia.org/wiki/Object-relational_database—e.g.: 
Redis http://en.wikipedia.org/wiki/Redis or 
PostgreSQLhttp://en.wikipedia.org/wiki/PostgreSQL—and 
web-framework http://en.wikipedia.org/wiki/Web_application_framework—e.g. 
Django http://en.wikipedia.org/wiki/Django_%28web_framework%29, 
Web2Pyhttp://www.web2py.com/or 
Flask http://flask.pocoo.org/—would you recommend?
Thanks for all suggestions

-- 
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/-/TjDMJf8CmCUJ.
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] Getting comparison TypeError when trying to commit aware datetime when previous value was naive datetime

2012-05-12 Thread Steve Zatz
When I try to commit a timezone aware datetime to replace a value that was
previously timezone naive, I get a TypeError when I try to do the commit
with the message:

TypeError: can't compare offset-naive and offset-aware datetimes

Now I am not trying to compare anything but just store the new value in an
sqlite database.  Is there a way to force the commit to take place without
it performing a comparison to the previously stored value (if that is in
fact what is going on)?

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