-
-
Notifications
You must be signed in to change notification settings - Fork 14
Subquery crash in select().insert() #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is also not possible for UPDATE type queries. |
Yes, it's a known limitation, this is to be done in the future. No type error because it's meant to be done in the future, and adding type errors in this case won't be simple.
It is bypassable by a separate query: const id = await db.user.get("id").insert({ name: "Bob" })
const userData = await db.user.find(id).select('id', { posts: q => q.posts.select("id", "text") }) |
For context, my use case is using the shared helper for create and select. For example, the chat app uses: export const selectViewChatMessage = db.chatMessage.makeHelper(q =>
q.select("id", "content", {
time: "createdAt",
// TODO replace raw SQL with ORM once https://github.com/romeerez/orchid-orm/issues/383 is fixed.
username: () => sql<string>`(select username from "user" where id=user_id)`,
// username: t => t.user.get("username"),
}),
)
// add message
const newMessage = await selectViewChatMessage(db.chatMessage).create({ chatId, userId, text, content })
// list messages
const lastMessages = await selectViewChatMessage(db.chatMessage).order({ id: "DESC" }) |
With
select().insert()
, it's not possible to use subqueries:I'm not sure if this is a known limitation or something that could be fixed?
Full reproduction
The text was updated successfully, but these errors were encountered: