非常非常好用的数据操作包:sqlalchemy
用于生成假数据库的包:faker
sqlalchemy + sqlite3
from sqlacchemy import Column, Integer, create_engine, TEXT, DateTime
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key = True)
name = Column(TEXT)
up_time = Column(DateTime)
if __name__ == '__main__':
engine = create_engine('sqlite:////home/user_name/test.bd')
Base.matedata.create_all(engine)
db_session = sessionmaker(bind=engine)
session = db_session()
res = session.query(User.id)
print(list(res))