React Developer
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?