Forgot readme

This commit is contained in:
M1ha 2017-01-26 15:48:01 +05:00
parent ca341ea997
commit 41e73a5cbb

View File

@ -189,9 +189,9 @@ Field Types
Currently the following field types are supported:
============= ======== ================= ===================================================
=================== ======== ================= ===================================================
Class DB Type Pythonic Type Comments
============= ======== ================= ===================================================
=================== ======== ================= ===================================================
StringField String unicode Encoded as UTF-8 when written to ClickHouse
DateField Date datetime.date Range 1970-01-01 to 2038-01-19
DateTimeField DateTime datetime.datetime Minimal value is 1970-01-01 00:00:00; Always in UTC
@ -208,7 +208,9 @@ Float64Field Float64 float
Enum8Field Enum8 Enum See below
Enum16Field Enum16 Enum See below
ArrayField Array list See below
============= ======== ================= ===================================================
AliasField See below See below See below
MaterializedField See below See below See below
=================== ========== ================= ===================================================
Working with enum fields
************************
@ -249,6 +251,40 @@ You can create array fields containing any data type, for example::
data = SensorData(date=date.today(), temperatures=[25.5, 31.2, 28.7], humidity_levels=[41, 39, 66])
Working with materialized and alias fields
******************************************
ClickHouse provides an opportunity to create MATERIALIZED and ALIAS Fields.
See documentation `here <https://clickhouse.yandex/reference_en.html#Default values>`.
Both field types can't be inserted into database directly.
These field values are ignored, when using database.insert() method.
These fields are set to default values if you use database.select('SELECT * FROM mymodel', model_class=MyModel),
because ClickHouse doesn't return them.
Nevertheless, attribute values (as well as defaults) can be set for model object from python.
Usage::
class Event(models.Model):
created = fields.DateTimeField()
created_date = fields.MaterializedField(fields.DateTimeField(), 'toDate(created)')
name = StringField()
username = AliasField(StringField(), 'name')
engine = engines.MergeTree('created_date', ('created_date', 'created'))
obj = Event(created=datetime.now(), name='MyEvent')
db = Database('my_test_db')
db.insert([obj])
# All values will be retrieved from database
db.select('SELECT created, created_date, username, name FROM $db.event', model_class=Event)
# created_date, username will contain default value
db.select('SELECT * FROM $db.event', model_class=Event)
Table Engines
-------------