bun:sqlite FindFirst returns an object with all values undefined

Running FindFirst gives me an object with the proper keys but all values are undefined. Running FindMany with a limit of 1 gives me the correct output but in an array. Enabling logger gives this output for both findFirst and findMany with limit 1 select "id", "name", "location" from "company" limit ? -- params: [1] I've narrowed it down by doing db.query.company.findFirst().prepare(); with this i can then do both .get() and .all(), it seems using get gives me the broken output while doing all give me the array with correct output. Any ideas what is happening here and why?
5 Replies
Angelelz
Angelelz12mo ago
You should use .get() when you're expecting only one value from the database. The problem is that findFirst is also attempting to pull the first element of the array. Does it work is you use findMany with limit 1 and the then .get()? findFirst with .all() should also work I think
jabh
jabhOP12mo ago
My intention is not to use the .get() or .all() but rather that they seem to be the underlaying functions being called and somewhere in the code for get in combination with bun:sqlite (i think) it breaks and I get an object with the correct keys but undefined values. For now this is my workaround to emulate the correct behaviour with findFirst
const user = await db.query.user
.findMany({
where: eq(userTable.username, username),
columns: {
id: true,
passwordHash: true,
firstName: true,
},
limit: 1,
})
.then((users) => users.at(0));
const user = await db.query.user
.findMany({
where: eq(userTable.username, username),
columns: {
id: true,
passwordHash: true,
firstName: true,
},
limit: 1,
})
.then((users) => users.at(0));
Angelelz
Angelelz12mo ago
Please create an issue in GH and if you can include the code that's giving you problems
jabh
jabhOP12mo ago
Will do, thanks! Is there any prefered online codespace I should submit with or just a codeblock?
Angelelz
Angelelz12mo ago
Preferably a repo or a code sandbox
Want results from more Discord servers?
Add your server