mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2024-11-25 02:03:46 +03:00
Forgot readme
This commit is contained in:
parent
ca341ea997
commit
41e73a5cbb
76
README.rst
76
README.rst
|
@ -189,26 +189,28 @@ 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
|
||||
Int8Field Int8 int Range -128 to 127
|
||||
Int16Field Int16 int Range -32768 to 32767
|
||||
Int32Field Int32 int Range -2147483648 to 2147483647
|
||||
Int64Field Int64 int/long Range -9223372036854775808 to 9223372036854775807
|
||||
UInt8Field UInt8 int Range 0 to 255
|
||||
UInt16Field UInt16 int Range 0 to 65535
|
||||
UInt32Field UInt32 int Range 0 to 4294967295
|
||||
UInt64Field UInt64 int/long Range 0 to 18446744073709551615
|
||||
Float32Field Float32 float
|
||||
Float64Field Float64 float
|
||||
Enum8Field Enum8 Enum See below
|
||||
Enum16Field Enum16 Enum See below
|
||||
ArrayField Array list See below
|
||||
============= ======== ================= ===================================================
|
||||
=================== ======== ================= ===================================================
|
||||
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
|
||||
Int8Field Int8 int Range -128 to 127
|
||||
Int16Field Int16 int Range -32768 to 32767
|
||||
Int32Field Int32 int Range -2147483648 to 2147483647
|
||||
Int64Field Int64 int/long Range -9223372036854775808 to 9223372036854775807
|
||||
UInt8Field UInt8 int Range 0 to 255
|
||||
UInt16Field UInt16 int Range 0 to 65535
|
||||
UInt32Field UInt32 int Range 0 to 4294967295
|
||||
UInt64Field UInt64 int/long Range 0 to 18446744073709551615
|
||||
Float32Field Float32 float
|
||||
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
|
||||
-------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user