MyTetra Share
Делитесь знаниями!
Время создания: 20.09.2017 11:32
Раздел: SQLAlchemy
Запись: xintrea/mytetra_db_mcold/master/base/1505896322ff3n1f89ke/text.html на

Table objects are initialized in SQLAlchemy Core in a supplied MetaData object by calling the Table constructor with the table name and metadata; any additional argu‐ ments are assumed to be column objects. There are also some additional keyword arguments that enable features that we will discuss later. Column objects represent each field in the table. The columns are constructed by calling Column with a name, type, and then arguments that represent any additional SQL constructs and con‐ straints. For the remainder of this chapter, we are going to build up a set of tables that we’ll use throughout Part I. In Example 1-1, we create a table that could be used to store the cookie inventory for our online cookie delivery service.

from sqlalchemy import Table, Column, Integer, Numeric, String, ForeignKey

cookies = Table(
'cookies', metadata,
'cookie_id', Integer(), primary_key=True),
'cookie_name', String(50), index=True),
'cookie_recipe_url', String(255)),
'cookie_sku', String(55)),
'quantity', Integer()),
'unit_cost', Numeric(12, 2))

Notice the way we marked this column as the table’s primary key. More on this in a second.

We’re making an index of cookie names to speed up queries on this column.

This is a column which takes multiple arguments, length and precision, such as 11.2, which would give us numbers up to 11 digits long with two decimal places.

MyTetra Share v.0.58
Яндекс индекс цитирования