tomri
tomri
DTDrizzle Team
Created by tomri on 11/7/2023 in #help
how to group Related Items
// index.ts

const coursesList = await db
.select({ title: courses.title, tags: tags.tag })
.from(courseTags)
.leftJoin(courses, eq(courses.id, courseTags.courseId))
.leftJoin(tags, eq(courseTags.tagId, tags.id));
// index.ts

const coursesList = await db
.select({ title: courses.title, tags: tags.tag })
.from(courseTags)
.leftJoin(courses, eq(courses.id, courseTags.courseId))
.leftJoin(tags, eq(courseTags.tagId, tags.id));
# actual output

courses: [
{
title: "Course 1",
tags: "Tag 1"
}, {
title: "Course 2",
tags: "Tag 2"
}, {
title: "Course 3",
tags: "Tag 3"
}, {
title: "Course 1",
tags: "tag 4"
}, {
title: "Course 1",
tags: "tag 5"
}
]
# actual output

courses: [
{
title: "Course 1",
tags: "Tag 1"
}, {
title: "Course 2",
tags: "Tag 2"
}, {
title: "Course 3",
tags: "Tag 3"
}, {
title: "Course 1",
tags: "tag 4"
}, {
title: "Course 1",
tags: "tag 5"
}
]
# desired output

courses: [
{
title: "Course 1",
tags: ["Tag 1", "tag 4", "tag 5"]
}, {
title: "Course 2",
tags: ["Tag 2"]
}, {
title: "Course 3",
tags: ["Tag 3"]
}
]
# desired output

courses: [
{
title: "Course 1",
tags: ["Tag 1", "tag 4", "tag 5"]
}, {
title: "Course 2",
tags: ["Tag 2"]
}, {
title: "Course 3",
tags: ["Tag 3"]
}
]
1 replies
DTDrizzle Team
Created by tomri on 11/7/2023 in #help
is placeholder in prepare statements deprecated!??
const courses = db.query.userCourses
.findMany({
where: eq(placeholder("userId"), userCourses.userId),
columns: {},
with: { courses: true },
})
.prepare("courses");
const courses = db.query.userCourses
.findMany({
where: eq(placeholder("userId"), userCourses.userId),
columns: {},
with: { courses: true },
})
.prepare("courses");
'placeholder' is deprecated. typescript (6385) [1, 14]
The signature '(name: "userId"): Placeholder<"userId", any>' of 'placeholder' is deprecated. typescript (6387) [9, 15]
'placeholder' is deprecated. typescript (6385) [1, 14]
The signature '(name: "userId"): Placeholder<"userId", any>' of 'placeholder' is deprecated. typescript (6387) [9, 15]
4 replies
DTDrizzle Team
Created by tomri on 11/3/2023 in #help
error: column "id" cannot be cast automatically to type uuid
No description
9 replies