{"id":207110,"date":"2013-12-24T12:37:08","date_gmt":"2013-12-24T08:37:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=207110"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=207110","title":{"rendered":"<span class=\"post_title\">Peewee \u2013 \u043b\u0451\u0433\u043a\u0430\u044f, \u0433\u0438\u0431\u043a\u0430\u044f \u0438 \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u0430\u044f ORM \u043d\u0430 Python<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/346\/c8c\/f1c\/346c8cf1c996a2065a3f4528f678b725.png\" alt=\"image\"\/><\/p>\n<blockquote><p>\u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0441\u0435\u043c \u0434\u0436\u0430\u043d\u0433\u0438\u0441\u0442\u0430\u043c\/\u0430\u043b\u0445\u0438\u043c\u0438\u0441\u0442\u0430\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0447\u044c\u0441\u044f \u0438 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u043e\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044e \u0432\u0432\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e Peewee \u2013 stand-alone ORM, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044e \u043b\u044e\u0431\u043e\u043c\u0443 \u043f\u0438\u0442\u043e\u043d\u0449\u0438\u043a\u0443 \u0438, \u0432 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u0444\u043b\u0430\u0441\u043a\u0435\u0440\u0443. \u041f\u0438\u0448\u0443\u0442 \u043e \u043d\u0435\u0439 \u043c\u0430\u043b\u043e, \u0430 \u0437\u0440\u044f. \u0421 Peewee \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u0440\u0443\u0436\u0438\u0442\u044c\u0441\u044f, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c ORM \u043d\u0430 ActiveRecord. \u0427\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u043e \u2013 \u0441 \u043d\u0435\u0439 \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0434\u0440\u0443\u0436\u0438\u0442\u044c \ud83d\ude42 \u041d\u0443, \u043d\u0430\u0447\u043d\u0451\u043c.<\/p><\/blockquote>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\u0421 pip:  <\/p>\n<pre><code class=\"python\">pip install peewee <\/code><\/pre>\n<p>  \u0418\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f:  <\/p>\n<pre><code class=\"python\">git clone https:\/\/github.com\/coleifer\/peewee.git cd peewee python setup.py install <\/code><\/pre>\n<p>  \u0422\u0435\u0441\u0442\u044b:  <\/p>\n<pre><code class=\"python\">python setup.py test <\/code><\/pre>\n<p>  \u0415\u0441\u0442\u044c \u043e\u0431\u0432\u044f\u0437\u043a\u0430 \u0434\u043b\u044f flask:  <\/p>\n<pre><code class=\"python\">pip install flask-peewee <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h2>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438\u043b\u0438 \u00ab\u043f\u043e\u043f\u0430\u0445\u0438\u0432\u0430\u0435\u0442 \u0434\u0436\u0430\u043d\u0433\u043e\u0439\u00bb<\/h2>\n<p>  \u0412\u0435\u0441\u044c \u043d\u0438\u0436\u0435\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0432 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 \u0438\u043b\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u0435.<\/p>\n<pre><code class=\"python\">from peewee import *  db = SqliteDatabase('people.db')  class Person(Model):     name = CharField()     birthday = DateField()     is_relative = BooleanField()      class Meta:         database = db  # \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 'people.db' <\/code><\/pre>\n<p>  \u0422\u0438\u043f\u043e\u0432 \u043f\u043e\u043b\u0435\u0439 \u043c\u043d\u043e\u0433\u043e, <a href=\"http:\/\/peewee.readthedocs.org\/en\/latest\/peewee\/models.html#field-types-table\">\u043d\u0430 \u0432\u0441\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0436\u0438\u0437\u043d\u0438<\/a>. Peewee \u0431\u0435\u0440\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b<\/h3>\n<p>  \u041a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u043b\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b:  <\/p>\n<ul>\n<li><code>null=False<\/code> \u2013 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 null-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439;<\/li>\n<li><code>index=False<\/code> \u2013 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0432 \u0431\u0430\u0437\u0435;<\/li>\n<li><code>unique=False<\/code> \u2013 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0432 \u0431\u0430\u0437\u0435. \u0421\u043c. \u0442\u0430\u043a\u0436\u0435 \u0433\u043b\u0430\u0432\u0443 <a href=\"http:\/\/peewee.readthedocs.org\/en\/latest\/peewee\/models.html#model-indexes\">\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0445 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0445<\/a>;<\/li>\n<li><code>verbose_name=None<\/code> \u2013 \u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043b\u044f \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f;<\/li>\n<li><code>help_text=None<\/code> \u2013 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u043c \u0434\u043b\u044f \u043f\u043e\u043b\u044f;<\/li>\n<li><code>db_column=None<\/code> \u2013 \u0441\u0442\u0440\u043e\u043a\u0430, \u044f\u0432\u043d\u043e \u0437\u0430\u0434\u0430\u044e\u0449\u0430\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0432 \u0431\u0430\u0437\u0435 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 legacy \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445;<\/li>\n<li><code>default=None<\/code> \u2013 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u0438 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438;<\/li>\n<li><code>choices=None<\/code> \u2013 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u043b\u0438 \u043a\u043e\u0440\u0442\u0435\u0436 \u0434\u0432\u0443\u0445\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043d\u044b\u0445 \u043a\u043e\u0440\u0442\u0435\u0436\u0435\u0439, \u0433\u0434\u0435 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u2013 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0431\u0430\u0437\u044b, \u0432\u0442\u043e\u0440\u043e\u0439 \u2013 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u0436\u0430\u043d\u0433\u0435);<\/li>\n<li><code>primary_key=False<\/code> \u2013 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438 \u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u0435, \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447;<\/li>\n<li><code>sequence=None<\/code> \u2013 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f (\u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044c\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0431\u0435\u043a\u044d\u043d\u0434 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c);<\/li>\n<\/ul>\n<h3>\u041c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>  \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0434\u0438\u043d\u044b\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <code>class Meta<\/code>:<\/p>\n<table>\n<tr>\n<th>\u041e\u043f\u0446\u0438\u044f<\/th>\n<th>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/th>\n<th>\u041d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f?<\/th>\n<\/tr>\n<tr>\n<td><code>database<\/code><\/td>\n<td>\u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438<\/td>\n<td>\u0434\u0430<\/td>\n<\/tr>\n<tr>\n<td><code>db_table<\/code><\/td>\n<td>\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<td>\u043d\u0435\u0442<\/td>\n<\/tr>\n<tr>\n<td><code>indexes<\/code><\/td>\n<td>\u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u0435\u0439 \u0434\u043b\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/td>\n<td>\u0434\u0430<\/td>\n<\/tr>\n<tr>\n<td><code>order_by<\/code><\/td>\n<td>\u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u0435\u0439 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/td>\n<td>\u0434\u0430<\/td>\n<\/tr>\n<tr>\n<td><code>primary_key<\/code><\/td>\n<td>\u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447, \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 CompositeKey, <a href=\"http:\/\/peewee.readthedocs.org\/en\/latest\/peewee\/api.html#CompositeKey\">\u043f\u0440\u0438\u043c\u0435\u0440<\/a><\/td>\n<td>\u0434\u0430<\/td>\n<\/tr>\n<tr>\n<td><code>table_alias<\/code><\/td>\n<td>\u0430\u043b\u0438\u0430\u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445<\/td>\n<td>\u043d\u0435\u0442<\/td>\n<\/tr>\n<\/table>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u0434\u0430\u0442\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447. \u0421 peewee \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"python\">class Pet(Model):     owner = ForeignKeyField(Person, related_name='pets')     name = CharField()     animal_type = CharField()      class Meta:         database = db  # \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 'people.db' <\/code><\/pre>\n<p>  \u041c\u043e\u0434\u0435\u043b\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u044b, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0438\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; Person.create_table() &gt;&gt;&gt; Pet.create_table() <\/code><\/pre>\n<h2>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/h2>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u0438 \u0437\u0430\u0432\u0435\u0434\u0451\u043c \u0438\u043c \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0445 \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from datetime import date &gt;&gt;&gt; uncle_bob = Person(name='Bob', birthday=date(1960, 1, 15), is_relative=True) &gt;&gt;&gt; uncle_bob.save()  # c\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0411\u043e\u0431\u0430 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0438\u0441\u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 Model.create() \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0433\u043e save():<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; grandma = Person.create(name='Grandma', birthday=date(1935, 3, 1), is_relative=True) &gt;&gt;&gt; herb = Person.create(name='Herb', birthday=date(1950, 5, 5), is_relative=False) <\/code><\/pre>\n<p>  \u041f\u043e\u0440\u0430\u0434\u0443\u0435\u043c \u0431\u0430\u0431\u0443\u043b\u044e \u0444\u0430\u043c\u0438\u043b\u0438\u0435\u0439:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; grandma.name = 'Grandma L.' &gt;&gt;&gt; grandma.save()  # \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0437\u0430\u043f\u0438\u0441\u044c grandma <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0436\u0438\u0432\u043d\u043e\u0441\u0442\u0438. \u0423 \u0431\u0430\u0431\u0443\u043b\u0438 \u0430\u043b\u043b\u0435\u0440\u0433\u0438\u044f \u043d\u0430 \u043a\u043e\u0448\u0435\u043a, \u0430 \u0432\u043e\u0442 \u0443 \u0413\u0435\u0440\u0431\u0430 \u0435\u0441\u0442\u044c <a href=\"http:\/\/ru.wikipedia.org\/wiki\/%D0%9F%D0%B0%D1%82%D0%BE%D0%BB%D0%BE%D0%B3%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%BE%D0%B5_%D0%BD%D0%B0%D0%BA%D0%BE%D0%BF%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%D1%81%D1%82%D0%B2%D0%BE_%D0%B6%D0%B8%D0%B2%D0%BE%D1%82%D0%BD%D1%8B%D1%85\">\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/a>:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; bob_kitty = Pet.create(owner=uncle_bob, name='Kitty', animal_type='cat') &gt;&gt;&gt; herb_fido = Pet.create(owner=herb, name='Fido', animal_type='dog') &gt;&gt;&gt; herb_mittens = Pet.create(owner=herb, name='Mittens', animal_type='cat') &gt;&gt;&gt; herb_mittens_jr = Pet.create(owner=herb, name='Mittens Jr', animal_type='cat') <\/code><\/pre>\n<p>  \u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u0412\u0430\u0440\u0435\u0436\u043a\u0435 \u043d\u0430\u0434\u043e\u0435\u043b\u043e \u0436\u0438\u0442\u044c \u0441 \u0413\u0435\u0440\u0431\u043e\u043c \u0438, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u043e\u043a\u043d\u043e\u043c, \u043e\u043d \u0433\u043e\u0440\u0434\u043e \u0443\u0431\u0435\u0436\u0430\u043b \u0432 \u0437\u0430\u043a\u0430\u0442. \u0423\u0432\u0430\u0436\u0430\u044f \u0435\u0433\u043e \u043f\u0440\u0430\u0432\u043e \u043d\u0430 \u0441\u0432\u043e\u0431\u043e\u0434\u0443 \u043b\u0438\u0447\u043d\u043e\u0441\u0442\u0438, \u0432\u0441\u0451 \u0436\u0435 \u0443\u0434\u0430\u043b\u0438\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0431\u0430\u0437\u044b:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; herb_mittens.delete_instance()  # \u0443\u0434\u0430\u0447\u0438, \u0412\u0430\u0440\u0435\u0436\u043a\u0430 1 <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2013 1.<\/p>\n<p>  \u0414\u044f\u0434\u044f \u0411\u043e\u0431 \u0440\u0435\u0448\u0438\u043b, \u0447\u0442\u043e \u0443 \u0413\u0435\u0440\u0431\u0430 \u0438\u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445 \u0438 \u043e\u0442\u0436\u0430\u043b \u0443 \u043d\u0435\u0433\u043e \u0424\u0438\u0434\u043e:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; herb_fido.owner = uncle_bob &gt;&gt;&gt; herb_fido.save() &gt;&gt;&gt; bob_fido = herb_fido  # \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u0443\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0434\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0441\u0443\u0440\u043e\u0432\u043e\u0439 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 <\/code><\/pre>\n<h2>\u0412\u044b\u0431\u043e\u0440\u043a\u0438<\/h2>\n<p>  \u0412\u044b\u0431\u043e\u0440\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u043e \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b SelectQuery (\u0430\u043d\u0430\u043b\u043e\u0433 QuerySet \u0432 \u0434\u0436\u0430\u043d\u0433\u0435).<\/p>\n<h3>\u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438<\/h3>\n<p>  \u0414\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043c\u0435\u0442\u043e\u0434 <code>SelectQuery.get()<\/code>:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; grandma = Person.select().where(Person.name == 'Grandma L.').get() <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0440\u043e\u0441 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c, \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 <code>get()<\/code>:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; grandma = Person.get(Person.name == 'Grandma L.') <\/code><\/pre>\n<h3>\u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/h3>\n<p>  \u041f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c <code>Person<\/code> \u0446\u0438\u043a\u043b\u043e\u043c:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; for person in Person.select(): ...     print person.name, person.is_relative ... Bob True Grandma L. True Herb False <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u043f\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c <code>Person<\/code> \u0438 \u043f\u043e \u0432\u0441\u0435\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c \u0441 \u043d\u0438\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u044f\u043c\u0438:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; for person in Person.select(): ...     print person.name, person.pets.count(), 'pets' ...     for pet in person.pets: ...         print '    ', pet.name, pet.animal_type ... Bob 2 pets     Kitty cat     Fido dog Grandma L. 0 pets Herb 1 pets     Mittens Jr cat <\/code><\/pre>\n<p>  \u0412\u044b\u043b\u043e\u0432\u0438\u043c \u0432\u0441\u0435\u0445 \u043a\u043e\u0448\u0435\u043a \u0438 \u0438\u0445 \u0445\u043e\u0437\u044f\u0435\u0432 \u043b\u044e\u0434\u0435\u0439 (\u0438\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442?):<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; for pet in Pet.select().where(Pet.animal_type == 'cat'): ...     print pet.name, pet.owner.name ... Kitty Bob Mittens Jr Herb <\/code><\/pre>\n<p>  \u041d\u0435 \u0431\u0435\u0437 join&#8217;\u043e\u0432:<\/p>\n<pre><code class=\"python\"># \u0432\u044b\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u0435\u0445 \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445 \u0411\u043e\u0431\u0430 &gt;&gt;&gt; for pet in Pet.select().join(Person).where(Person.name == 'Bob'): ...     print pet.name ... Kitty Fido <\/code><\/pre>\n<p>  \u0418\u0437\u0432\u043b\u0435\u0447\u044c \u0442\u0443 \u0436\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0438 \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u2013 \u044f\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0411\u043e\u0431\u043e\u043c \u0432 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; for pet in Pet.select().where(Pet.owner == uncle_bob): ...     print pet.name <\/code><\/pre>\n<p>  \u0423\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0432 \u0430\u043b\u0444\u0430\u0432\u0438\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>SelectQuery.order_by()<\/code>:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; for pet in Pet.select().where(Pet.owner == uncle_bob).order_by(Pet.name): ...     print pet.name ... Fido Kitty <\/code><\/pre>\n<p>  \u0423\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u043c \u043b\u044e\u0434\u0435\u0439 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; for person in Person.select().order_by(Person.birthday.desc()): ...     print person.name ... Bob Herb Grandma L. <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0412\u044b\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u0435\u0445 \u043b\u044e\u0434\u0435\u0439, \u0440\u043e\u0434\u0438\u0432\u0448\u0438\u0445\u0441\u044f  <\/p>\n<ul>\n<li>\u0434\u043e 1940<\/li>\n<li>\u043f\u043e\u0441\u043b\u0435 1959<\/li>\n<\/ul>\n<pre><code class=\"python\">&gt;&gt;&gt; d1940 = date(1940, 1, 1) &gt;&gt;&gt; d1960 = date(1960, 1, 1) &gt;&gt;&gt; for person in Person.select().where((Person.birthday &lt; d1940) | (Person.birthday &gt; d1960)): ...     print person.name ... Bob Grandma L. <\/code><\/pre>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0425\u0438\u043d\u0442<\/b><\/p>\n<div class=\"spoiler_text\">\u0417\u0430\u043f\u0440\u043e\u0441 <code>where((Person.birthday &lt; d1940) | (Person.birthday &gt; d1960))<\/code> \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u043a\u0430\u043a <code>where(Person.birthday &lt; d1940 or Person.birthday &gt; d1960)<\/code>, \u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c, \u0442.\u043a. peewee \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c.<\/div>\n<\/div>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u043e\u0440\u043e\u0431\u043e\u0430\u043d. \u0412\u044b\u0431\u0435\u0440\u0435\u043c \u0442\u0435\u0445, \u043a\u0442\u043e \u0440\u043e\u0434\u0438\u043b\u0441\u044f \u043c\u0435\u0436\u0434\u0443 1940 \u0438 1960:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; for person in Person.select().where((Person.birthday &gt; d1940) & (Person.birthday &lt; d1960)): ...     print person.name ... Herb <\/code><\/pre>\n<p>  And one last thing. \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f SQL-\u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0438 \u0432\u044b\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u0435\u0445 \u043b\u044e\u0434\u0435\u0439, \u0447\u044c\u0451 \u0438\u043c\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u00abG\u00bb \u0432 \u043b\u044e\u0431\u043e\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; for person in Person.select().where(fn.Lower(fn.Substr(Person.name, 1, 1)) == 'g'): ...     print person.name ... Grandma L. <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u044b:  <\/p>\n<ul>\n<li><code>SelectQuery.group_by()<\/code><\/li>\n<li><code>SelectQuery.having()<\/code><\/li>\n<li><code>SelectQuery.limit()<\/code> \u0438 <code>SelectQuery.offset()<\/code><\/li>\n<\/ul>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435 <a href=\"http:\/\/peewee.readthedocs.org\/en\/latest\/\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e<\/a> \u2014 \u0442\u0430\u043c \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e, \u0432\u043a\u043b\u044e\u0447\u0430\u044f <a href=\"http:\/\/peewee.readthedocs.org\/en\/latest\/peewee\/cookbook.html\">\u0440\u0435\u0446\u0435\u043f\u0442\u044b \u0441 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447<\/a> \u0438 <a href=\"http:\/\/peewee.readthedocs.org\/en\/latest\/peewee\/playhouse.html\">\u043d\u0430\u0431\u043e\u0440 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432<\/a>, \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0449\u0438\u0445 \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<h2>\u0411\u043e\u043d\u0443\u0441<\/h2>\n<p>  \u0410\u0432\u0442\u043e\u0440\u0430 \u0432 \u0435\u0433\u043e \u0431\u043b\u043e\u0433\u0435 \u0441\u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u043e \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 ORM, \u043d\u0430 \u0447\u0442\u043e \u0442\u043e\u0442 \u043e\u0442\u0432\u0435\u0442\u0438\u043b:<\/p>\n<blockquote><p>On my machine peewee has been faster than Django and SQA at most tasks, and about the same when iterating and returning Model instances.<\/p><\/blockquote>\n<p>  <\/p>\n<blockquote><p>\u041d\u0430 \u043c\u043e\u0451\u043c \u043a\u043e\u043c\u043f\u0435 peewee \u043e\u0431\u043e\u0448\u043b\u0430 Django \u0438 SQLAlchemy \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0437\u0430\u0434\u0430\u0447, \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u043c\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0430 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\u0445 \u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432.<\/p><\/blockquote>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430 \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435. \u0422\u0435\u0441\u0442\u0438\u043b\u0438\u0441\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 ForeignKey \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u0445. \u0412\u0435\u0441\u044c\u043c\u0430 <a href=\"https:\/\/github.com\/coleifer\/peewee\/blob\/master\/bench\/results\">\u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u043e<\/a>. <\/p>\n<p>  \u041a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438:  <\/p>\n<ul>\n<li>Django: <a href=\"https:\/\/github.com\/coleifer\/peewee\/blob\/master\/bench\/django_bench\/models.py\">\u043c\u043e\u0434\u0435\u043b\u0438<\/a> \u0438 <a href=\"https:\/\/github.com\/coleifer\/peewee\/blob\/master\/bench\/django_bench\/bench.py\">\u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a<\/a><\/li>\n<li>SQLAlchemy: <a href=\"https:\/\/github.com\/coleifer\/peewee\/blob\/master\/bench\/sqlalc_bench\/models.py\">\u043c\u043e\u0434\u0435\u043b\u0438<\/a> \u0438 <a href=\"https:\/\/github.com\/coleifer\/peewee\/blob\/master\/bench\/sqlalc_bench\/bench.py\">\u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a<\/a><\/li>\n<li>Peewee: <a href=\"https:\/\/github.com\/coleifer\/peewee\/blob\/master\/bench\/peewee_bench\/models.py\">\u043c\u043e\u0434\u0435\u043b\u0438<\/a> \u0438 <a href=\"https:\/\/github.com\/coleifer\/peewee\/blob\/master\/bench\/peewee_bench\/bench.py\">\u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/coleifer\/peewee\/blob\/master\/bench\/run_bench.py\">\u0421\u0432\u043e\u0434\u043d\u044b\u0439 \u0431\u0435\u043d\u0447<\/a><\/li>\n<\/ul>\n<p>  \u0425\u043e\u0440\u043e\u0448\u0430\u044f \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u0410\u043b\u0445\u0438\u043c\u0438\u0438, \u043a\u0430\u043a \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0435?    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/207110\/\"> http:\/\/habrahabr.ru\/post\/207110\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/346\/c8c\/f1c\/346c8cf1c996a2065a3f4528f678b725.png\" alt=\"image\"\/><\/p>\n<blockquote><p>\u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0441\u0435\u043c \u0434\u0436\u0430\u043d\u0433\u0438\u0441\u0442\u0430\u043c\/\u0430\u043b\u0445\u0438\u043c\u0438\u0441\u0442\u0430\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0447\u044c\u0441\u044f \u0438 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u043e\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044e \u0432\u0432\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e Peewee \u2013 stand-alone ORM, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u0435\u043d\u0438\u044e \u043b\u044e\u0431\u043e\u043c\u0443 \u043f\u0438\u0442\u043e\u043d\u0449\u0438\u043a\u0443 \u0438, \u0432 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u0444\u043b\u0430\u0441\u043a\u0435\u0440\u0443. \u041f\u0438\u0448\u0443\u0442 \u043e \u043d\u0435\u0439 \u043c\u0430\u043b\u043e, \u0430 \u0437\u0440\u044f. \u0421 Peewee \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u0440\u0443\u0436\u0438\u0442\u044c\u0441\u044f, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c ORM \u043d\u0430 ActiveRecord. \u0427\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u043e \u2013 \u0441 \u043d\u0435\u0439 \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0434\u0440\u0443\u0436\u0438\u0442\u044c \ud83d\ude42 \u041d\u0443, \u043d\u0430\u0447\u043d\u0451\u043c.<\/p><\/blockquote>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\u0421 pip:  <\/p>\n<pre><code class=\"python\">pip install peewee <\/code><\/pre>\n<p>  \u0418\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f:  <\/p>\n<pre><code class=\"python\">git clone https:\/\/github.com\/coleifer\/peewee.git cd peewee python setup.py install <\/code><\/pre>\n<p>  \u0422\u0435\u0441\u0442\u044b:  <\/p>\n<pre><code class=\"python\">python setup.py test <\/code><\/pre>\n<p>  \u0415\u0441\u0442\u044c \u043e\u0431\u0432\u044f\u0437\u043a\u0430 \u0434\u043b\u044f flask:  <\/p>\n<pre><code class=\"python\">pip install flask-peewee <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h2>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438\u043b\u0438 \u00ab\u043f\u043e\u043f\u0430\u0445\u0438\u0432\u0430\u0435\u0442 \u0434\u0436\u0430\u043d\u0433\u043e\u0439\u00bb<\/h2>\n<p>  \u0412\u0435\u0441\u044c \u043d\u0438\u0436\u0435\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0432 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 \u0438\u043b\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u0435.<\/p>\n<pre><code class=\"python\">from peewee import *  db = SqliteDatabase('people.db')  class Person(Model):     name = CharField()     birthday = DateField()     is_relative = BooleanField()      class Meta:         database = db  # \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 'people.db' <\/code><\/pre>\n<p>  \u0422\u0438\u043f\u043e\u0432 \u043f\u043e\u043b\u0435\u0439 \u043c\u043d\u043e\u0433\u043e, <a href=\"http:\/\/peewee.readthedocs.org\/en\/latest\/peewee\/models.html#field-types-table\">\u043d\u0430 \u0432\u0441\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0436\u0438\u0437\u043d\u0438<\/a>. Peewee \u0431\u0435\u0440\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-207110","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/207110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=207110"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/207110\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=207110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=207110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=207110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}