mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2025-08-02 11:10:11 +03:00
Merge 5028769c3b
into 45a9200ff6
This commit is contained in:
commit
7a16a0bc68
|
@ -15,6 +15,6 @@ while True:
|
|||
timestamp = datetime.datetime.now()
|
||||
print(timestamp)
|
||||
db.insert([
|
||||
CPUStats(timestamp=timestamp, cpu_id=cpu_id, cpu_percent=cpu_percent)
|
||||
CPUStats(timestamp=timestamp, cpu_id=cpu_id, cpu_percent=cpu_percent, working_status=True)
|
||||
for cpu_id, cpu_percent in enumerate(stats)
|
||||
])
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from infi.clickhouse_orm import Model, DateTimeField, UInt16Field, Float32Field, Memory
|
||||
from infi.clickhouse_orm import Model, DateTimeField, UInt16Field, Float32Field, Memory, BooleanField
|
||||
|
||||
|
||||
class CPUStats(Model):
|
||||
|
@ -6,6 +6,7 @@ class CPUStats(Model):
|
|||
timestamp = DateTimeField()
|
||||
cpu_id = UInt16Field()
|
||||
cpu_percent = Float32Field()
|
||||
working_status = BooleanField()
|
||||
|
||||
engine = Memory()
|
||||
|
||||
|
|
|
@ -162,6 +162,24 @@ class FixedStringField(StringField):
|
|||
if len(value) > self._length:
|
||||
raise ValueError('Value of %d bytes is too long for FixedStringField(%d)' % (len(value), self._length))
|
||||
|
||||
class BooleanField(Field):
|
||||
# The ClickHouse column type to use
|
||||
db_type = 'Bool'
|
||||
# The default value
|
||||
class_default = False
|
||||
|
||||
def to_python(self, value, timezone_in_use):
|
||||
# Convert valid values to bool
|
||||
if value in (1, '1', True):
|
||||
return True
|
||||
elif value in (0, '0', False):
|
||||
return False
|
||||
else:
|
||||
raise ValueError('Invalid value for BooleanField: %r' % value)
|
||||
|
||||
def to_db_string(self, value, quote=True):
|
||||
# The value was already converted by to_python, so it's a bool
|
||||
return '1' if value else '0'
|
||||
|
||||
class DateField(Field):
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user