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

Export WriteAdapter method #26

Merged
merged 1 commit into from Aug 24, 2023
Merged

Conversation

skolodyazhnyy
Copy link
Contributor

@skolodyazhnyy skolodyazhnyy commented Aug 23, 2023

Sometimes you have to break abstraction for whatever reason and get to underlying SQL connection. With standard SQL adapter you can get database connection using Adapter method in rel.Repository.

repo.Adapter(ctx).(*sql.SQL).DB

But if your SQL adapter is wrapped into primaryreplica it becomes impossible to access underlying connection.

As a suggestion, in this PR I've exported WriteAdapter() method which allows to get access to primary adapter (connection).

It's a little bit cumbersome

pr := repo.Adapter(ctx).(*primaryreplica.PrimaryReplica)
db := pr.WriteAdapter().(*sql.SQL).DB

But it allows to implement a workaround or execute very exotic query otherwise not supported by Repository API.

It probably would make sense to open up ReadAdapter() too, but I wanted to keep changes to a minimum.

As a context, in my case I'm trying to make aggregation by a float (decimal) field which is not supported by Repository yet.

Export WriterAdapter method to allow users to get to the adapter if they really have to.
@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (5eb196d) 100.00% compared to head (e669f00) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #26   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           31        31           
=========================================
  Hits            31        31           
Files Changed Coverage Δ
primary_replica.go 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Fs02 Fs02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks

@Fs02 Fs02 merged commit df5d4cf into go-rel:main Aug 24, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants