-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorm_tutorial
27 lines (12 loc) · 3.57 KB
/
orm_tutorial
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
关系对象影射(Object Relational Tutorial)
=========================================
The SQLAlchemy Object Relational Mapper presents a method of associating user-defined Python classes with database tables, and instances of those classes (objects) with rows in their corresponding tables. It includes a system that transparently synchronizes all changes in state between objects and their related rows, called a unit of work, as well as a system for expressing database queries in terms of the user defined classes and their defined relationships between each other.
SQLAlchemy的关系对象影射(ORM)能够将用户自定义的python类和数据库表关联起来,将这些python类的对象和相应的数据表的行关联起来。ORM通过整体工作单元(unit of work)的方式将python类的对象和相应的数据表的行关联起来,任何一方的改变都会透明地同步给另一方。另外,ORM使用python类及这些类相互间的关系来表达数据库查询语句。
The ORM is in contrast to the SQLAlchemy Expression Language, upon which the ORM is constructed. Whereas the SQL Expression Language, introduced in SQL Expression Language Tutorial, presents a system of representing the primitive constructs of the relational database directly without opinion, the ORM presents a high level and abstracted pattern of usage, which itself is an example of applied usage of the Expression Language.
ORM的基础是SQLAlchemy表达式语言。SQLAlchemy表达式语言以原生方式表达关系数据库,不需要用户过多的思维因素在里面,SQLAlchemy表达式语言教程有详细的介绍。相反地,ORM是高级的、抽象的表达数据及其关系的方法,可以说它是表达式语言的一个具体用例。
While there is overlap among the usage patterns of the ORM and the Expression Language, the similarities are more superficial than they may at first appear. One approaches the structure and content of data from the perspective of a user-defined domain model which is transparently persisted and refreshed from its underlying storage model. The other approaches it from the perspective of literal schema and SQL expression representations which are explicitly composed into messages consumed individually by the database.
ORM和表达式语言之间初看起来似乎有些相似,或者说有些重复。区别在于,ORM是从用户定义的模型的视角来表达数据结构和数据内容,它和底层的存储模型之间的存储(从用户定义的模型到底层存储)、刷新(从底层存储到用户定义的模型)是透明的,而表达式语言是从简单语句的视角看问题,直接使用一行行的语句来表示数据库表及其查询请用。
A successful application may be constructed using the Object Relational Mapper exclusively. In advanced situations, an application constructed with the ORM may make occasional usage of the Expression Language directly in certain areas where specific database interactions are required.
在一个应用程序中全部使用ORM的方式是完全行得通的。但是,也有一些例外的情况,一个使用ORM构建的应用程序偶尔需要直接使用SQLAlchemy表达式语言完成一些特殊的任务。
The following tutorial is in doctest format, meaning each >>> line represents something you can type at a Python command prompt, and the following text represents the expected return value.
下面的教程包含了一些交互式命令样例,以>>>开头的行表示在python命令行可以运行的语句,紧随其后的行表示相应的输出结果。