cloudoll 3.0.4__tar.gz → 3.0.5__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.
Files changed (45) hide show
  1. {cloudoll-3.0.4 → cloudoll-3.0.5}/PKG-INFO +1 -1
  2. cloudoll-3.0.5/cloudoll/__init__.py +1 -0
  3. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/orm/field.py +19 -5
  4. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/orm/model.py +1 -1
  5. cloudoll-3.0.5/cloudoll/orm/test_sql.py +89 -0
  6. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/web/core.py +7 -2
  7. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll.egg-info/PKG-INFO +1 -1
  8. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll.egg-info/SOURCES.txt +1 -0
  9. {cloudoll-3.0.4 → cloudoll-3.0.5}/pyproject.toml +1 -1
  10. cloudoll-3.0.4/cloudoll/__init__.py +0 -1
  11. {cloudoll-3.0.4 → cloudoll-3.0.5}/LICENSE +0 -0
  12. {cloudoll-3.0.4 → cloudoll-3.0.5}/README.md +0 -0
  13. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/__main__.py +0 -0
  14. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/cli.py +0 -0
  15. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/clitool/__init__.py +0 -0
  16. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/clitool/cli_main.py +0 -0
  17. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/clitool/m2d.py +0 -0
  18. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/clitool/process.py +0 -0
  19. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/clitool/spinner.py +0 -0
  20. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/clitool/watch.py +0 -0
  21. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/logging/__init__.py +0 -0
  22. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/mail/__init__.py +0 -0
  23. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/mail/smtp.py +0 -0
  24. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/orm/__init__.py +0 -0
  25. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/orm/base.py +0 -0
  26. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/orm/err.py +0 -0
  27. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/orm/mysql.py +0 -0
  28. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/orm/parse.py +0 -0
  29. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/orm/postgres.py +0 -0
  30. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/template/__init__.py +0 -0
  31. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/utils/__init__.py +0 -0
  32. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/utils/common.py +0 -0
  33. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/utils/snowflake.py +0 -0
  34. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/web/__init__.py +0 -0
  35. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/web/exception.py +0 -0
  36. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/web/html.py +0 -0
  37. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/web/jwt.py +0 -0
  38. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/web/requests.py +0 -0
  39. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll/web/settings.py +0 -0
  40. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll.egg-info/dependency_links.txt +0 -0
  41. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll.egg-info/entry_points.txt +0 -0
  42. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll.egg-info/requires.txt +0 -0
  43. {cloudoll-3.0.4 → cloudoll-3.0.5}/cloudoll.egg-info/top_level.txt +0 -0
  44. {cloudoll-3.0.4 → cloudoll-3.0.5}/setup.cfg +0 -0
  45. {cloudoll-3.0.4 → cloudoll-3.0.5}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cloudoll
3
- Version: 3.0.4
3
+ Version: 3.0.5
4
4
  Summary: Assist in quickly creating distributable microservices based on aiohttp, with a focus on simplicity and ease of use.
5
5
  Home-page: https://github.com/smallerqiu/cloudoll-py
6
6
  Author: Qiu
@@ -0,0 +1 @@
1
+ __version__ = "3.0.5"
@@ -141,7 +141,7 @@ class FieldBase(object):
141
141
 
142
142
  def max_when(self, *arg):
143
143
  """
144
- input: max_when(A.field > 10 ,A.field) \n
144
+ input: max_when(A.field > 10 ,A.field) \n
145
145
  output: max(case when A.field > 10 then A.field end)
146
146
  """
147
147
  return Function(self, OP.MAX_WHEN, arg)
@@ -151,7 +151,7 @@ class FieldBase(object):
151
151
 
152
152
  def min_when(self, *arg):
153
153
  """
154
- input: min_when(A.field > 10 ,A.field) \n
154
+ input: min_when(A.field > 10 ,A.field) \n
155
155
  output: min(case when A.field > 10 then A.field end)
156
156
  """
157
157
  return Function(self, OP.MIN_WHEN, arg)
@@ -288,14 +288,14 @@ class ExpList(FieldBase):
288
288
  def deconstruct(args):
289
289
  f = args[0] if len(args) > 0 else None
290
290
  v1 = args[1] if len(args) > 1 else 1
291
- v2 = args[2] if len(args) > 2 and args[2] is not None else 'NULL'
291
+ v2 = args[2] if len(args) > 2 and args[2] is not None else "NULL"
292
292
  c = None
293
293
  v = None
294
294
  if isinstance(f, FieldBase):
295
295
  c = f"{f.lhs.full_name} {f.op} ?"
296
296
  v = f.rhs
297
297
  if isinstance(v1, FieldBase):
298
- v1 = v1.name
298
+ v1 = v1.full_name
299
299
  return c, v, v1, v2
300
300
 
301
301
 
