clickhouse-orm 3.1.0__py2.py3-none-any.whl → 3.2.0__py2.py3-none-any.whl

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.
@@ -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 = self.connection_readonly = False
125
+ self.readonly = False
128
126
  self.timeout = timeout
129
- self.verify_ssl_cert = verify_ssl_cert
130
- self.request_session = None
131
- self.__username = username
132
- self.__password = password
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clickhouse_orm
3
- Version: 3.1.0
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
- with db.session(): # use a requests session for efficiency
64
- while True:
65
- time.sleep(1)
66
- stats = psutil.cpu_percent(percpu=True)
67
- timestamp = datetime.datetime.now()
68
- db.insert([
69
- CPUStats(timestamp=timestamp, cpu_id=cpu_id, cpu_percent=cpu_percent)
70
- for cpu_id, cpu_percent in enumerate(stats)
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:
@@ -1,5 +1,5 @@
1
1
  clickhouse_orm/__init__.py,sha256=ksYW9scTnD6VVCj8Rzv7B41VkvHDn-JWpyIh1Tjserc,478
2
- clickhouse_orm/database.py,sha256=JdQhviLvK9sABb7WRrAqMaxgA1nJzuDznfH6VuGRZtg,18804
2
+ clickhouse_orm/database.py,sha256=v4I2NKxkwF6Bm2hJAM6vCg-n9ss10THA9AIoxuHnU1g,17828
3
3
  clickhouse_orm/engines.py,sha256=AV80AmLRM3hlEXj3o6GPjjKDPk8YyRdTEns9SZCppA0,11166
4
4
  clickhouse_orm/fields.py,sha256=Wfm3NkctRhnaw2bc9KqlncV04FCvBEb_74ky9ZF2aq4,24039
5
5
  clickhouse_orm/funcs.py,sha256=8S1kdwCjIJ45imvA2XkxHjDhGOYlNg4aS1vMU2CQ224,42108
@@ -8,7 +8,7 @@ clickhouse_orm/models.py,sha256=pUkLBClnfyXPg5xuHTpobNhFqHtKuHlXTNwWv5PnV_U,2308
8
8
  clickhouse_orm/query.py,sha256=3-v1Z5G1xO1c8ywVhmZiz0tpAvBmH19xzeyxVpxc6uU,24103
9
9
  clickhouse_orm/system_models.py,sha256=pU-Pvq69GH6QD4iKIrSRxw3Q6n-qlgQzGLqpYwAF12U,6447
10
10
  clickhouse_orm/utils.py,sha256=2fEmTrBSDNpPzbbnUOZeCQ2NX5httkOKrJKzgdTezH4,5179
11
- clickhouse_orm-3.1.0.dist-info/licenses/LICENSE,sha256=MP0KDNu_tFQJrr35YkSFnwwp2F8p2a7Q1Mi2lOs8FLw,1503
12
- clickhouse_orm-3.1.0.dist-info/WHEEL,sha256=Dyt6SBfaasWElUrURkknVFAZDHSTwxg3PaTza7RSbkY,100
13
- clickhouse_orm-3.1.0.dist-info/METADATA,sha256=2Pa9QHoZsuXV_9tEoXVtZgwxk6Xcr_XZmHggSjhzURE,3492
14
- clickhouse_orm-3.1.0.dist-info/RECORD,,
11
+ clickhouse_orm-3.2.0.dist-info/licenses/LICENSE,sha256=MP0KDNu_tFQJrr35YkSFnwwp2F8p2a7Q1Mi2lOs8FLw,1503
12
+ clickhouse_orm-3.2.0.dist-info/WHEEL,sha256=Dyt6SBfaasWElUrURkknVFAZDHSTwxg3PaTza7RSbkY,100
13
+ clickhouse_orm-3.2.0.dist-info/METADATA,sha256=jtHZZdZ3ORpb8OrNZQi41B4cVd3E36hNO8MhUnHW40o,3400
14
+ clickhouse_orm-3.2.0.dist-info/RECORD,,