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
- Framework categorization for Sites
Hello, I want to deploy my web app via Appwrite SItes. My web app is vite+reactjs. In the Appwrite docs, it creates a vite+react app, and chooses React from the...
- [SOLVED] Appwrite 25.1.0 returns Invalid...
I've already opened an issue on GitHub, but somewhat it doesn't seem like GitHub is monitored very closely, so I'm leaving a bug report here on Discord as well....
- Helping in unblock my account
I deleted my Appwrite Cloud account that was linked via GitHub. Now I activated my GitHub Student Pack and want to sign up again using the same GitHub account, ...