-
Notifications
You must be signed in to change notification settings - Fork 46
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
feat: abstract model storage and add csv output for walk command #316
Conversation
Codecov Report
@@ Coverage Diff @@
## master #316 +/- ##
========================================
+ Coverage 44.9% 45.6% +0.6%
========================================
Files 20 22 +2
Lines 1978 2075 +97
========================================
+ Hits 890 947 +57
- Misses 969 997 +28
- Partials 119 131 +12 |
861dcc3
to
c34dfd4
Compare
c34dfd4
to
43fcf9f
Compare
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.
Good Stuff!!
Most of the changes here look fairly mechanical and I didn't review them too thoroughly.
I like that this centralizes access of go-pg. 🚢
if _, err := s.tx.ModelContext(ctx, m). | ||
OnConflict("do nothing"). | ||
Insert(); err != nil { | ||
return xerrors.Errorf("persisting model: %w", err) | ||
} |
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.
After this change lands would you expect #292 to be addressed here via reflection, via an interface the model implements, or something different?
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.
I think we could either handle in a few ways:
a) automatic via reflection magic (would be ideal but I'm unsure)
b) the model's Persist method could pass some hints when it calls PersistModel
c) we could add an UpdateModel method to StorageBatch that allows more control over the persistence
storage/csv_test.go
Outdated
Message: "msg1", | ||
} | ||
|
||
dir, err := ioutil.TempDir("", "TestCSVPersist") |
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.
could use t.Name()
as instead of TestCSVPersist
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.
Good idea!
43fcf9f
to
6e711ff
Compare
Introduce
model.Storage
andmodel.StorageBatch
interfaces to abstract away the details of the underlying model storage system.model.Storage
is analogous to a database,model.StorageBatch
is analogous to a transaction. A task should callStorage.PersistBatch
with a set of results to be persisted. The storage will call thePersist
method on each result, passing in amodel.StorageBatch
. A model should persist itself by callingStorageBatch.PersistModel
. A composite type such as a list of results or a struct containing result fields should call thePersist
method on each of its sub-results to ensure that they are persisted correctly.Replace all the direct references to
go-pg
with this pair of interfaces. Move a bunch of helpers to more appropriate packages.Add a
--csv=path
flag which will cause Visor to write data to csv files at that path, one file per database table. This flag overrides any database connection string if supplied. In other words Visor will not write to both a database and csv files.