sqlalchemy

Mysql connection pooling question: is it worth it?

I recall hearing that the connection process in mysql was designed to be very fast compared to other RDBMSes, and that therefore using a library that provides connection pooling (SQLAlchemy) won't actually help you that much if you enable the connection pool. Does anyone have any experience with this? I'm leery of enabling it because o...

SQLAlchemy DateTime timezone

SQLAlchemy's DateTime type allows for a timezone=True argument to save a non-naive datetime object to the datbase, and to return it as such. Is there any way to modify the timezone of the tzinfo that SQLAlchemy passes in so it could be, for instance, UTC? I realize that I could just use default=datetime.datetime.utcnow; however, this is ...

sqlalchemy, turning a list of IDs to a list of objects

I have sequence of IDs I want to retrieve. It's simple: session.query(Record).filter(Record.id.in_(seq)).all() Is there a better way to do it? ...

IronPython db-api 2.0

Does anyone know which if any db-api 2.0 drivers work with IronPython? If so, has anyone tried using it with SQLAlchemy, SQLObject or the Django ORM? ...

Filtering by relation count in SQLAlchemy

Hi all, I'm using the SQLAlchemy Python ORM in a Pylons project. I have a class "Project" which has a one to many relationship with another class "Entry". I want to do a query in SQLAlchemy that gives me all of the projects which have one or more entries associated with them. At the moment I'm doing: [project for project in Session.que...

How can I order objects according to some attribute of the child in sqlalchemy?

Here is the situation: I have a parent model say BlogPost. It has many Comments. What I want is the list of BlogPosts ordered by the creation date of its' Comments. I.e. the blog post which has the most newest comment should be on top of the list. Is this possible with SQLAlchemy? ...

Outputting data a row at a time from mysql using sqlalchemy

I want to fetch data from a mysql database using sqlalchemy and use the data in a different class.. Basically I fetch a row at a time, use the data, fetch another row, use the data and so on.. I am running into some problem doing this.. Basically, how do I output data a row at a time from mysql data?.. I have looked into all tutorials ...

SQLAlchemy and empty columns

When I try to insert a new record into the database using SQLAlchemy and I don't fill out all values, it tries to insert them as "None" (instead of omitting them). It then complains about "can't be null" errors. Is there a way to have it just omit columns from the sql query if I also omitted them when declaring the instance? ...

SQLAlchemy/Elixir validation rules?

I just found out how to validate my database input before saving it, but I'm kinda bummed to find there are no premade rules (like validate email, length, etc) that are found in some web based frameworks. Are there any validation libraries laying around anywhere or somewhere that some premade validation lists are hiding that I haven't fo...

py2exe + sqlalchemy + sqlite problem

I am playing around with getting some basic stuff to work in Python before i go into full speed dev mode. Here are the specifics: Python 2.5.4 PyQt4 4.4.3 SqlAlchemy 0.5.2 py2exe 0.6.9 setuptools 0.6c9 pysqlite 2.5.1 setup.py: from distutils.core import setup import py2exe setup(windows=[{"script" : "main.py"}], options={"py2exe" : ...

Any reasons not to use SQLObject over SQLAlchemy?

I don't expect to need much more than basic CRUD type functionality. I know that SQLAlchemy is more flexible, but the syntax etc of sqlobject just seem to be a bit easier to get up and going with. ...

SQLAlchemy Obtain Primary Key With Autoincrement Before Commit

When I have created a table with an auto-incrementing primary key, is there a way to obtain what the primary key would be (that is, do something like reserve the primary key) without actually committing? I would like to place two operations inside a transaction however one of the operations will depend on what primary key was assigned i...

Best practice for integrating CherryPy web-framework, SQLAlchemy sessions and lighttpd to serve a high-load webservice

I'm developing a CherryPy FastCGI server behind lighttpd with the following setup to enable using ORM SQLAlchemy sessions inside CherryPy controllers. However, when I run stress tests with 14 concurrent requests for about 500 loops, it starts to give errors like AttributeError: '_ThreadData' object has no attribute 'scoped_session_class'...

SELECT * in sqlalchemy?

Is it possible to do SELECT * in sqlalchemy? Edit: Specifically, SELECT * WHERE foo=1 ...

Can I get rows from SQLAlchemy that are plain arrays, rather than dictionaries?

I'm trying to optimize some Python code. The profiler tells me that SQLAlchemy's _get_col() is what's killing performance. The code looks something like this: lots_of_rows = get_lots_of_rows() for row in lots_of_rows: if row.x == row.y: print row.z I was about to go through the code and make it more like this... lots_of_r...

Django connection pooling and time fields

Has anyone got connection pooling working with Django, SQLAlchemy, and MySQL? I used this tutorial (http://node.to/wordpress/2008/09/30/another-database-connection-pool-solution-for-django-mysql/) which worked great but the issue I'm having is whenever I bring back a time field it is being converted to a timedelta since the Django-speci...

Doctest for dynamically created objects.

What is the best way to test code like this (the one below obviously fails while object is created in different block every time): def get_session(db_name, verbose, test): """Returns current DB session from SQLAlchemy pool. >>> get_session('Mmusc20090126', False, True) <sqlalchemy.orm.session.Session object at 0xfb5ff0> """ if test: ...

How to get number of affected rows in sqlalchemy?

Hi everybody, I have one question concerning Python and the sqlalchemy module. What is the equivalent for cursor.rowcount in the sqlalchemy Python? Thank you ...

SQLAlchemy - INSERT OR REPLACE equivalent

Hi, does anybody know what is the equivalent to SQL "INSERT OR REPLACE" clause in SQLAlchemy and its SQL expression language? Many thanks -- honzas ...

What am I missing about SqlAlchemy?

So I wanted to introduce a friend to the wonderful world of python ORM libraries, which I still know little about. Our databases are extremely fragmented and at times under normalized (for efficiency) and over normalized. Making "entities" out of it at this point is too much work (we have lots of legacy php code working with this) so th...