@@ -355,32 +355,46 @@ class Function(FieldBase):
355
355
  return f"json_contains({col_name},json_object({key},?))", [_v]
356
356
  elif op == OP.JSON_CONTAINS_ARRAY:
357
357
  if is_field:
358
- return f"json_contains({col_name},json_array({self.rpt.full_name}))", None
358
+ return (
359
+ f"json_contains({col_name},json_array({self.rpt.full_name}))",
360
+ None,
361
+ )
359
362
  return f"json_contains({col_name},json_array(?))", [self.rpt]
360
363
  elif op == OP.COUNT:
361
364
  return f"COUNT({col_name})", None
362
365
  elif op == OP.COUNT_WHEN:
363
366
  c, v, v1, v2 = deconstruct(self.rpt)
367
+ if v2 == "NULL":
368
+ return f"COUNT(CASE WHEN {c} THEN {v1} END)", [v]
364
369
  return f"COUNT(CASE WHEN {c} THEN {v1} ELSE {v2} END)", [v]
365
370
  elif op == OP.SUM:
366
371
  return f"SUM({col_name})", None
367
372
  elif op == OP.SUM_WHEN:
368
373
  c, v, v1, v2 = deconstruct(self.rpt)
374
+ if v2 == "NULL":
375
+ return f"SUM(CASE WHEN {c} THEN {v1} END)", [v]
369
376
  return f"SUM(CASE WHEN {c} THEN {v1} ELSE {v2} END)", [v]
370
377
  elif op == OP.AVG:
371
378
  return f"AVG({col_name})", None
372
379
  elif op == OP.AVG_WHEN:
373
380
  c, v, v1, v2 = deconstruct(self.rpt)
381
+ print("avg", v2)
382
+ if v2 == "NULL":
383
+ return f"AVG(CASE WHEN {c} THEN {v1} END)", [v]
374
384
  return f"AVG(CASE WHEN {c} THEN {v1} ELSE {v2} END)", [v]
375
385
  elif op == OP.MAX:
376
386
  return f"MAX({col_name})", None
377
387
  elif op == OP.MAX_WHEN:
378
388
  c, v, v1, v2 = deconstruct(self.rpt)
389
+ if v2 == "NULL":
390
+ return f"MAX(CASE WHEN {c} THEN {v1} END)", [v]
379
391
  return f"MAX(CASE WHEN {c} THEN {v1} ELSE {v2} END)", [v]
380
392
  elif op == OP.MIN:
381
393
  return f"MIN({col_name})", None
382
394
  elif op == OP.MIN_WHEN:
383
395
  c, v, v1, v2 = deconstruct(self.rpt)
396
+ if v2 == "NULL":
397
+ return f"MIN(CASE WHEN {c} THEN {v1} END)", [v]
384
398
  return f"MIN(CASE WHEN {c} THEN {v1} ELSE {v2} END)", [v]
385
399
  elif op == OP.GROUP_CONCAT:
386
400
  arg = self.rpt
@@ -339,7 +339,7 @@ class Model(metaclass=ModelMetaclass):
339
339
  return self
340
340
 
341
341
  def test(self):
342
- return self._sql()
342
+ return self._sql(), self.__params__
343
343
 
344
344
  async def one(self):
345
345
  self.limit(1)
