-
Notifications
You must be signed in to change notification settings - Fork 87
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
Bulk import #168
Merged
Merged
Bulk import #168
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
814de94
Start of bulk-import method
Blacksmoke16 d1b2134
Use parameterized statement
Blacksmoke16 93b6e67
Handle duplicate key IGNORE/UPDATE
Blacksmoke16 6435d63
Add commas between update values
Blacksmoke16 85c36a0
merge in the fields unity code
Blacksmoke16 73e7de5
Remove now undeeded primary_auto variable
Blacksmoke16 1a03145
Add import for pg adapter
Blacksmoke16 54dd5b7
Also quote other column key
Blacksmoke16 c74d126
Add adapter for sqlite
Blacksmoke16 e0e1be4
Merge branch 'master' into bulk-import
faustinoaq 84364d9
Fix spec
Blacksmoke16 2d15769
Add more tests, fix sqlite adapter
Blacksmoke16 bbd2f7f
Update readme
Blacksmoke16 2425ad2
Fix spacing issue in sqlite adapater
Blacksmoke16 87009d5
Fix indentation
Blacksmoke16 acc4a6e
Fix typos in readme examples
Blacksmoke16 4b10e27
Merge branch 'master' into bulk-import
faustinoaq 87268a0
Fix indentations
Blacksmoke16 f6dcf2a
Add overload methods for update/ignore_on_duplicate, update readme
Blacksmoke16 e3e525a
Add = sign to model arrays in readme
Blacksmoke16 371d0b4
Merge branch 'master' into bulk-import
drujensen 9fe4bcb
Specify imports do not trigger callbacks yet
Blacksmoke16 5b31b80
proper grammar
Blacksmoke16 027be38
Merge branch 'master' into bulk-import
drujensen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,20 @@ module Granite::ORM::Transactions | |
@updated_at : Time? | ||
@created_at : Time? | ||
|
||
# The import class method will run a batch INSERT statement for each model in the array | ||
# the array must contain only one model class | ||
# invalid model records will be skipped | ||
def self.import(model_array : Array(self)) | ||
begin | ||
@@adapter.import(table_name, primary_name, {{primary_auto}}, fields, model_array) | ||
rescue err | ||
raise DB::Error.new(err.message) | ||
end | ||
end | ||
|
||
# The save method will check to see if the primary exists yet. If it does it | ||
# will call the update method, otherwise it will call the create method. | ||
# This will update the timestamps apropriately. | ||
# This will update the timestamps appropriately. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥇 |
||
def save | ||
return false unless valid? | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unless primary_auto references above/below here can be removed once #169 gets merged, since fields will cover it by default.
Probably also be able to remove the primary_auto param since that is only reason i needed it.