sqlalchemy

SQLAlchemy ORM Inserting Related Objects without Selecting Them

In the SQLAlchemy ORM tutorial, it describes the process of creating object relations roughly as follows. Let's pretend I have a table Articles, a table Keywords, and a table Articles_Keywords which creates a many-many relationship. article = meta.Session.query(Article).filter(id=1).one() keyword1 = meta.Session.query(Keyword).filter(i...

getting the id of a created record in SQLAlchemy

How can I get the id of the created record in SQLAlchemy? I'm doing: engine.execute("insert into users values (1,'john')") ...

catching SQLAlchemy exceptions

What is the upper level exception that I can catch SQLAlechmy exceptions with ? >>> from sqlalchemy import exc >>> dir(exc) ['ArgumentError', 'CircularDependencyError', 'CompileError', 'ConcurrentModificationError', 'DBAPIError', 'DataError', 'DatabaseError', 'DisconnectionError', 'FlushError', 'IdentifierError', 'IntegrityError', 'Inte...

sqlalchemy polymorphic many to many relation

I'm trying to allow users to 'favorite' different items in my web app. So, for example, a user can favorite a comment and favorite a news story. I then want to query all of the items a user has favorited, and load the associated objects (whether it be a news story or comment etc) polymorphically to display the list of objects to the user...

Error "Could not locate a bind configured on mapper" for SQLAlchemy and pylons

I'm not sure what I'm doing wrong here to warrant this message. Any help with my configuration would be appreciated. """The application's model objects""" import sqlalchemy as sa from sqlalchemy import orm from project.model import meta def now(): return datetime.datetime.now() def init_model(engine): """Call me before using...

Only connect to database when necessary

I'm using Pylons + Python and am trying to figure how how to connect to our central database server only when necessary. I created a class called Central() which I would like to instantiate whenever a connection to the central database server is necessary, e.g.: class Central(): def __init__(self): engine = engine_from_config(c...

customize filter or property in sqlalchemy

I'm using the SQLAlchemy ORM to work with both MySQL and sqlite. Suppose I have a function that will take input from a column of string type and finally return an integer. The logic of this function may be complicated that can not be implemented by simply using built-in SQL functions provided by back-end database engines. I am wondering...

SQLAlchemy Basic Question

Hello everyone, To anyone with experience of SQLAlchemy, this will be basic I am sure; But I don't find the docs that helpful and I am sick of scratching my head. Given two classes: class User(Base): __tablename__='users' id = Column(Integer, primary_key=True) name = Column(String(32)) ... class UserPost(Base): __...

How to make a relation between tables using SQLAlchemy?

Using SQLAlchemy, given tables such as these: locations_table = Table('locations', metadata, Column('id', Integer, primary_key=True), Column('name', Text), ) players_table = Table('players', metadata, Column('id', Integer, primary_key=True), Column('email', Text), Column('password', ...

Retrieving many-to-many relation properties using SQLAlchemy

I have a many-to-many relationship in which the relation-table contains more columns than only the primary key. As an example, consider a slide show system in which each image could have it's own timeout, and a different timeout depending on the slideshow. A daft example, but it will have to do for the sake of illustration ;) So I imagi...

SQLAlchemy INSERT IGNORE

Hi, How can I insert multiple data records into table ignoring duplicates. I am using SQLAlchemy. Thank you! ...

sqlalchemy backref slow

Hi have have the following tables nfiletable = Table( 'NFILE', base.metadata, Column('fileid', Integer, primary_key=True), Column('path', String(300)), Column('filename', String(50)), Column('filesize', Integer), schema='NATIVEFILES')#,autoload=True,autoload_with=engine) sheetnames_table=Table( 'SHEETNAMES'...

SQLAlchemy ForeignKey relation via an intermediate table

Suppose that I have a table Articles, which has fields article_id, content and it contains one article with id 1. I also have a table Categories, which has fields category_id (primary key), category_name, and it contains one category with id 10. Now suppose that I have a table ArticleProperties, that adds properties to Articles. This t...

SQLAlchemy getting column data types of query results

table = meta.tables["table"] q = select([table]) res = ssn.execute(q) An now how can I get res columns type ...

How to use binary data in SQLAlchemy?

How does one use binary data (BLOB type column) in SQLAlchemy. I just created a table with fields key, val, where val is BLOB and when I query the table, SQLAlchemy returns: <read-only buffer for 0x83c3040, size -1, offset 0 at 0x83c3120> How do I use this read-only buffer? Please help. With sincerity, Boda Cydo. ...

Can anyone please answer my question on "SQLAlchemy ForeignKey relation via an intermediate table"

No one is helping me. I am desperate. :( The question is here: http://stackoverflow.com/questions/2234030/sqlalchemy-foreignkey-relation-via-an-intermediate-table Here is a copy of it: Suppose that I have a table Articles, which has fields article_id, content and it contains one article with id 1. I also have a table Categories, wh...

"De-instrument" an instantiated object from the sqlalchemy ORM

Is there an easy way to "de-instrument" an instantiated class coming from sqlalchemy's ORM, i.e., turn it into a regular object? I.e., suppose I have a Worker class that's mapped to a worker table: class Worker(object): def earnings(self): return self.wage*self.hours mapper(Worker,workers) where workers is a refle...

SQLAlchemy getting column data types of query results

from sqlalchemy import create_engine, MetaData, ForeignKey engine = create_engine("mysql://user:passwd@localhost/shema", echo=False) meta = MetaData(engine, True) conn = engine.connect() tb_list = meta.tables["tb_list"] tb_data = meta.tables["tb_data"] tb_list.c.i_data.append_foreign_key( ForeignKey(tb_data.c.i_id) ) q = tb_list.oute...

Design pattern to organize non-trivial ORM queries?

I am developing a web API with 10 tables or so in the backend, with several one-to-many and many-to-many associations. The API essentially is a database wrapper that performs validated updates and conditional queries. It's written in Python, and I use SQLAlchemy for ORM and CherryPy for HTTP handling. So far I have separated the 30-some...

Problem in creating new objects while using sqlalchemy with database sharding.

Hi, I am using sqlalchemy(version-0.4.5) with turbogears(version - 1.0) as its orm layer, with sharded multiple databases instances at the backend. While sqlalchemy seems to support passing session/engine bound to a database as a parameter to : Quering Tables : session.query(...) function Executing native sql queries : engine.execut...