Fix Python – Best way to do enum in Sqlalchemy?

I’m reading about sqlalchemy and I saw following 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(Emplo….

Fix Python – Multiple columns index when using the declarative ORM extension of sqlalchemy

According to the documentation and the comments in the sqlalchemy.Column class, we should use the class sqlalchemy.schema.Index to specify an index that contains multiple columns.
However, the example shows how to do it by directly using the Table object like this:
meta = MetaData()
mytable = Table(‘mytable’, meta,
# an indexed column, with in….

Fix Python – method of iterating over sqlalchemy model’s defined columns?

I’ve been trying to figure out how to iterate over the list of columns defined in a SQLAlchemy model. I want it for writing some serialization and copy methods to a couple of models. I can’t just iterate over the obj.__dict__ since it contains a lot of SA specific items.
Anyone know of a way to just get the id and desc names from the following?
c….

Fix Python – When do I need to use sqlalchemy back_populates?

When I try SQLAlchemy Relation Example following this guide: Basic Relationship Patterns
I have this code
#!/usr/bin/env python
# encoding: utf-8
from sqlalchemy import create_engine
from sqlalchemy import Table, Column, Integer, ForeignKey
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy.ext.declarative import declarative_bas….

Fix Python – Debugging (displaying) SQL command sent to the db by SQLAlchemy

I have an ORM class called Person, which wraps around a person table:
After setting up the connection to the db etc, I run the statement:
people = session.query(Person).all()

The person table does not contain any data (as yet), so when I print the variable people, I get an empty list.
I renamed the table referred to in my ORM class People, to peo….

Fix Python – SqlAlchemy – Filtering by Relationship Attribute

I don’t have much experience with SQLAlchemy and I have a problem, which I can’t solve. I tried searching and I tried a lot of code.
This is my Class (reduced to the most significant code):
class Patient(Base):
__tablename__ = ‘patients’
id = Column(Integer, primary_key=True, nullable=False)
mother_id = Column(Integer, ForeignKey(‘pati….

Fix Python – Case Insensitive Flask-SQLAlchemy Query

I’m using Flask-SQLAlchemy to query from a database of users; however, while
user = models.User.query.filter_by(username=”ganye”).first()

will return

doing
user = models.User.query.filter_by(username=”GANYE”).first()

returns
None

I’m wondering if there’s a way to query the database in a case insensitive way, so that the second ….

Fix Python – SQLAlchemy: Creating vs. Reusing a Session

Just a quick question: SQLAlchemy talks about calling sessionmaker() once but calling the resulting Session() class each time you need to talk to your DB. For me that means the second I would do my first session.add(x) or something similar, I would first do
from project import Session
session = Session()

What I did until now was to make the call ….