Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
excelsieur
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
excelsieur
Commits
49410bb5
Verified
Commit
49410bb5
authored
6 years ago
by
Alexis Reigel
Browse files
Options
Downloads
Patches
Plain Diff
document transaction support
parent
b7eb2160
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!6
Convert test to spec syntax
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+41
-0
41 additions, 0 deletions
README.md
with
41 additions
and
0 deletions
README.md
+
41
−
0
View file @
49410bb5
...
@@ -74,6 +74,47 @@ import.total
...
@@ -74,6 +74,47 @@ import.total
# => 3
# => 3
```
```
### Transactions
When setting
`transaction true`
no record is inserted if any one of them has an error.
```
ruby
class
UserImporter
<
Excelsior
::
Importer
# declare the source file
source
"static/ftp/users.xlsx"
# only insert all rows if none of them have an error
transaction
true
# declare the mapping
map
"First Name"
,
to: :firstname
map
"Last Name"
,
to: :lastname
map
"E-Mail"
,
to: :email
end
```
If a block is passed to
`run`
the block needs to raise an error in order to
roll back the transaction.
This means that the following will trigger a rollback if the model is not
valid:
```
ruby
UserImport
.
new
.
run
do
|
row
|
User
.
create!
(
row
)
end
```
On the other hand, the following won't trigger a rollback if the model is
invalid:
```
ruby
UserImport
.
new
.
run
do
|
row
|
User
.
create
(
row
)
end
```
### Extended API
### Extended API
You may want to pass an excel file per instance. You can also define your own
You may want to pass an excel file per instance. You can also define your own
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment