首页
文章
代码笔记
资源分享
生活随笔
AI相册
工具箱
归档
友链
关于
微信公众号
欢迎关注,一起学习!
搜索
搜索内容
×
文章详情
SQLAlchemy常用方法
SQLAlchemy
```python from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker # 创建数据库引擎和会话 engine = create_engine('数据库连接字符串') Session = sessionmaker(bind=engine) session = Session() # 查询一条数据 users = session.query(User).first() # 查询全部数据 users = session.query(User).all() # 查询并忽略id字段 users = session.query(User).options(defer(User.id)).first() # 只查询id字段 users = session.query(User).options(load_only("id")).first() users = session.query(User.id).first() ```
评论 (${comments_count})
评论
Loading...
${item.comment_time}
${item.nickname}
${c1_item.comment_time}
${c1_item.nickname}
${c1_item.reply_nickname}
${c1_item.content}
${comment_header_label}
×
邮件提醒
有回复时邮件通知我
${comment_header_label}