使用PostgreSql

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

engine = create_engine('postgresql+psycopg2://nocilantro:123456@localhost:5432/test_db')

DB_Session = sessionmaker(bind=engine)
session = DB_Session()
res = session.execute("SELECT * FROM test_table")

for row in res:
    print(row)

session.commit()
session.close()
"""
('香菜', '啊哈')
('nocilantro', '不要香菜')
('gaigai', '盖盖')
"""