jkb
jkb
Explore posts from servers
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
@TOSL thanks for the help, looking forward to being able to use this in the future
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
:Shrug:
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
figured it would be a common use case
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
Im suprised they don't allow for the ordering by relation
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
Thats what I did get working here: db.select().from(users).innerJoin(userRoleMappings,eq(users.id,userRoleMappings.userId)).orderBy(asc(userRoleMappings.userRoleId)).limit(5).execute()
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
db.query.users.findMany({
with: {
userRoleMappings: {
orderBy: (userRoleMappings, { desc }) => [
desc(userRoleMappings.userRoleId),
],
},
},
});
db.query.users.findMany({
with: {
userRoleMappings: {
orderBy: (userRoleMappings, { desc }) => [
desc(userRoleMappings.userRoleId),
],
},
},
});
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
not the users
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
I did try that and it only sorts the userRoleMappings
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
{ "status": "error", "error": "syntax error at or near "desc"" } That query throws this error ^
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
@TOSL
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
this would be very similar to the other tables above, but I want to order the parent by a relational table
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
Im tyring to get a more basic example working. Im not using the tables mentioned above because my local db is not filled with that data yet. My users table is
export const user = pgTable(
"users",
{
id: uuid()
.primaryKey()
.default(sql`gen_random_uuid()`),
firstName: text(),
lastName: text(),
lastLogin: timestamp({ precision: 6, withTimezone: true }),
...defaultColumns,
},
(t) => [index("user_pk_index").on(t.id)],
)
export const userRoleMappings = pgTable(
"userRoleMappings",
{
id: uuid()
.primaryKey()
.default(sql`gen_random_uuid()`),
userId: uuid().references(() => user.id),
userRoleId: integer()
.notNull()
.references(() => userRoles.id),
...defaultColumns,
},
(t) => [index("user_role_mapping_pk_index").on(t.id)],
)

db.query.users.findMany({
with:{
userRoleMappings:true
},
orderBy:(userRoleMappings, { asc }) => [asc(userRoleMappings.userRoleId)]
})
export const user = pgTable(
"users",
{
id: uuid()
.primaryKey()
.default(sql`gen_random_uuid()`),
firstName: text(),
lastName: text(),
lastLogin: timestamp({ precision: 6, withTimezone: true }),
...defaultColumns,
},
(t) => [index("user_pk_index").on(t.id)],
)
export const userRoleMappings = pgTable(
"userRoleMappings",
{
id: uuid()
.primaryKey()
.default(sql`gen_random_uuid()`),
userId: uuid().references(() => user.id),
userRoleId: integer()
.notNull()
.references(() => userRoles.id),
...defaultColumns,
},
(t) => [index("user_role_mapping_pk_index").on(t.id)],
)

db.query.users.findMany({
with:{
userRoleMappings:true
},
orderBy:(userRoleMappings, { asc }) => [asc(userRoleMappings.userRoleId)]
})
In the example above I want to return users ordered by their userRoleId
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
Essentially looking to order playerItem based on player.lastName
28 replies
DTDrizzle Team
Created by jkb on 2/20/2025 in #help
Order by on Joined Tables
This will only order by the player table not the return of the playerItem
28 replies
DTDrizzle Team
Created by jkb on 12/12/2024 in #help
Drizzle Kit Generate renames columns incorrectly
@Mario564 I removed all my previous migrations and started from scratch. Thank you again for the help it seems to be fine for now. At least I know some steps to resolve it 👍
37 replies
DTDrizzle Team
Created by jkb on 12/12/2024 in #help
Drizzle Kit Generate renames columns incorrectly
That seemed to stop it from effecting other tables
37 replies
DTDrizzle Team
Created by jkb on 12/12/2024 in #help
Drizzle Kit Generate renames columns incorrectly
no
37 replies
DTDrizzle Team
Created by jkb on 12/12/2024 in #help
Drizzle Kit Generate renames columns incorrectly
I even removed all the references and explicitly added the timestamp in each table and it is still happening
37 replies
DTDrizzle Team
Created by jkb on 12/12/2024 in #help
Drizzle Kit Generate renames columns incorrectly
I got prompted to change other columns
37 replies
DTDrizzle Team
Created by jkb on 12/12/2024 in #help
Drizzle Kit Generate renames columns incorrectly
there is also no explicit documentation on allowing you to do this, it mentions being able to create objects for commonly used columns, but it also implicitly suggests you can
There are a few tricks you can use with Drizzle ORM. As long as Drizzle is entirely in TypeScript files, you can essentially do anything you would in a simple TypeScript project with your code.
There are a few tricks you can use with Drizzle ORM. As long as Drizzle is entirely in TypeScript files, you can essentially do anything you would in a simple TypeScript project with your code.
37 replies