freerware / work

A compact library for tracking and committing changes to your entities.
Apache License 2.0
59 stars 2 forks source link

Introduce InsertFunc, UpdateFunc, and DeleteFunc options. #73

Closed fr33r closed 2 years ago

fr33r commented 2 years ago

Description

Introduces the work.UnitInsertFunc, work.UnitUpdateFunc, and work.UnitDeleteFunc options. Additionally refactors the work.SQLUnit and work.BestEffortUnit to leverage work.UnitDataMapperFunc internally instead of work.DataMapper.

Rationale

See #60 .

Suggested Version

v4.0.0-beta.5

Example Usage

// entities.
f := Foo{}

// type names.
ft := unit.TypeNameOf(f)

// 🎉
opts = []unit.Option{
  unit.DB(db),
  unit.InsertFunc(ft, func(ctx context.Context, mCtx unit.MapperContext, entities ...interface{}) error {
    // insertion data mapper logic.
  }),
  unit.UpdateFunc(ft, func(ctx context.Context, mCtx unit.MapperContext, entities ...interface{}) error {
    // update data mapper logic.
  }),
  unit.DeleteFunc(ft, func(ctx context.Context, mCtx unit.MapperContext, entities ...interface{}) error {
    // deletion data mapper logic.
  }),
}
unit, err := unit.New(opts...)
codecov[bot] commented 2 years ago

Codecov Report

Base: 96.57% // Head: 98.71% // Increases project coverage by +2.13% :tada:

Coverage data is based on head (9e6c128) compared to base (339bf8e). Patch coverage: 97.53% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #73 +/- ## ========================================== + Coverage 96.57% 98.71% +2.13% ========================================== Files 14 14 Lines 1345 1396 +51 ========================================== + Hits 1299 1378 +79 + Misses 34 14 -20 + Partials 12 4 -8 ``` | Flag | Coverage Δ | | |---|---|---| | v3 | `98.71% <ø> (ø)` | | | v4 | `98.70% <97.53%> (+3.97%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=freerware#carryforward-flags-in-the-pull-request-comment) to find out more. | [Impacted Files](https://codecov.io/gh/freerware/work/pull/73?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=freerware) | Coverage Δ | | |---|---|---| | [v4/best\_effort\_unit.go](https://codecov.io/gh/freerware/work/pull/73/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=freerware#diff-djQvYmVzdF9lZmZvcnRfdW5pdC5nbw==) | `95.10% <92.06%> (+8.57%)` | :arrow_up: | | [v4/sql\_unit.go](https://codecov.io/gh/freerware/work/pull/73/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=freerware#diff-djQvc3FsX3VuaXQuZ28=) | `100.00% <100.00%> (+6.66%)` | :arrow_up: | | [v4/unit.go](https://codecov.io/gh/freerware/work/pull/73/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=freerware#diff-djQvdW5pdC5nbw==) | `100.00% <100.00%> (ø)` | | | [v4/unit\_options.go](https://codecov.io/gh/freerware/work/pull/73/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=freerware#diff-djQvdW5pdF9vcHRpb25zLmdv) | `99.57% <100.00%> (+0.16%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=freerware). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=freerware)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.