bear-utils 0.8.22__py3-none-any.whl → 0.8.23__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.
@@ -32,42 +32,35 @@ class DatabaseManager:
32
32
  raise ValueError("Base class is not set, failed to set base.")
33
33
  return cls._base
34
34
 
35
- def __init__(self, db_url: str | Path | None = None):
35
+ def __init__(self, db_url: str | Path | None = None, default_schema: str = "sqlite:///"):
36
36
  if db_url is None or db_url == "":
37
37
  raise ValueError("Database URL cannot be None or empty.")
38
- if isinstance(db_url, str) and not db_url.startswith("sqlite://"):
39
- db_url = f"sqlite:///{db_url}"
38
+ if isinstance(db_url, str) and not db_url.startswith(default_schema):
39
+ db_url = f"{default_schema}{db_url}"
40
40
  self.db_url: str = str(db_url)
41
41
  self.engine: Engine = create_engine(self.db_url, echo=False)
42
42
  base: DeclarativeMeta = DatabaseManager.get_base()
43
43
  self.metadata: MetaData = base.metadata
44
- self.SessionFactory = sessionmaker(bind=self.engine)
45
- self.session = scoped_session(self.SessionFactory)
44
+ self.SessionFactory: sessionmaker[Session] = sessionmaker(bind=self.engine)
45
+ self.session: scoped_session[Session] = scoped_session(self.SessionFactory)
46
46
  atexit.register(self.close_all)
47
47
  self.create_tables()
48
48
 
49
49
  def get_all_records(self, table_obj: type[TableType]) -> list[TableType]:
50
50
  """Get all records from a table."""
51
- with self.open_session() as session:
52
- return session.query(table_obj).all()
51
+ return self.session().query(table_obj).all()
53
52
 
54
53
  def count_records(self, table_obj: type[TableType]) -> int:
55
54
  """Count the number of records in a table."""
56
- with self.open_session() as session:
57
- count: int = session.query(table_obj).count()
58
- return count
55
+ return self.session().query(table_obj).count()
59
56
 
60
57
  def get_records_by_var(self, table_obj: type[TableType], variable: str, value: str) -> list[TableType]:
61
58
  """Get records from a table by a specific variable."""
62
- with self.open_session() as session:
63
- records: list[TableType] = session.query(table_obj).filter(getattr(table_obj, variable) == value).all()
64
- return records
59
+ return self.session().query(table_obj).filter(getattr(table_obj, variable) == value).all()
65
60
 
66
61
  def count_records_by_var(self, table_obj: type[TableType], variable: str, value: str) -> int:
67
62
  """Count the number of records in a table by a specific variable."""
68
- with self.open_session() as session:
69
- count: int = session.query(table_obj).filter(getattr(table_obj, variable) == value).count()
70
- return count
63
+ return self.session().query(table_obj).filter(getattr(table_obj, variable) == value).count()
71
64
 
72
65
  @contextmanager
73
66
  def open_session(self) -> Generator[Session, Any]:
@@ -14,13 +14,14 @@ from bear_utils.extras._async_helpers import AsyncResponseModel, create_async_ta
14
14
  # Pydantic will yell if we put this into a TYPE_CHECKING block.
15
15
  from bear_utils.logger_manager import AsyncLoggerProtocol, LoggerProtocol # noqa: TC001
16
16
 
17
- SUCCESS: list[str] = ["name", "success"]
18
- FAILURE: list[str] = ["name"]
19
-
20
17
  if TYPE_CHECKING:
21
18
  from collections.abc import Callable
22
19
 
23
20
 
21
+ SUCCESS: list[str] = ["name", "success", "number_of_tasks"]
22
+ FAILURE: list[str] = ["name", "number_of_tasks"]
23
+
24
+
24
25
  class FunctionResponse(BaseModel):
25
26
  """A class to represent the response of a function call, including success status, content, and error messages."""
26
27
 
@@ -337,10 +338,8 @@ class FunctionResponse(BaseModel):
337
338
  content = []
338
339
  if not isinstance(error, (list | str)):
339
340
  error = []
340
-
341
341
  if not content and not error:
342
342
  return
