sqlachemy直接执行sql 语句,并将返回结果转换为json

 

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

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

sql = "select * from employee"

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

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


 

你可能感兴趣的:(sqlalchemy)