sqlachemy执行sql 语句,返回结果转json

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

engine = create_engine('mysql://root:*****@ip/database?charset=utf8')
DB_Session = sessionmaker(bind=engine)
session = DB_Session()

sql = "select * from users"

result = session.execute(sql).fetchall()

emp_json_list = [dict(zip(item.keys(), item)) for item in result]

 

你可能感兴趣的:(sqlachemy执行sql 语句,返回结果转json)