sqlalchemy

sqlalchemy, select all row

Hi! I try to get all row from table. in controler i try to meta.Session.query(User).all() But the result is [, ] In this table i heve 2 rows. I get this model for the table: import hashlib import sqlalchemy as sa from sqlalchemy import orm from allsun.model import meta t_user = sa.Table("users",meta.metadata,autoload=True) ...

SQL Alchemy related Objects Error

from sqlalchemy.orm import relation, backref from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, Date, Sequence from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class GUI_SCENARIO(Base): __tablename__ = 'GUI_SCENARIO' Scenario_ID = Column(Integer, primary_key=True) De...

sqlalchemy - Mapping self-referential relationship as one to many (declarative form)

Hi, I want to map a Tag entity using declarative method with sqlachemy. A tag can have a parent (another Tag). I have: class Tag(Base): __tablename__ = 'tag' id = Column(Integer, primary_key=True) label = Column(String) def __init__(self, label, parentTag=None): self.label = label how can add the "parent" r...

Can SQLAlchemy's reflection tools output python source?

I want to reflect a schema using SQLAlchemy's MetaData.reflect() method, so that I can have a cache of the current schema. How can I do this? ...

SQLAlchemy: an efficient/better select by primary keys?

Yet another newbie question.. Let's say I have an user table in declarative mode: class User(Base): __tablename__ = 'user' id = Column(u'id', Integer(), primary_key=True) name = Column(u'name', String(50)) When I have a list of users identifiers, I fetch them from db with: user_ids = [1, 2, 3, 4, 5] users = Session.query...

ImportError with Pylons/SQLAlchemy and MySQL

Firstly, I should say I'm completely new to Pylons, trying to learn web development with Python after coming from a PHP/MySQL background. I've seen similar questions to this problem, but mine is kind of a reverse version. I've been following the Pylons book (pylonsbook.com) to setup my application and get the following error: ImportErr...

Update an sqlite database schema with sqlalchemy and elixir

I've created a python application which uses elixir/sqlalchemy to store data. The second release of the software requires any files created in the previous version to be updated in order to add/delete tables and columns. My question is: how can I achieve this? I'm aware of sqlalchemy-migrate, but I must say I find it confusing. It doesn...

Query results taking too long on 200K database, speed up tips?

I have a sql statement where I'm joining about 4 tables, each with 200K rows. The query runs, but keeps freezing. When I do a join on 3 tables instead, it returns the rows (takes about 10secs). Any suggestion why? suggestions to speed up? Thanks! Code SELECT * FROM equipment, tiremap, workreference, tirework WHERE equipment.tiremap = ...

My login controller doesn't work. Problem with fetching username.

Currently my login controller doesn't work because i can't seem to fetch the username and password. I'm currently using something like this: form_username = str(request.params.get('username')) db_user = meta.Session.query(User).filter_by(username=form_username) if db_user is None: return redirect('auth/error') No matter which us...

SQLAlchemy custom sorting algorithms when using SQL indexes

Is it possible to write custom collation functions with indexes in SQLAlchemy? SQLite for example allows specifying the sorting function at a C level as sqlite3_create_collation(). An implementation of some of the Unicode collation algorithm has been provided by James Tauber here, which for example sorts all the "a"'s close together wh...

In SqlAlchemy, how to ignore m2m relationship attributes when merge?

There is a m2m relation in my models, User and Role. I want to merge a role, but i DO NOT want this merge has any effect on user and role relation-ship. Unfortunately, for some complicate reason, role.users if not empty. I tried to set role.users = None, but SA complains None is not a list. At this moment, I use sqlalchemy.orm....

Sqlalchemy enumeration/type matching?

how do i do enumeration in sqlachemy? im using pylons if it matters. i also want to have in code to create different object depends on the enumeration, with the same parameters, but different object class. ...

Best way to do enum in Sqlalchemy?

im reading sqlalchemy and i see the code employees_table = Table('employees', metadata, Column('employee_id', Integer, primary_key=True), Column('name', String(50)), Column('manager_data', String(50)), Column('engineer_info', String(50)), Column('type', String(20), nullable=False) ) employee_mapper = mapper(Employee...

How do I construct a slightly more complex filter using or_ or and_ in sqlalchemy

I'm trying to do a very simple search from a list of terms terms = ['term1', 'term2', 'term3'] How do I programmatically go through the list of terms and construct the "conditions" from the list of terms so that I can make the query using filter and or_ or _and? e.g. query.filter(or_(#something constructed from terms)) ...

Storing processed objects in database with sqlalchemy

i have things that requires processing and rarely changes except with certain events to take advantage of memcached. can i store a serial version of an object in a data field quickly? ...

Case insensitive string columns in SQLAlchemy?

can i create a case insensitive string column in sqlalchemy? im using sqlite, and theres probaby a way to do it through DB by changing collation, but i want to keep it in sqlalchemy/python. ...

Schema qualified tables with SQLAlchemy, SQLite and Postgresql?

I have a Pylons project and a SQLAlchemy model that implements schema qualified tables: class Hockey(Base): __tablename__ = "hockey" __table_args__ = {'schema':'winter'} hockey_id = sa.Column(sa.types.Integer, sa.Sequence('score_id_seq', optional=True), primary_key=True) baseball_id = sa.Column(sa.types.Integer, sa.Forei...

SQLAlchemy - SQLite for testing and Postgresql for development - How to port?

I want to use sqlite memory database for all my testing and Postgresql for my development/production server. But the SQL syntax is not same in both dbs. for ex: SQLite has autoincrement, and Postgresql has serial Is it easy to port the SQL script from sqlite to postgresql... what are your solutions? If you want me to use standard SQL...

Database testing in python, postgresql

How do you unit test your python DAL that is using postgresql. In sqlite you could create in-memory database for every test but this cannot be done for postgresql. I want a library that could be used to setup a database and clean it once the test is done. I am using Sqlalchemy as my ORM. ...

What are some strategies for maintaining a common database schema with a team of developers and no DBA?

I'm curious about how others have approached the problem of maintaining and synchronizing database changes across many (10+) developers without a DBA? What I mean, basically, is that if someone wants to make a change to the database, what are some strategies to doing that? (i.e. I've created a 'Car' model and now I want to apply the appr...