.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
Gyurmatag
GyurmatagOP2y ago
Can't use that, there is no getAll() method. Can anybody help me?
hisam
hisam2y ago
Can you try this instead:
const fetchedPosts = await db.select().from(posts).limit(limit).offset(offset);
const fetchedPosts = await db.select().from(posts).limit(limit).offset(offset);
Note: make sure you've installed the latest version 👍
Gyurmatag
GyurmatagOP2y ago
It's not working. We need get() to get the results rather than the raw function. Any other idea?
Startup Spells 🪄 Newsletter Guy
does it work without limit & offset? like returns more than 1
Gyurmatag
GyurmatagOP2y ago
No, It is not working neither without limit and offset. Any other idea? @Andrew Sherman maybe can you help us please?
Andrii Sherman
the problem is that you are getting and array with 1 element instead of just 1 object from .get()?
Gyurmatag
GyurmatagOP2y ago
The problem is that I am getting one object element, instead of array of objects with get.
Andrii Sherman
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 there
Gyurmatag
GyurmatagOP2y ago
Ahhhhhhh... Thank you very much!! It worked. Please update the docs ASAP! 😄 😄
Want results from more Discord servers?
Add your server