Skip to content

Commit 71a8512

Browse files
authored
Merge pull request #96 from huandu/feature-with-without-tag
More flexibility to filter fields with WithTag and WithoutTag in Struct
2 parents 1191d33 + a2c395f commit 71a8512

File tree

5 files changed

+513
-140
lines changed

5 files changed

+513
-140
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ debug_test
3333

3434
# Mac
3535
.DS_Store
36+
37+
# go work
38+
go.work
39+
go.work.sum

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ We can define a struct type and use field tags to let `Struct` know how to creat
136136
type ATable struct {
137137
Field1 string // If a field doesn't has a tag, use "Field1" as column name in SQL.
138138
Field2 int `db:"field2"` // Use "db" in field tag to set column name used in SQL.
139-
Field3 int64 `db:"field3" fieldtag:"foo,bar"` // Set fieldtag to a field. We can call `WithTag` to change default tag or call methods like `Struct#SelectForTag` to set tag explicitly.
139+
Field3 int64 `db:"field3" fieldtag:"foo,bar"` // Set fieldtag to a field. We can call `WithTag` to include fields with tag or `WithoutTag` to exclude fields with tag.
140140
Field4 int64 `db:"field4" fieldtag:"foo"` // If we use `s.WithTag("foo").Select(table)`, columnes of SELECT are field3 and field4.
141141
Field5 string `db:"field5" fieldas:"f5_alias"` // Use "fieldas" in field tag to set a column alias (AS) used in SELECT.
142142
Ignored int32 `db:"-"` // If we set field name as "-", Struct will ignore it.
@@ -158,7 +158,7 @@ Here is a sample to use `Struct` as ORM. It should be quite straight forward for
158158

159159
```go
160160
type User struct {
161-
ID int64 `db:"id"`
161+
ID int64 `db:"id" fieldtag:"pk"`
162162
Name string `db:"name"`
163163
Status int `db:"status"`
164164
}

0 commit comments

Comments
 (0)