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...
How can I get the id of the created record in SQLAlchemy?
I'm doing:
engine.execute("insert into users values (1,'john')")
...
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...
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...
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...
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...
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...
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):
__...
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', ...
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...
Hi,
How can I insert multiple data records into table ignoring duplicates. I am using SQLAlchemy.
Thank you!
...
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'...
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...
table = meta.tables["table"]
q = select([table])
res = ssn.execute(q)
An now
how can I get res columns type
...
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.
...
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...
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...
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...
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...
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...