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

Feat: Ignore Columns #49

Merged
merged 1 commit into from
Dec 6, 2021
Merged

Feat: Ignore Columns #49

merged 1 commit into from
Dec 6, 2021

Conversation

Codexiaoyi
Copy link
Collaborator

ignore columns by Tag and Option.

@codecov
Copy link

codecov bot commented Nov 9, 2021

Codecov Report

Merging #49 (51aaed1) into main (71867f0) will increase coverage by 0.88%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #49      +/-   ##
==========================================
+ Coverage   81.14%   82.03%   +0.88%     
==========================================
  Files          14       14              
  Lines         748      768      +20     
==========================================
+ Hits          607      630      +23     
+ Misses        120      118       -2     
+ Partials       21       20       -1     
Impacted Files Coverage Δ
model.go 100.00% <100.00%> (+7.89%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8ff671c...51aaed1. Read the comment docs.

@Codexiaoyi
Copy link
Collaborator Author

#47

@flycash
Copy link
Contributor

flycash commented Nov 22, 2021

Please fix deepsource issues

model.go Outdated
@@ -72,6 +72,11 @@ func (t *tagMetaRegistry) Register(table interface{}, opts ...tableMetaOption) (
for i := 0; i < lens; i++ {
structField := v.Field(i)
tag := structField.Tag.Get("eql")
isIgnore := strings.Contains(tag, "-")
Copy link
Contributor

Choose a reason for hiding this comment

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

please help to refactor this part. I think using strings.Contains is not a good practice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will parse the tag by bit operation. All tags are parsed at once and saved by bit operations.

model.go Outdated
for _, field := range fieldNames {
//has field in the TableMeta
if _, ok := meta.fieldMap[field]; ok {
exist := false
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't need this flag, just always `delete(meta.fieldMap, field). And you need to check if this is primary key, I think we'd better not allow users to remove primary key.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok.

Copy link
Contributor

@flycash flycash left a comment

Choose a reason for hiding this comment

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

Sorry for late reply because I was busy this month

model.go Outdated

// The tag is parsed by bit operation.
// This is better than using strings.Contains queries once for each tag.
func parseTag(tag string) tagBitFlags {
Copy link
Contributor

Choose a reason for hiding this comment

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

hhh, you don't need this. Just iterate the tags and the modify the column meta directly

}

type TestIgnoreModel struct {
Id int64 `eql:"auto_increment,primary_key,-"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer that symbol - has highest priority. So if we find -, we just ignore it.

model.go Outdated
for _, field := range fieldNames {
//has field in the TableMeta
if columnMeta, ok := meta.fieldMap[field]; ok {
if columnMeta.isPrimaryKey {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need to check this. Users should be responsible for their action. They can find they remove the PK when they run tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes.

@flycash flycash merged commit 587fafa into ecodeclub:main Dec 6, 2021
@flycash
Copy link
Contributor

flycash commented Dec 6, 2021

Please add example for this. I have added examples for some public functions and you can take them as reference

@Codexiaoyi Codexiaoyi deleted the ignore-columns branch December 6, 2021 06:15
@Codexiaoyi
Copy link
Collaborator Author

Please add example for this. I have added examples for some public functions and you can take them as reference

ok

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.

2 participants