Hi, i starting to rework some older functions to TablesDB list_rows Method. I used list_documents with a resultset with worked fine. Now i tried to get all rows from a specific table and have the data in it. So i started with the Documentation and changed my function to the following.
from appwrite.client import Client from pydantic import BaseModel from datetime import datetime from typing import Optional from appwrite.services.tables_db import TablesDB from appwrite.query import Query import os
class Product(BaseModel): image: str description_de: str description_en: str description_fr: str price: float url: str visible: bool uvp: float name_en: str name_fr: str name_de: str popularity: int
def main(context): client = ( Client() .set_endpoint(os.environ["APPWRITE_FUNCTION_API_ENDPOINT"]) .set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"]) .set_key(context.req.headers["x-appwrite-key"]) ) databases = TablesDB(client)
database_id = "67615fe8003a2b1eaebf"
products_id = "677ae7d9003770708d10"
body = context.req.body_json or {}
offset = int(body.get("offset", 0))
context.log(f"Offset from body: {offset}")
limit = 25
try:
response = databases.list_rows(
database_id=database_id,
table_id=products_id,
#model_type=Product,
queries=[
Query.equal("visible", True),
Query.order_desc("$createdAt"),
Query.limit(limit),
Query.offset(offset)
]
)
context.log(response)
data = response.model_dump()
return context.res.json(data)
except Exception as e:
return context.res.json({"error": str(e)}, 500)
Response But as you can see no real Data are in it. Even if i add them via Query.select Anyone can help me here?
Query with Select response = databases.list_rows( database_id=database_id, table_id=products_id, model_type=Product, queries=[ Query.equal("visible", True), Query.order_desc("$createdAt"), Query.limit(limit), Query.offset(offset), Query.select([ "$id", "name_en", "name_fr", "name_de", "price", "url", "visible", "uvp", "popularity", "image", "description_de", "description_en", "description_fr"
])
]
)
Recommended threads
- Worker functions stuck on "Fetched 0 fun...
Appwrite Version: 1.9.0 Bug Description: The appwrite-worker-functions container gets stuck in an infinite loop logging "Fetched 0 functions..." while scheduled...
- I am using s3 for app storage but is it ...
_APP_STORAGE_DEVICE=s3 puts everything to the s3 storage but i need to be able to keep the function builds and site in the local and not waste the cloud storage...
- Local Serverless Function Testing: Are D...
I have followed the instructions to get the CLI working, and have been able to log-in, initialize my project, and created a simple Python function, which calls ...