sqlalchemy

Having some trouble creating my Model in Pylons

I've been reading the Pylons Book and, having got to the part about Models, realise it's out of date. So I then switched over to the official Pylons documentation for creating Models in Pylons 1.0 - http://pylonshq.com/docs/en/1.0/tutorials/quickwiki_tutorial/ I've followed what they've got and it's still failing. ./blog/model/init.py ...

SQLAlchemy introspection of declarative classes

I'm writing a small sqlalchemy shim to export data from a MySQL database with some lightweight data transformations—mostly changing field names. My current script works fine but requires me to essentially describe my model twice—once in the class declaration and once as a list of field names to iterate over. I'm trying to figure out ...

Where to put my sqlalchemy code in my script?

I had my sqlalchemy related code in my main() method in my script. But then when I created a function, I wasn't able to reference my 'products' mapper because it was in the main() method. Should I be putting the sqlalchemy related code (session, mapper, and classes) in global scope so all functions in my single file script can refer to...

Do I reference the session when making any db calls in sqlalchemy?

In this tutorial it says (http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html) to select all rows of an entity like: s = products.select() rs = s.execute() I get an error saying: This select object is not bound and does not support direct execution ... Do I need to reference the session object? I just want to get all rows in my ...

In Sqlalchemy, if i add an object using session.add() and flush it, session.query() does not give that object, why?

While using SQLAlchemy, i add a object to a session using session.add(objname), then either explicitly flush it using session.flush or enable autoflush=True while creating the engine itself. Now in the session, if want to return that object via session.query(classname).all(), i cannot retrieve it. Why is that so? or is there a way in w...

To select only some columns from some tables using session object

Hello, I have these classe where items (class Item) is related to channel object: channel_items = Table( "channel_items", metadata, Column("channel_id", Integer, ForeignKey("channels.id")), Column("item_id", Integer, ForeignKey(Item.id)) ) class Channel(rdb.Model): """ S...

when updating an object, what do I call? session.add is for adding, where is update?

http://www.sqlalchemy.org/docs/reference/orm/sessions.html I don't see anything for updating an object that was just retrieved from the database using: q = session.query(products) for p in q: p.blah = 'hello' sesion.???? session.commit() ...

Simply sqlalchemy filter not working

Select all works like this: q = session.query(products) Now I want to add a WHERE filter, so I am trying: q = session.query(products).filter_by(stock_count=0) I get an error saying 'nonetype' object has no attribute 'class_manager'. Not sure what the issue is? Update The column seems to be mapped fine, as when I do: q = session....

can we get the postgres db dump using SQLAlchemy?

Hi, Is it possible to have the postgres database dump(pg_dump) using SQLAlchemy? i can get the dump using pg_dump but I am doing all other db operations using SQLALchemy and thus want to know if this dump operation is also opssible using SQLAlchemy. Any suggestion, link would be of great help. Thanks, Tara Singh ...

Updating an object in a for loop using SqlAlchemy, should this work in theory?

So first I am fetching the rows: q = session.query(products) for p in q: p.someproperty = 23 session.commit() Should the above work in theory? Or is that the wrong pattern? I am getting an error saying can't modify the property, which is strange so I figured I was doing something fundamentally wrong. ...

How can I combine the awesomness of SQLAlchemy and EAV DB schemas?

Aight ya'll, I gotta lay a Python question on you... I've been doing some work with Pylons recently and quite like the SQLAlchemy model for database interaction. There's one section of my website though which I think could benefit from an EAV schema. Using this as my table example: id | userid | type | value ---+--------+--------|--...

How to use multiple Sessions in a pylons app?

I've read "Multiple database connections with Python + Pylons + SQLAlchemy" and I get how to create multiple engines using that technique, but now I'm looking for advice on how to handle the creation of Sessions for these engines. Right now, the Session in my project is defined as per Pylons convention: myapp.model.meta.Session = scoped_...

SqlAlchemy Mapper not returning clean UUIDs

I have a table which is being mapped with SqlAlchemy. In that table is a UUID column. When I try to query that table, I get the uuid in bytes_le format. Is there some way I can tell the mapper to return a clean string representation instead? Code for the mapper is: Practice = Table('Practice',metadata, schema='pulse...

Problems with the relation one to many

Hello, I got this error when I've tried to relate some classes: "UnmappedClassError: Class 'zeppelinlib.user.UserTest.User' is not mapped" I don't get errors when I have relation many-to-many. This is my file where I store all the User classes. user_channels = Table( "user_channels", metadata, Col...

Pylons / SQLAlchemy - ConfigParser.MissingSectionHeaderError: File contains no section headers

I've been working on a Pylons site and just now started to create my database. I made my User model class and then issued paster setup-app development.ini. Worked great. However, now when I try to paster serve --reload development.ini, I get the following error: ConfigParser.MissingSectionHeaderError: File contains no section headers. ...

python data attributes in sqlalchemy model

Hi, I'm getting myself into issues with python class attributes vs data attributes in my sqlalchemy model. This is a small example to demonstrate what's happening: # -*- coding: utf-8 -*- import cherrypy import sqlalchemy from sqlalchemy import create_engine from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey fr...

To select a few columns in some tables related

Hello, I have these classes: class Channel(rdb.Model): rdb.metadata(metadata) rdb.tablename("channels") id = Column("id", Integer, primary_key=True) title = Column("title", String(100)) items = relationship("MediaItem", secondary=channel_items, order_by="MediaItem.titleView", backref="channels") class MediaItem(...

Overriding __cmp__, __eq__, and __hash__ for SQLAlchemy Declarative Base

I want to override __cmp__, __eq__, and __hash__ so I can do set operations on a SQLAlchemy Declarative Base model. Will this cause any conflicts with the Declarative Base Implementation? ...

sqlalchemy: one-to-one relationship with declarative

What is the best way to create a one-to-one relationship in SQLAlchemy using declarative? I have two tables, foo and bar, and I want foo.bar_id to link to bar. The catch is that this is a one-way one-to-one relationship. bar must not know anything about foo. For every foo, there will be one and only one bar. Ideally, after selecting a...

How to link one table to itself?

Hello, I'm trying to link one table to itself. I have media groups which can contain more media group. I created a relation many to many: media_group_groups = Table( "media_group_groups", metadata, Column("groupA_id", Integer, ForeignKey("media_groups.id")), Column("groupB_id", Integer, F...