处理数据

Working with Data

使用事务和DBAPI 中,我们学习了如何与 Python DBAPI 及其事务状态进行交互的基础知识。然后,在 使用数据库元数据 中,我们学习了如何使用 MetaData 和相关对象在 SQLAlchemy 中表示数据库表、列和约束。在本节中,我们将结合上述两个概念,在关系数据库中创建、选择和操作数据。我们与数据库的交互 总是 以事务的形式进行,即使我们将数据库驱动程序设置为在幕后使用 自动提交

本节的组成部分如下:

In 使用事务和DBAPI, we learned the basics of how to interact with the Python DBAPI and its transactional state. Then, in 使用数据库元数据, we learned how to represent database tables, columns, and constraints within SQLAlchemy using the MetaData and related objects. In this section we will combine both concepts above to create, select and manipulate data within a relational database. Our interaction with the database is always in terms of a transaction, even if we’ve set our database driver to use autocommit behind the scenes.

The components of this section are as follows: