pysonDB / pysonDB

A Simple , ☁️ Lightweight , 💪 Efficent JSON based database for 🐍 Python. PysonDB-V2 has been released ⬇️
https://github.com/pysonDB/pysonDB-v2
MIT License
391 stars 32 forks source link

Id Does not Exist in DB error when ID exists in DB #103

Open isConic opened 1 year ago

isConic commented 1 year ago

# Start DB
db =db.getDb("users.json")

# Add new Entry
db.add( dict(user_name = "abc", phone = 123))

# Retrieve Entry  to get DB id
user = db.getBy({'phone': "123"}) 
_id = user["id"]   
print(id) # returns 325759948692082048  

# Attempt to delete by ID
db.deleteById(id)  

# Error:
# pysondb.errors.db_errors.IdNotFoundError: Id '325759948692082048' does not exist in the JSON db  
isConic commented 1 year ago

The ID DOES exist when I do db.getAll()

isConic commented 1 year ago

Identified the issue I think

https://github.com/pysonDB/pysonDB/blob/4fad660bfb2465b8524fbe314d03b84b30abcb7c/pysondb/db.py#L186

You should be casting the first value too. Otherwise you're comparing an int to a string.

Python interpreter says:
image

isConic commented 1 year ago

Also here: https://github.com/pysonDB/pysonDB/blob/4fad660bfb2465b8524fbe314d03b84b30abcb7c/pysondb/db.py#L263