Anna-Team / AnnaDB

Developer-first database
Apache License 2.0
56 stars 4 forks source link

How to get a single entry by using a UUID instead of a "link" #19

Closed tibeer closed 1 year ago

tibeer commented 1 year ago

Hi there,

I wonder how I would get a single entry by using a UUID in Python. The code below gives me this error: "Get query can contain only links"

from annadb import Connection
from uuid import UUID

db = Connection.from_connection_string("annadb://localhost:10001")

def get(container: str, id: UUID) -> None:
    container = db[container]
    response = container.get_one(id).run()
    print(response)

get("category", "bd6b60a1-02c3-401f-954b-f136b7f62b25")
roman-right commented 1 year ago

Hey @tibeer ,

Thank you for the issue. Currently, it doesn't cast UUID into links, but I have to add this feature.

For now, you can use the next way:

from annadb import Connection
from uuid import UUID

from annadb.data_types.primitive import Link

db = Connection.from_connection_string("annadb://localhost:10001")

def get(container: str, id: UUID) -> None:
    link = Link(prefix=container, value=id)
    container = db[container]
    response = container.get_one(link).run()
    print(response.meta.count, response.data)

get("category", "bd6b60a1-02c3-401f-954b-f136b7f62b25")
tibeer commented 1 year ago

Awesome! Thanks a lot :)