-
-
Notifications
You must be signed in to change notification settings - Fork 866
[FEATURE]: allow INSERT in CTEs (WITH clauses) #2078
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
@AndriiSherman should this also include DELETE as well?
|
IMO it should include INSERT, SELECT, UPDATE and DELETE as Drizzle aims to be full featured SQL-in-TS |
This needs to be added, as it is something that appears in complicated apps! And both MySQL and Postgres support such CTE queries. |
+1 In my case, I need to use it with UPDATE. All operations are important for this feature. Maybe there needs to be a note on the documentation that it only supports SELECT for now. |
Please add this! |
Is this why I get the error const newTimezoneId = db
.$with("new_timezone_id")
.as(
db
.insert(timezones)
.values({ name: "UTC" })
.onConflictDoNothing()
.returning({ id: timezones.id }),
); |
This would be a game changer. |
Has anyone come up with a workaround? |
I also need this. |
@michrome Yes. Have you come up with a workaround? |
I wanted a I agree with comments above though: Drizzle should add support for INSERT with CTEs as there are many valid use cases for it. async function getTimezoneId(timezoneName) {
const existingTimezone = await db
.select({ id: timezones.id })
.from(timezones)
.where(eq(timezones.name, timezoneName))
.limit(1);
if (existingTimezone.length !== 1) {
return await createTimezone(timezoneName); // executes an INSERT and returns the new ID
}
return existingTimezone[0].id;
} |
Bummer, I was hoping to avoid multiple queries. My company will have to stick with Kysely for data-intensive applications. |
Great feature! It can improve multiple inserts to many tables |
really need this in my app, is there a workaround available even if not pretty and/or not fully typesafe that keeps the whole thing in one DB query? i was trying to figure out if i could use |
I want to add that a await db.insert({
authors: {
name: 'Jane Austen',
books: {
create: [
{ title: 'Pride and Prejudice' },
{ title: 'Sense and Sensibility' },
],
},
},
}); J |
it more about |
What if we want to Note: Going to use await db.insert({
authors: {
name: 'Jane Austen',
books: {
insert: [
{ title: 'Pride and Prejudice' },
{ title: 'Sense and Sensibility' },
],
},
},
}); For await db.insert({
authors: {
name: 'Jane Austen',
books: {
update: [
{ id: '0x123', title: 'Pride and Prejudice' },
{ id: '0x234', title: 'Sense and Sensibility' }
],
},
},
}); J |
i talk that it more about relation API this differ from SQL writing - dont like it in query builder but proposal is good i need it |
Available in |
Would this support multiple J |
Describe what you want
Drizzle ORM supports
SELECT
queries in CTEs (WITH
clauses). From the docs:Currently, Drizzle does not support
INSERT
queries in CTEs. Example of such a query:As you can see, this would be very useful for nested inserts in a single query and should be supported by Drizzle to be a feature complete SQL query builder.
The text was updated successfully, but these errors were encountered: