.get() returning only one element
Hey I am using DrizzleORM with Turso and I am having a problem thath this query return only one element, not a list of objects. How?
export async function GET(req) {
const page = req.query?.page ? parseInt(req.query.page) : 1;
const limit = req.query?.limit ? parseInt(req.query.limit) : 10;
const offset = (page - 1) * limit;
const fetchedPosts = await db.select().from(posts).limit(limit).offset(offset).get();
console.log(fetchedPosts)
return NextResponse.json(fetchedPosts)
}
Can somebody please help me?
Thank you very much!
10 Replies
use
getAll()
Can't use that, there is no getAll() method. Can anybody help me?
Can you try this instead:
Note: make sure you've installed the latest version 👍
It's not working. We need get() to get the results rather than the raw function. Any other idea?
does it work without limit & offset?
like returns more than 1
No, It is not working neither without limit and offset.
Any other idea?
@Andrew Sherman maybe can you help us please?
the problem is that you are getting and array with 1 element instead of just 1 object from .get()?
The problem is that I am getting one object element, instead of array of objects with get.
oh
then just use
.all()
get() is for 1 element
all() for an array
we didn't update docs for that yet
but soon will be thereAhhhhhhh... Thank you very much!! It worked. Please update the docs ASAP! 😄 😄