vaphes / pocketbase

PocketBase client SDK for python
https://pypi.org/project/pocketbase/
MIT License
332 stars 38 forks source link

how to see data from [<Record: 85oeuawmpqdm44y>, <Record: l99wjn9094c2193>] #29

Closed bobwatcherx closed 1 year ago

bobwatcherx commented 1 year ago

i want to see and display all data in collection . and output like this [<Record: 85oeuawmpqdm44y>, ] how to parse it into text

bobwatcherx commented 1 year ago

from my code here import asyncio from pocketbase import PocketBase

client = PocketBase('http://127.0.0.1:8090')

admin_data = client.admins.auth_with_password("xxxx@gmail.com", "admin12345")

result = client.collection("fletSample").get_full_list()

for x in result: print(x)

tjmuenster commented 1 year ago

I'm not 100% sure if you can get the content of every field without knowing what fields an element of result will contain (someone will correct me). You'd probably need to extend the class BaseModel and add class variables for your needs (e.g. the fields in your collection in pocketbase).

For me it worked, when writing:

for x in result:
    print(x.id)

Where id can be the name of the field in your collection.

gaetan1903 commented 1 year ago
client = PocketBase('http://127.0.0.1:8090/')

admin_data = client.admins.auth_with_password("[xxxx@gmail.com](mailto:xxxx@gmail.com)", "admin12345")

result = client.collection("fletSample").get_full_list()

for res in result:
  print(res.__dict__)
lewisjr commented 9 months ago

Figured it out, here's an example:

data = db.collection("data").get_full_list()
jsonified_data = [vars(row) for row in data]
print(jsonified_data)

Just note that if you wanted to use json.dumps to get indents on the terminal it'll return a TypeError: Object of type datetime is not JSON serializable from the created and updated columns at the very least.