@@ -0,0 +1,89 @@
1
+ from model import models, Model
2
+
3
+
4
+ class A(Model):
5
+
6
+ __table__ = "a"
7
+
8
+ id = models.BigIntegerField(
9
+ primary_key=True, max_length=64, not_null=True, comment="ID"
10
+ )
11
+ source = models.IntegerField(max_length=16, not_null=True, comment="状态")
12
+ param = models.TextField(not_null=True)
13
+ gmt_create = models.TimestampField(
14
+ max_length=3, default="CURRENT_TIMESTAMP(3)", not_null=True, comment="创建时间"
15
+ )
16
+
17
+
18
+ class B(Model):
19
+
20
+ __table__ = "b"
21
+
22
+ id = models.BigIntegerField(primary_key=True, max_length=64, not_null=True)
23
+ task_id = models.BigIntegerField(max_length=64, default="0", not_null=True)
24
+ employee_id = models.BigIntegerField(max_length=64, default="0", not_null=True)
25
+ agency_id = models.BigIntegerField(max_length=64, default="0", not_null=True)
26
+ proxy_str = models.VarCharField(max_length=512, default="", not_null=True)
27
+ proxy_scheme = models.VarCharField(max_length=16, default="", not_null=True)
28
+ proxy_ip = models.VarCharField(max_length=64, default="", not_null=True)
29
+ proxy_region = models.VarCharField(max_length=32, default="", not_null=True)
30
+ proxy_order_no = models.VarCharField(max_length=64, default="", not_null=True)
31
+ proxy_merchant = models.VarCharField(max_length=32, default="", not_null=True)
32
+ proxy_subnet = models.VarCharField(max_length=128, default="", not_null=True)
33
+ channel_type = models.IntegerField(max_length=16, default="0", not_null=True)
34
+ channel = models.VarCharField(max_length=512, default="", not_null=True)
35
+ type = models.IntegerField(max_length=16, default="0", not_null=True)
36
+ url = models.VarCharField(max_length=512, default="", not_null=True)
37
+ gmt_create = models.TimestampField(
38
+ max_length=3, default="CURRENT_TIMESTAMP(3)", not_null=True
39
+ )
40
+ timeout = models.IntegerField(max_length=32, default="0", not_null=True)
41
+
42
+
43
+ class C(Model):
44
+
45
+ __table__ = "i_network_speed_result"
46
+
47
+ id = models.BigIntegerField(primary_key=True, max_length=64, not_null=True)
48
+ pack_id = models.BigIntegerField(max_length=64, default="0", not_null=True)
49
+ delay = models.IntegerField(max_length=32, default="-1", not_null=True)
50
+ finish_load = models.IntegerField(max_length=32, default="-1", not_null=True)
51
+ ip = models.VarCharField(max_length=64, default="", not_null=True)
52
+ region = models.VarCharField(max_length=32, default="", not_null=True)
53
+ gmt_create = models.TimestampField(
54
+ max_length=3, default="CURRENT_TIMESTAMP(3)", not_null=True
55
+ )
56
+ speed = models.NumericField(
57
+ max_length=12, scale_length=2, default="0", not_null=True
58
+ )
59
+ packet_loss_rate = models.NumericField(
60
+ max_length=12, scale_length=2, default="0", not_null=True
61
+ )
62
+ is_failed = models.BooleanField(default="true", not_null=True)
63
+ is_timeout = models.BooleanField(default="true", not_null=True)
64
+
65
+
66
+ if __name__ == "__main__":
67
+ sql, arg = (
68
+ B.use()
69
+ .select(
70
+ B.proxy_order_no.As("host_no"),
71
+ B.proxy_order_no.count().As("total_count"),
72
+ C.region.As("region"),
73
+ C.is_failed.avg_when(C.is_failed == False, C.finish_load).As("avg_val"),
74
+ C.is_failed.min_when(C.is_failed == False, C.finish_load).As("min_val"),
75
+ C.is_failed.max_when(C.is_failed == False, C.finish_load).As("max_val"),
76
+ C.is_failed.sum_when(C.is_failed == False, 1, 0).As("success_count"),
77
+ C.is_failed.sum_when(C.is_failed == True, 1, 0).As("failure_count"),
78
+ )
79
+ .join(C, C.pack_id == B.id)
80
+ .where(
81
+ B.channel_type == 1,
82
+ B.type == int(1),
83
+ B.proxy_order_no.In(tuple(["aa"])),
84
+ )
85
+ .group_by(B.proxy_order_no, C.region)
86
+ .test()
87
+ )
88
+ # sql = B()._exchange_sql(sql)
89
+ print(sql, arg)
@@ -282,8 +282,13 @@ class Application(object):
282
282
  async def _init_database(self, apps):
283
283
  conf_db = self.config.get("database")
284
284
  if conf_db:
285
- for db_key in conf_db:
286
- apps.db[db_key] = await create_engine(**conf_db[db_key])
285
+ # for db_key in conf_db:
286
+ # apps.db[db_key] = await create_engine(**conf_db[db_key])
287
+
288
+ tasks = [create_engine(**conf_db[db_key]) for db_key in conf_db]
289
+ engines = await asyncio.gather(*tasks)
290
+ for db_key, engine in zip(conf_db.keys(), engines):
291
+ apps.db[db_key] = engine
287
292
 
288
293
  async def _init_session(self, apps):
289
294
  config = self.config or {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cloudoll
3
- Version: 3.0.4
3
+ Version: 3.0.5
4
4
  Summary: Assist in quickly creating distributable microservices based on aiohttp, with a focus on simplicity and ease of use.
5
5
  Home-page: https://github.com/smallerqiu/cloudoll-py
6
6
  Author: Qiu
@@ -29,6 +29,7 @@ cloudoll/orm/model.py
29
29
  cloudoll/orm/mysql.py
30
30
  cloudoll/orm/parse.py
31
31
  cloudoll/orm/postgres.py
32
+ cloudoll/orm/test_sql.py
32
33
  cloudoll/template/__init__.py
33
34
  cloudoll/utils/__init__.py
34
35
  cloudoll/utils/common.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cloudoll"
7
- version = "3.0.4"
7
+ version = "3.0.5"
8
8
  description = "Assist in quickly creating distributable microservices based on aiohttp, with a focus on simplicity and ease of use."
9
9
  authors = [
10
10
  {name = "Qiu", email = "smallerqiu@gmail.com"},
@@ -1 +0,0 @@
1
- __version__ = "3.0.4"
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
File without changes
File without changes
File without changes