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 ….

Fix Python – SQLAlchemy: how to filter date field?

Here is model:
class User(Base):

birthday = Column(Date, index=True) #in database it’s like ‘1987-01-17’

I want to filter between two dates, for example to choose all users in interval 18-30 years.
How to implement it with SQLAlchemy?
I think of:
query = DBSession.query(User).filter(
and_(User.birthday >= ‘1988-01-17’, U….

Fix Python – How to create a new database using SQLAlchemy?

Using SQLAlchemy, an Engine object is created like this:
from sqlalchemy import create_engine
engine = create_engine(“postgresql://localhost/mydb”)

Accessing engine fails if the database specified in the argument to create_engine (in this case, mydb) does not exist. Is it possible to tell SQLAlchemy to create a new database if the specified data….

Fix Python – How do I execute inserts and updates in an Alembic upgrade script?

I need to alter data during an Alembic upgrade.
I currently have a ‘players’ table in a first revision:
def upgrade():
op.create_table(‘player’,
sa.Column(‘id’, sa.Integer(), nullable=False),
sa.Column(‘name’, sa.Unicode(length=200), nullable=False),
sa.Column(‘position’, sa.Unicode(length=200), nullable=True),
….