beaver-db 0.11.0__py3-none-any.whl → 0.11.1__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.

Potentially problematic release.


This version of beaver-db might be problematic. Click here for more details.

beaver/dicts.py CHANGED
@@ -1,8 +1,9 @@
1
1
  import json
2
2
  import sqlite3
3
- import time # Add this import
3
+ import time # Add this import
4
4
  from typing import Any, Iterator, Tuple
5
5
 
6
+
6
7
  class DictManager:
7
8
  """A wrapper providing a Pythonic interface to a dictionary in the database."""
8
9
 
@@ -52,14 +53,28 @@ class DictManager:
52
53
 
53
54
  if expires_at is not None and time.time() > expires_at:
54
55
  # Expired: delete the key and raise KeyError
55
- cursor.execute("DELETE FROM beaver_dicts WHERE dict_name = ? AND key = ?", (self._name, key))
56
+ cursor.execute(
57
+ "DELETE FROM beaver_dicts WHERE dict_name = ? AND key = ?",
58
+ (self._name, key),
59
+ )
56
60
  self._conn.commit()
57
61
  cursor.close()
58
- raise KeyError(f"Key '{key}' not found in dictionary '{self._name}' (expired)")
62
+ raise KeyError(
63
+ f"Key '{key}' not found in dictionary '{self._name}' (expired)"
64
+ )
59
65
 
60
66
  cursor.close()
61
67
  return json.loads(value)
62
68
 
69
+ def pop(self, key: str, default: Any = None):
70
+ """Deletes an item if it exists and returns its value."""
71
+ try:
72
+ value = self[key]
73
+ del self[key]
74
+ return value
75
+ except KeyError:
76
+ return default
77
+
63
78
  def __delitem__(self, key: str):
64
79
  """Deletes a key-value pair (e.g., `del my_dict[key]`)."""
65
80
  with self._conn:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beaver-db
3
- Version: 0.11.0
3
+ Version: 0.11.1
4
4
  Summary: Fast, embedded, and multi-modal DB based on SQLite for AI-powered applications.
5
5
  Requires-Python: >=3.13
6
6
  Description-Content-Type: text/markdown
@@ -215,7 +215,7 @@ For more in-depth examples, check out the scripts in the `examples/` directory:
215
215
  - [`examples/cache.py`](examples/cache.py): A practical example of using a dictionary with TTL as a cache for API calls.
216
216
  - [`examples/rerank.py`](examples/rerank.py): Shows how to combine results from vector and text search for more refined results.
217
217
  - [`examples/fuzzy.py`](examples/fuzzy.py): Demonstrates fuzzy search capabilities for text search.
218
- - [`examples/stress_vectors.py](examples/stress_vectors.py): A stress test for the vector search functionality.
218
+ - [`examples/stress_vectors.py`](examples/stress_vectors.py): A stress test for the vector search functionality.
219
219
  - [`examples/general_test.py`](examples/general_test.py): A general-purpose test to run all operations randomly which allows testing long-running processes and synchronicity issues.
220
220
 
221
221
  ## Roadmap
@@ -2,12 +2,12 @@ beaver/__init__.py,sha256=-z5Gj6YKMOswpJOOn5Gej8z5i6k3c0Xs00DIYLA-bMI,75
2
2
  beaver/channels.py,sha256=jKL1sVLOe_Q_pP0q1-iceZbPe8FOi0EwqJtOMOe96f4,8675
3
3
  beaver/collections.py,sha256=CXWB8xlyazdJpnhizRkmGmLdN3yt3M2BYNFwr2Ijbas,23896
4
4
  beaver/core.py,sha256=BQsYUA99U2ZT8mXbkBidzVpmTI9KPaF19efASCHCXyM,10569
5
- beaver/dicts.py,sha256=y4z632XKWU29ekP_vdFSOP-MAG9Z8b79kBEHA88gO7E,4463
5
+ beaver/dicts.py,sha256=EFlrSr7oFVt0lfuEX-PsdHnJXKC6cTcgbD7Lh2gID8s,4805
6
6
  beaver/lists.py,sha256=jFlDWwyaYycG0ZFVm58rMChefUaVZhaP1UeQ-hVo3Sg,9082
7
7
  beaver/queues.py,sha256=WKpBzlXr9Hp_rOKEs_Y1Tjyj_hWx6ql1uBRKBV7rw8w,2780
8
8
  beaver/vectors.py,sha256=j7RL2Y_xMAF2tPTi6E2LdJqZerSQXlnEQJOGZkefTsA,18358
9
- beaver_db-0.11.0.dist-info/licenses/LICENSE,sha256=1xrIY5JnMk_QDQzsqmVzPIIyCgZAkWCC8kF2Ddo1UT0,1071
10
- beaver_db-0.11.0.dist-info/METADATA,sha256=QjYGU-36h-e8EhVMmrLq2UKhFUBKFROEHw6ouPVsqE4,12928
11
- beaver_db-0.11.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- beaver_db-0.11.0.dist-info/top_level.txt,sha256=FxA4XnX5Qm5VudEXCduFriqi4dQmDWpQ64d7g69VQKI,7
13
- beaver_db-0.11.0.dist-info/RECORD,,
9
+ beaver_db-0.11.1.dist-info/licenses/LICENSE,sha256=1xrIY5JnMk_QDQzsqmVzPIIyCgZAkWCC8kF2Ddo1UT0,1071
10
+ beaver_db-0.11.1.dist-info/METADATA,sha256=o74KW8nGarOJqStI-YCff1XWj3jV2FB3qEwffyIEJXs,12929
11
+ beaver_db-0.11.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ beaver_db-0.11.1.dist-info/top_level.txt,sha256=FxA4XnX5Qm5VudEXCduFriqi4dQmDWpQ64d7g69VQKI,7
13
+ beaver_db-0.11.1.dist-info/RECORD,,