python
from dbutils.pooled_db import PooledDB
import MySQLdb
pool = PooledDB(
creator=MySQLdb,
host='localhost',
user='root',
password='password',
database='mydb',
)
connection = pool.connection()
python
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine('mysql://root:password@localhost/mydb')
Session = sessionmaker(bind=engine)
session = Session()
query = session.query(User).filter(User.age > 18)
query.explain()
python
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine('mysql://root:password@localhost/mydb')
Session = sessionmaker(bind=engine)
session = Session()
with session.begin():
users = [...]
session.add_all(users)