clickhouse-orm 3.1.0__tar.gz → 3.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/PKG-INFO +9 -10
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/README.md +8 -9
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/clickhouse_orm/database.py +6 -38
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/pyproject.toml +1 -1
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/LICENSE +0 -0
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/clickhouse_orm/__init__.py +0 -0
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/clickhouse_orm/engines.py +0 -0
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/clickhouse_orm/fields.py +0 -0
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/clickhouse_orm/funcs.py +0 -0
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/clickhouse_orm/migrations.py +0 -0
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/clickhouse_orm/models.py +0 -0
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/clickhouse_orm/query.py +0 -0
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/clickhouse_orm/system_models.py +0 -0
- {clickhouse_orm-3.1.0 → clickhouse_orm-3.2.0}/clickhouse_orm/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clickhouse_orm
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: A simple ORM for working with the Clickhouse database. Maintainance fork of infi.clickhouse_orm.
|
|
5
5
|
Author-email: Oliver Margetts <oliver.margetts@gmail.com>
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -60,15 +60,14 @@ Now we can collect usage statistics per CPU, and write them to the database:
|
|
|
60
60
|
import psutil, time, datetime
|
|
61
61
|
|
|
62
62
|
psutil.cpu_percent(percpu=True) # first sample should be discarded
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
])
|
|
63
|
+
while True:
|
|
64
|
+
time.sleep(1)
|
|
65
|
+
stats = psutil.cpu_percent(percpu=True)
|
|
66
|
+
timestamp = datetime.datetime.now()
|
|
67
|
+
db.insert([
|
|
68
|
+
CPUStats(timestamp=timestamp, cpu_id=cpu_id, cpu_percent=cpu_percent)
|
|
69
|
+
for cpu_id, cpu_percent in enumerate(stats)
|
|
70
|
+
])
|
|
72
71
|
```
|
|
73
72
|
|
|
74
73
|
Querying the table is easy, using either the query builder or raw SQL:
|
|
@@ -33,15 +33,14 @@ Now we can collect usage statistics per CPU, and write them to the database:
|
|
|
33
33
|
import psutil, time, datetime
|
|
34
34
|
|
|
35
35
|
psutil.cpu_percent(percpu=True) # first sample should be discarded
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
])
|
|
36
|
+
while True:
|
|
37
|
+
time.sleep(1)
|
|
38
|
+
stats = psutil.cpu_percent(percpu=True)
|
|
39
|
+
timestamp = datetime.datetime.now()
|
|
40
|
+
db.insert([
|
|
41
|
+
CPUStats(timestamp=timestamp, cpu_id=cpu_id, cpu_percent=cpu_percent)
|
|
42
|
+
for cpu_id, cpu_percent in enumerate(stats)
|
|
43
|
+
])
|
|
45
44
|
```
|
|
46
45
|
|
|
47
46
|
Querying the table is easy, using either the query builder or raw SQL:
|
|
@@ -3,7 +3,6 @@ from __future__ import annotations
|
|
|
3
3
|
import datetime
|
|
4
4
|
import logging
|
|
5
5
|
import re
|
|
6
|
-
from contextlib import contextmanager
|
|
7
6
|
from math import ceil
|
|
8
7
|
from string import Template
|
|
9
8
|
|
|
@@ -106,7 +105,6 @@ class Database:
|
|
|
106
105
|
timeout=60,
|
|
107
106
|
verify_ssl_cert=True,
|
|
108
107
|
log_statements=False,
|
|
109
|
-
session=None,
|
|
110
108
|
):
|
|
111
109
|
"""
|
|
112
110
|
Initializes a database instance. Unless it's readonly, the database will be
|
|
@@ -124,13 +122,12 @@ class Database:
|
|
|
124
122
|
"""
|
|
125
123
|
self.db_name = db_name
|
|
126
124
|
self.db_url = db_url or self._default_url
|
|
127
|
-
self.readonly =
|
|
125
|
+
self.readonly = False
|
|
128
126
|
self.timeout = timeout
|
|
129
|
-
self.
|
|
130
|
-
self.request_session =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
self.request_session = requests.Session()
|
|
128
|
+
self.request_session.verify = verify_ssl_cert
|
|
129
|
+
if username:
|
|
130
|
+
self.request_session.auth = (username, password or "")
|
|
134
131
|
self.log_statements = log_statements
|
|
135
132
|
self.settings = {}
|
|
136
133
|
self.db_exists = False # this is required before running _is_existing_database
|
|
@@ -150,22 +147,6 @@ class Database:
|
|
|
150
147
|
# Version 19.0 and above support LowCardinality
|
|
151
148
|
self.has_low_cardinality_support = self.server_version >= (19, 0)
|
|
152
149
|
|
|
153
|
-
@contextmanager
|
|
154
|
-
def session(self):
|
|
155
|
-
"""Contextmanager to use a persistent session for requests.
|
|
156
|
-
|
|
157
|
-
This can be quicker if making lots of small queries.
|
|
158
|
-
"""
|
|
159
|
-
with requests.Session() as session:
|
|
160
|
-
session.verify = self.verify_ssl_cert
|
|
161
|
-
if self.__username:
|
|
162
|
-
session.auth = (self.__username, self.__password or "")
|
|
163
|
-
self.request_session = session
|
|
164
|
-
try:
|
|
165
|
-
yield self
|
|
166
|
-
finally:
|
|
167
|
-
self.request_session = None
|
|
168
|
-
|
|
169
150
|
def create_database(self):
|
|
170
151
|
"""
|
|
171
152
|
Creates the database on the ClickHouse server if it does not already exist.
|
|
@@ -417,20 +398,7 @@ class Database:
|
|
|
417
398
|
if self.log_statements:
|
|
418
399
|
logger.info(data)
|
|
419
400
|
params = self._build_params(settings)
|
|
420
|
-
|
|
421
|
-
if self.request_session:
|
|
422
|
-
r = self.request_session.post(self.db_url, params=params, data=data, stream=stream, timeout=self.timeout)
|
|
423
|
-
else:
|
|
424
|
-
r = requests.post(
|
|
425
|
-
self.db_url,
|
|
426
|
-
params=params,
|
|
427
|
-
data=data,
|
|
428
|
-
stream=stream,
|
|
429
|
-
timeout=self.timeout,
|
|
430
|
-
verify=self.verify_ssl_cert,
|
|
431
|
-
auth=(self.__username, self.__password or "") if self.__username else None,
|
|
432
|
-
)
|
|
433
|
-
|
|
401
|
+
r = self.request_session.post(self.db_url, params=params, data=data, stream=stream, timeout=self.timeout)
|
|
434
402
|
if r.status_code != 200:
|
|
435
403
|
raise ServerError(r.text)
|
|
436
404
|
return r
|
|
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "clickhouse_orm"
|
|
7
|
-
version = "3.
|
|
7
|
+
version = "3.2.0"
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
description = "A simple ORM for working with the Clickhouse database. Maintainance fork of infi.clickhouse_orm."
|
|
10
10
|
authors = [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|