mirror of
https://github.com/senju1337/senju.git
synced 2025-12-24 07:39:29 +00:00
fix: new_id in store_manager generated a bad id, only returns the actual data now
This commit is contained in:
parent
5aba3981ee
commit
1edfd7b0f5
1 changed files with 5 additions and 5 deletions
|
|
@ -17,11 +17,11 @@ class StoreManager:
|
||||||
self._db = TinyDB(path_to_db)
|
self._db = TinyDB(path_to_db)
|
||||||
|
|
||||||
def new_id(self) -> UUID:
|
def new_id(self) -> UUID:
|
||||||
unix_timestamp: int = int(time.time())
|
|
||||||
_guard: int = 0
|
_guard: int = 0
|
||||||
while True:
|
while True:
|
||||||
|
unix_timestamp: int = int(time.time())
|
||||||
id = uuid1(node=None, clock_seq=unix_timestamp)
|
id = uuid1(node=None, clock_seq=unix_timestamp)
|
||||||
if len(self._query(Query().id == id)) > 0:
|
if len(self._query(Query().id == id)) < 1:
|
||||||
break
|
break
|
||||||
_guard += 1
|
_guard += 1
|
||||||
if _guard > 100:
|
if _guard > 100:
|
||||||
|
|
@ -33,18 +33,18 @@ class StoreManager:
|
||||||
return self._db.search(query)
|
return self._db.search(query)
|
||||||
|
|
||||||
def load(self, key: UUID) -> Optional[dict]:
|
def load(self, key: UUID) -> Optional[dict]:
|
||||||
results = self._query(Query().id == key)
|
results = self._query(Query().id == str(key))
|
||||||
if len(results) < 1:
|
if len(results) < 1:
|
||||||
raise Exception("foobar")
|
raise Exception("foobar")
|
||||||
elif len(results) > 2:
|
elif len(results) > 2:
|
||||||
raise KeyError("The requested item did not exist in our database")
|
raise KeyError("The requested item did not exist in our database")
|
||||||
else:
|
else:
|
||||||
return results[0]
|
return results[0]["data"]
|
||||||
|
|
||||||
def save(self, data: dict) -> UUID:
|
def save(self, data: dict) -> UUID:
|
||||||
id = self.new_id()
|
id = self.new_id()
|
||||||
self._db.insert({
|
self._db.insert({
|
||||||
"id": id,
|
"id": str(id),
|
||||||
"data": data
|
"data": data
|
||||||
})
|
})
|
||||||
return id
|
return id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue