mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2024-11-25 10:13:45 +03:00
Forgot readme
This commit is contained in:
parent
ca341ea997
commit
41e73a5cbb
42
README.rst
42
README.rst
|
@ -189,9 +189,9 @@ Field Types
|
||||||
|
|
||||||
Currently the following field types are supported:
|
Currently the following field types are supported:
|
||||||
|
|
||||||
============= ======== ================= ===================================================
|
=================== ======== ================= ===================================================
|
||||||
Class DB Type Pythonic Type Comments
|
Class DB Type Pythonic Type Comments
|
||||||
============= ======== ================= ===================================================
|
=================== ======== ================= ===================================================
|
||||||
StringField String unicode Encoded as UTF-8 when written to ClickHouse
|
StringField String unicode Encoded as UTF-8 when written to ClickHouse
|
||||||
DateField Date datetime.date Range 1970-01-01 to 2038-01-19
|
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
|
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
|
Enum8Field Enum8 Enum See below
|
||||||
Enum16Field Enum16 Enum See below
|
Enum16Field Enum16 Enum See below
|
||||||
ArrayField Array list 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
|
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])
|
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
|
Table Engines
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user