summaryrefslogtreecommitdiff
path: root/DAL
diff options
context:
space:
mode:
authorPhysick <96335032+DegustatorPonos@users.noreply.github.com>2025-11-29 20:18:11 +0500
committerPhysick <96335032+DegustatorPonos@users.noreply.github.com>2025-11-29 20:18:11 +0500
commite07dca81d05f304865a59c8afee98a3cde8bce8c (patch)
tree2dd01bbc5fd20b6ae024f0c18eb8946887ae9339 /DAL
Project init
Diffstat (limited to 'DAL')
-rw-r--r--DAL/DB/CRUD.go36
-rw-r--r--DAL/DB/CRUD_test.go25
-rw-r--r--DAL/go.mod3
-rw-r--r--DAL/models/Fighter.go17
4 files changed, 81 insertions, 0 deletions
diff --git a/DAL/DB/CRUD.go b/DAL/DB/CRUD.go
new file mode 100644
index 0000000..a3b4a24
--- /dev/null
+++ b/DAL/DB/CRUD.go
@@ -0,0 +1,36 @@
+package db
+
+import (
+ "reflect"
+ "strings"
+)
+
+type DataTable[T any] struct {
+ TableName string
+}
+
+// Forms a query to get all the fields from database
+func (self *DataTable[T]) formSelectRequest() string {
+ var sb = strings.Builder{}
+ sb.WriteString("SELECT (")
+ var fields = self.getFields()
+ for i, v := range fields {
+ if i != 0 {
+ sb.WriteString(", ")
+ }
+ sb.WriteString(v)
+ }
+ sb.WriteString(") FROM ")
+ sb.WriteString(self.TableName)
+ sb.WriteString(";")
+ return sb.String()
+}
+
+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)
+ }
+ return outp
+}
diff --git a/DAL/DB/CRUD_test.go b/DAL/DB/CRUD_test.go
new file mode 100644
index 0000000..de6fd40
--- /dev/null
+++ b/DAL/DB/CRUD_test.go
@@ -0,0 +1,25 @@
+package db
+
+import (
+ "testing"
+ "time"
+)
+
+type testDataType struct {
+ Id uint64
+ Name string
+ Data time.Time
+}
+
+var testDataTable = DataTable[testDataType] {
+ TableName: "DataTable",
+}
+
+func TestFormSelectRequest(t *testing.T) {
+ var expected = "SELECT (Id, Name, Data) FROM DataTable;"
+ var request = testDataTable.formSelectRequest()
+ if request != expected {
+ t.Errorf("Incorrect select query. \n Expected: '%s' \n Got: '%s'", expected, request)
+ }
+}
+
diff --git a/DAL/go.mod b/DAL/go.mod
new file mode 100644
index 0000000..dbb4b54
--- /dev/null
+++ b/DAL/go.mod
@@ -0,0 +1,3 @@
+module physick.ru/predictions/DAL
+
+go 1.25.4
diff --git a/DAL/models/Fighter.go b/DAL/models/Fighter.go
new file mode 100644
index 0000000..a399609
--- /dev/null
+++ b/DAL/models/Fighter.go
@@ -0,0 +1,17 @@
+package models
+
+import "time"
+
+type Fighter struct {
+ Id uint64
+ FirstName string
+ LastName string
+ // can be null
+ MiddleName *string
+ BirthDate time.Time
+
+ BirthCardID uint64
+ LifeLayoutID uint64
+ SpiritualLayoutID uint64
+ InTheCircle bool
+}