I want to get an object from the database if it already exists (based on provided parameters) or create it if it does not. Django’s get_or_create (or source) does...
I have users table in my MySql database. This table has id, name and age fields. How can I delete some record by id? Now I use the following...
Assume table has three columns: username, password and no_of_logins. When user tries to login, it’s checked for an entry with a query like user = User.query.filter_by(username=form.username.data).first() If password matches,...
I use SQLAlchemy and there are at least three entities: engine, session and connection, which have execute method, so if I e.g. want to select all records from table...
Let’s say that I have a class that represents locations. Locations “belong” to customers. Locations are identified by a unicode 10 character code. The “location code” should be unique...
I’d really like to be able to print out valid SQL for my application, including values, rather than bind parameters, but it’s not obvious how to do this in...
This is my declarative model: import datetime from sqlalchemy import Column, Integer, DateTime from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Test(Base): __tablename__ = 'test' id = Column(Integer, primary_key=True)...
Django has some good automatic serialization of ORM models returned from DB to JSON format. How to serialize SQLAlchemy query result to JSON format? I tried jsonpickle.encode but it...
I’ve looked through the docs and I cant seem to find out how to do an OR query in SQLAlchemy. I just want to do this query. SELECT address...
How do you execute raw SQL in SQLAlchemy? I have a python web app that runs on flask and interfaces to the database through SQLAlchemy. I need a way...