343
-
344
343
  res: AsyncResponseModel = create_async_task(
345
344
  _log_messages,
346
345
  content=content,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bear-utils
3
- Version: 0.8.22
3
+ Version: 0.8.23
4
4
  Summary: Various utilities for Bear programmers, including a rich logging utility, a disk cache, and a SQLite database wrapper amongst other things.
5
5
  Author-email: chaz <bright.lid5647@fastmail.com>
6
6
  Requires-Python: >=3.12
@@ -24,7 +24,7 @@ Provides-Extra: gui
24
24
  Requires-Dist: pyqt6>=6.9.0; extra == 'gui'
25
25
  Description-Content-Type: text/markdown
26
26
 
27
- # Bear Utils v# Bear Utils v0.8.22
27
+ # Bear Utils v# Bear Utils v0.8.23
28
28
 
29
29
  Personal set of tools and utilities for Python projects, focusing on modularity and ease of use. This library includes components for caching, database management, logging, time handling, file operations, CLI prompts, image processing, clipboard interaction, gradient utilities, event systems, and async helpers.
30
30
 
@@ -28,7 +28,7 @@ bear_utils/constants/date_related.py,sha256=vwgPPGamVJ8p12iRFu3IzTksmGfhqYULwrk-
28
28
  bear_utils/constants/server.py,sha256=1gWA3h1HH12uk5nqX3r5EFkffPKVDTo3he51teHSDbk,271
29
29
  bear_utils/constants/time_related.py,sha256=Mykb27THqC-K0HFrbbrdkTNJUKhzBEOfmPJ0rx2-L6E,705
30
30
  bear_utils/database/__init__.py,sha256=dS_HHJKESpsI6BFDLVx055o0GCJV9CMYOQVuHs7EfgY,192
31
- bear_utils/database/_db_manager.py,sha256=rW4yq6arMF7UbgKrA7C2Wi37O-byqzae39tIZixfRZk,3977
31
+ bear_utils/database/_db_manager.py,sha256=bbg5zG06DcOvd37oafLIqc480BwF9ZW9qWF3ldZHR8o,3805
32
32
  bear_utils/events/__init__.py,sha256=EFqmuzhaEYK9kjkGlrM7bjdjPwFEDbKn6RjJKfIBEJY,414
33
33
  bear_utils/events/events_class.py,sha256=vPDjWrbut8L3TFn7byyYFZpWYM5ADIqtW2Aeh-qtKfQ,1632
34
34
  bear_utils/events/events_module.py,sha256=DkQsDZ5WzM1MH1Msg7mRny40a17Jl31CXbpw4-pICxc,2349
@@ -37,7 +37,7 @@ bear_utils/extras/_async_helpers.py,sha256=4buULZZkR0n2z13Q8_FK59dMchj0Mup03YBaq
37
37
  bear_utils/extras/_tools.py,sha256=-rOH_-0pRd7_-o_l2QqByYBB2yhbXcTC8fuQf4Sx-eg,7671
38
38
  bear_utils/extras/platform_utils.py,sha256=Ai7ow7S-_cKb5zFwFh8dkC8xmbMJFy-0_-w3NCERdEw,1362
39
39
  bear_utils/extras/responses/__init__.py,sha256=XbE4VKemrKRwx9E5jqy__OiM_AAjA58ebnqQ2hytnT0,225
40
- bear_utils/extras/responses/function_response.py,sha256=VFhYGoSXbqdkgeBWYdmHcHcJ2Z0BFg_Y8EmdkaF442Y,16220
40
+ bear_utils/extras/responses/function_response.py,sha256=aGUhxfliaqE2tXKGtVPDeOy5JJRjHN5M9gRgI1IsopY,16257
41
41
  bear_utils/extras/wrappers/__init__.py,sha256=crh4sKOLvuhNMVX5bJYjCFWtXtH7G47UgNPOHq3HXTk,43
42
42
  bear_utils/extras/wrappers/add_methods.py,sha256=z2XZG2ZoYOB1MaGiLli4NRyyTeRgBy7tuYsiy8mTa9s,4422
43
43
  bear_utils/files/__init__.py,sha256=mIdnFSXoDE64ElM43bN2m6KuafURnN82ki0pdqN8q2o,201
@@ -86,6 +86,6 @@ bear_utils/monitoring/__init__.py,sha256=9DKNIWTp_voLnaWgiP-wJ-o_N0hYixo-MzjUmg8
86
86
  bear_utils/monitoring/_common.py,sha256=LYQFxgTP9fk0cH71IQTuGwBYYPWCqHP_mMRNecoD76M,657
87
87
  bear_utils/monitoring/host_monitor.py,sha256=e0TYRJw9iDj5Ga6y3ck1TBFEeH42Cax5mQYaNU8yams,13241
88
88
  bear_utils/time/__init__.py,sha256=VctjJG17SyEHAFXytI1sZrOrq7zm3hVenIDOJFdaMN0,1424
89
- bear_utils-0.8.22.dist-info/METADATA,sha256=bI6HOJaPlDs8ml0B_n-if7qmczI67TKOllT-6JkXXhY,8763
90
- bear_utils-0.8.22.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
91
- bear_utils-0.8.22.dist-info/RECORD,,
89
+ bear_utils-0.8.23.dist-info/METADATA,sha256=paN99eKZqMAyoDD6z25V7EFeHK1IcDaAvRwXBQPjyJ8,8763
90
+ bear_utils-0.8.23.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
91
+ bear_utils-0.8.23.dist-info/RECORD,,