summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhysick <96335032+DegustatorPonos@users.noreply.github.com>2025-11-29 20:25:00 +0500
committerPhysick <96335032+DegustatorPonos@users.noreply.github.com>2025-11-29 20:25:00 +0500
commit757e8534d1651965f55610d96f93c952a377f3c9 (patch)
tree072a70860f1ab8c68c7708f85a00b35d9215fdc9
parente07dca81d05f304865a59c8afee98a3cde8bce8c (diff)
Added tags to reflection
-rw-r--r--DAL/DB/CRUD.go7
-rw-r--r--DAL/DB/CRUD_test.go4
2 files changed, 8 insertions, 3 deletions
diff --git a/DAL/DB/CRUD.go b/DAL/DB/CRUD.go
index a3b4a24..51ef908 100644
--- a/DAL/DB/CRUD.go
+++ b/DAL/DB/CRUD.go
@@ -30,7 +30,12 @@ func (self *DataTable[T]) getFields() []string {
var zero T
var outp = make([]string, 0)
for _, f := range reflect.VisibleFields(reflect.TypeOf(zero)) {
- outp = append(outp, f.Name)
+ var tag, exists = f.Tag.Lookup("sql")
+ if exists {
+ outp = append(outp, tag)
+ } else {
+ outp = append(outp, f.Name)
+ }
}
return outp
}
diff --git a/DAL/DB/CRUD_test.go b/DAL/DB/CRUD_test.go
index de6fd40..474c937 100644
--- a/DAL/DB/CRUD_test.go
+++ b/DAL/DB/CRUD_test.go
@@ -7,7 +7,7 @@ import (
type testDataType struct {
Id uint64
- Name string
+ Name string `sql:"username"`
Data time.Time
}
@@ -16,7 +16,7 @@ var testDataTable = DataTable[testDataType] {
}
func TestFormSelectRequest(t *testing.T) {
- var expected = "SELECT (Id, Name, Data) FROM DataTable;"
+ var expected = "SELECT (Id, username, Data) FROM DataTable;"
var request = testDataTable.formSelectRequest()
if request != expected {
t.Errorf("Incorrect select query. \n Expected: '%s' \n Got: '%s'", expected, request)