Select
Select controls which fields the query returns. It defines the exact shape of the result type.
Without select
Section titled “Without select”Without select, all model columns are returned:
const { data: users } = await jsorm.users.get();// users: User[] (full model)With select
Section titled “With select”With select, only selected fields are returned:
const { data: users } = await jsorm.users.get({ select: { id: true, name: true, },});// users: { id: string; name: string }[]Relations in select
Section titled “Relations in select”Relations are specified as nested objects. They are flattened to the parent level:
const { data: users } = await jsorm.users.get({ select: { id: true, name: true, role: { name: { as: "roleName" } }, },});// users: { id: string; name: string; roleName: string }[]// ↑ role.name is flattened to the parent levelAliases
Section titled “Aliases”Use { as: "alias" } to rename fields:
const { data: users } = await jsorm.users.get({ select: { id: true, name: { as: "Nombre" }, role: { name: { as: "rol" }, }, },});// users: { id: string; Nombre: string; rol: string }[]first with select
Section titled “first with select”const { data: user } = await jsorm.users.first({ select: { name: true, email: true, role: { name: { as: "roleName" } } }, where: { email: "juan@test.com" },});// user: { name: string; email: string; roleName: string } | null