sqlalchemy

Do any Python ORMs (SQLAlchemy?) work with Google App Engine?

I'd like to use the Python version of App Engine but rather than write my code specifically for the Google Data Store, I'd like to create my models with a generic Python ORM that could be attached to Big Table, or, if I prefer, a regular database at some later time. Is there any Python ORM such as SQLAlchemy that would allow this? ...

Multiple Mappers for the same class in different databases

I am currently working on a Wikipedia API which means that we have a database for each language we want to use. The structure of each database is identical, they only differ in their language. The only place where this information is stored is in the name of the database. When starting with one language the straight forward approach to ...

sqlalchemy flush() and get inserted id?

I want to do something like this: f = Foo(bar='x') session.add(f) session.flush() # do additional queries using f.id before commit() print f.id # should be not None session.commit() But f.id is None when I try it. How can I get this to work? -Dan ...

Is this a good approach to avoid using SQLAlchemy/SQLObject?

Rather than use an ORM, I am considering the following approach in Python and MySQL with no ORM (SQLObject/SQLAlchemy). I would like to get some feedback on whether this seems likely to have any negative long-term consequences since in the short-term view it seems fine from what I can tell. Rather than translate a row from the database ...

What order does SQLAlchemy use for primary key columns?

Let's say I create a table like this: table = Table('mytable', metadata, Column('a', Integer, primary_key=True), Column('b', Integer, primary_key=True), ) table.create() Is it guaranteed that the primary key will be (a,b) and not (b,a)? ...

How do I efficiently do a bulk insert-or-update with SQLAlchemy?

I'm using SQLAlchemy with a Postgres backend to do a bulk insert-or-update. To try to improve performance, I'm attempting to commit only once every thousand rows or so: trans = engine.begin() for i, rec in enumerate(records): if i % 1000 == 0: trans.commit() trans = engine.begin() try: inserter.execute(...)...

How can I mass-assign SA ORM object attributes?

Hello there, I have an ORM mapped object, that I want to update. I have all attributes validated and secured in a dictionary (keyword arguments). Now I would like to update all object attributes as in the dictionary. for k,v in kw.items(): setattr(myobject, k, v) doesnt work (AttributeError Exception), thrown from SQLAlchemy. my...

SQLAlchemy Inheritance

I'm a bit confused about inheritance under sqlalchemy, to the point where I'm not even sure what type of inheritance (single table, joined table, concrete) I should be using here. I've got a base class with some information that's shared amongst the subclasses, and some data that are completely separate. Sometimes, I'll want data from al...

nose tests of Pylons app with models in init_model?

I have a stock Pylons app created using paster create -t pylons with one controller and matched functional test, added using paster controller, and a SQLAlchemy table and mapped ORM class. The SQLAlchemy stuff is defined in the init_model() function rather than in module scope (and needs to be there). Running python setup.py test raises...

SQLAlchemy session query with INSERT IGNORE

Hi, I'm trying to do a bulk insert/update with SQLAlchemy. Here's a snippet: for od in clist: where = and_(Offer.network_id==od['network_id'], Offer.external_id==od['external_id']) o = session.query(Offer).filter(where).first() if not o: o = Offer() o.network_id = od['network_id'] o.externa...

sqlalchemy create a foreign key?

I have a composite PK in table Strings (integer id, varchar(2) lang) I want to create a FK to ONLY the id half of the PK from other tables. This means I'd have potentially many rows in Strings table (translations) matching the FK. I just need to store the id, and have referential integrity maintained by the DB. Is this possible? If so,...

Issues with scoped_session in sqlalchemy - how does it work?

I'm not really sure how scoped_session works, other than it seems to be a wrapper that hides several real sessions, keeping them separate for different requests. Does it do this with thread locals? Anyway the trouble is as follows: S = elixir.session # = scoped_session(...) f = Foo(bar=1) S.add(f) # ERROR, f is already attached to sess...

TurboGears2/SQLAlchemy: Inserting a new row into a table with an autoincrement Primary Key

I am a noob and am trying to get my head around TG2 and SQLAlchemy. The specific problem I am wrestling with at the moment is how to insert a new row into a table when the PK field is configured as autoincrement. For example: in my myproject.model.myproject.py file I defined the following table: class Dj(DeclarativeBase): __table...

SQLAlchemy Connections, pooling, and SQLite

so, my design calls for a separate SQLite file for each "project".. I am reading through the SQLAlchemy Pooling docs more carefully.. my guess right now is that I dont want to fool with pooling at all, but this is really a separate connection engine for each project.. Agree?? In that case, when I create the engine, either I connect to a...

group by year, month, day in a sqlalchemy

I want "DBSession.query(Article).group_by(Article.created.month).all()" But this query can't using How do I do this using SQLAlchemy? ...

How to insert a row with autoincrement id in a multi-primary-key table?

I am writing a turbogears2 application. I have a table like this: class Order(DeclarativeBase): __tablename__ = 'order' # id of order id = Column(Integer, autoincrement=True, primary_key=True) # buyer's id buyer_id = Column(Integer, ForeignKey('user.user_id', onupdate="CASCADE", ondelete="CASCADE"), primary...

Python dicts in sqlalchemy

I would like to load/save a dict to/from my sqlite DB, but am having some problems figuring out a simple way to do it. I don't really need to be able to filter, etc., based on the contents so a simple conversion to/from string is fine. The next-best thing would be foreign keys. Please don't post links to huge examples, my head would exp...

sqlalchemy easy way to insert or update?

I have a sequence of new objects. They all look like similar to this: Foo(pk_col1=x, pk_col2=y, val='bar') Some of those are Foo that exist (i.e. only val differs from the row in the db) and should generate update queries. The others should generate inserts. I can think of a few ways of doing this, the best being: pk_cols = Foo.table...

How to get sqlalchemy storing datetime as julianday in sqlite?

I don't like how SQLAlchemy treats datetime values with sqlite databases. It stores the values in plain string format. At the same time sqlite recommends using julianday for storing datetime values. Is there an easy way to change the SQLAlchemy's behaviour here? PS. Shall I worry about it? May be noone is dealing with julianday just be...

Shall I bother with storing DateTime data as julianday in SQLite?

SQLite docs specifies that the preferred format for storing datetime values in the DB is to use Julian Day (using built-in functions). However, all frameworks I saw in python (pysqlite, SQLAlchemy) store the datetime.datetime values as ISO formatted strings. Why are they doing so? I'm usually trying to adapt the frameworks to storing d...