Skip to content
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

Add Bulk Insert #313

Closed
josephmancuso opened this issue Jan 18, 2021 · 5 comments · Fixed by #334
Closed

Add Bulk Insert #313

josephmancuso opened this issue Jan 18, 2021 · 5 comments · Fixed by #334
Labels
feature request A feature that does not yet exist but will be a good addition to the library medium These issues are geared for people who have contributed to the project before Query Builder Related to the query builder

Comments

@josephmancuso
Copy link
Member

Should be a way to insert multiple records at once. This will simply create a insert statement like this:

User.bulk_insert([
    {"user": "Joe"},
    {"user": "bill"},
    {"user": "John"},
])

This will produce a query like this:

INSERT INTO `users` (`username`) VALUES("Joe"),("Bill"),("John")
@josephmancuso josephmancuso changed the title add bulk insert Add Bulk Insert Jan 18, 2021
@josephmancuso josephmancuso added feature request A feature that does not yet exist but will be a good addition to the library medium These issues are geared for people who have contributed to the project before labels Jan 18, 2021
@girardinsamuel
Copy link
Contributor

@josephmancuso maybe we should use this name:

User.bulk_create([])

as we are using User.create() for one record

@josephmancuso
Copy link
Member Author

Yeah I think that's fine.

@jpmateo022
Copy link

jpmateo022 commented Jan 25, 2021

I think User.create([]) looks good similar to Eloquent. Though I really hope we have this soon. It's actually a very critical feature to have since putting create() inside a loop is a bad practice and will cause performance problems. Masonite ORM doesn't seem to have a way to construct a raw SQL Insert query which can be an alternative solution or workaround.

@josephmancuso
Copy link
Member Author

@jpmateo022 Ok I can work on this tonight. Both those features

@jpmateo022
Copy link

@josephmancuso Thank you so much!

@josephmancuso josephmancuso added the Query Builder Related to the query builder label Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature that does not yet exist but will be a good addition to the library medium These issues are geared for people who have contributed to the project before Query Builder Related to the query builder
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants