From b7e136771d2378a19fb4446875ad8f6315a938df Mon Sep 17 00:00:00 2001 From: Alcione Date: Wed, 25 May 2022 15:41:29 +0200 Subject: [PATCH 01/13] puting father first and mother second --- mygorm/test.db | Bin 81920 -> 81920 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/mygorm/test.db b/mygorm/test.db index e973318eb49a0e0ac2d1bc8dba31f2a9a6d5f8c4..74f2790df8c3d1becb0a583b2ef6e20613a16e61 100644 GIT binary patch delta 320 zcmZo@U~On%-M}WmHJyQf8NWZ@XTIs11r^%)w4+$~8GL;i#2I)wIK(*^IeCo?jEr;* z%ybQm6b#L*OiZjy&GpQT3{B0s?O$?&l zCo?Apsy&(sq@6){@;Z5Om;uHn7ABVFmZl&B6rl#d#2^L)rB?Vl8pSb!tzIK93Daq0 XVq{=oVG7oXF4p`}e)~sxMt%hVAr?Q9 From 58d6082156b730530a992172a91addd65aa10502 Mon Sep 17 00:00:00 2001 From: Alcione Date: Wed, 25 May 2022 17:40:19 +0200 Subject: [PATCH 02/13] deleted .zshrc.save --- .zshrc.save | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .zshrc.save diff --git a/.zshrc.save b/.zshrc.save deleted file mode 100644 index 8b13789..0000000 --- a/.zshrc.save +++ /dev/null @@ -1 +0,0 @@ - From a683bfa7e0d160eaed02a4061cf2362504d803e3 Mon Sep 17 00:00:00 2001 From: Alcione Date: Wed, 1 Jun 2022 16:13:48 +0200 Subject: [PATCH 03/13] adding new meta data type --- mygorm/breedingbook.go | 62 ++++++++++++++++++++++++++++++++++++++++++ mygorm/gorm.go | 3 +- 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 mygorm/breedingbook.go diff --git a/mygorm/breedingbook.go b/mygorm/breedingbook.go new file mode 100644 index 0000000..eaf87e3 --- /dev/null +++ b/mygorm/breedingbook.go @@ -0,0 +1,62 @@ +package mygorm + +import ( + "github.com/jinzhu/gorm" +) + +type TypeEnum struct { + slug string +} + +func (te TypeEnum) String() string { + return te.slug +} + +var ( + TypeUnknown = TypeEnum{""} + TypeString = TypeEnum{"string"} + TypeText = TypeEnum{"text"} + TypeCheckbox = TypeEnum{"checkbox"} + TypeInt = TypeEnum{"integer"} + TypeFloat = TypeEnum{"floating point"} + TypeDate = TypeEnum{"date"} + TypeDateTime = TypeEnum{"timestamp"} + TypeSelectOne = TypeEnum{"select one"} + TypeSelectMany = TypeEnum{"select many"} +) + +func NewTypeEnum(s string) TypeEnum { + switch s { + case TypeString.slug: + return TypeString + case TypeText.slug: + return TypeText + case TypeCheckbox.slug: + return TypeCheckbox + case TypeInt.slug: + return TypeInt + case TypeFloat.slug: + return TypeFloat + case TypeDate.slug: + return TypeDate + case TypeDateTime.slug: + return TypeDateTime + case TypeSelectOne.slug: + return TypeSelectOne + case TypeSelectMany.slug: + return TypeSelectMany + } + return TypeUnknown +} + +type MetaType struct { + gorm.Model + Name string + Group string + Type TypeEnum +} + +type MetaGroup struct { + gorm.Model + Name string +} diff --git a/mygorm/gorm.go b/mygorm/gorm.go index fc26b59..fbb3782 100644 --- a/mygorm/gorm.go +++ b/mygorm/gorm.go @@ -418,8 +418,7 @@ func FindAncestorsForDog(tx *gorm.DB, dog *Dog, generations int) ([]*Dog, error) return ancestors, err } -func findAncestors(tx *gorm.DB, dog *Dog, ancestors []*Dog, curGeneration, maxGeneration int, -) ([]*Dog, error) { +func findAncestors(tx *gorm.DB, dog *Dog, ancestors []*Dog, curGeneration, maxGeneration int) ([]*Dog, error) { f := &Dog{} if dog == nil || dog.FatherID == 0 { f = nil From db50f96894f64aa6f15503cdd013a5704c7e5cdf Mon Sep 17 00:00:00 2001 From: Alcione Date: Thu, 2 Jun 2022 16:26:25 +0200 Subject: [PATCH 04/13] writing meta types --- mygorm/breedingbook.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/mygorm/breedingbook.go b/mygorm/breedingbook.go index eaf87e3..c165df9 100644 --- a/mygorm/breedingbook.go +++ b/mygorm/breedingbook.go @@ -25,6 +25,19 @@ var ( TypeSelectMany = TypeEnum{"select many"} ) +var AllTypeEnums = []string{ + TypeUnknown.slug, + TypeString.slug, + TypeText.slug, + TypeCheckbox.slug, + TypeInt.slug, + TypeFloat.slug, + TypeDate.slug, + TypeDateTime.slug, + TypeSelectOne.slug, + TypeSelectMany.slug, +} + func NewTypeEnum(s string) TypeEnum { switch s { case TypeString.slug: @@ -51,12 +64,13 @@ func NewTypeEnum(s string) TypeEnum { type MetaType struct { gorm.Model - Name string + Name string `gorm:"unique"` Group string - Type TypeEnum + Type TypeEnum `gorm:"unique"` } type MetaGroup struct { gorm.Model - Name string + Name string `gorm:"unique"` + Color string `gorm:"unique"` } From cc7174dfdf01e301b5d1cb47bf676368474fa562 Mon Sep 17 00:00:00 2001 From: Alcione Date: Tue, 7 Jun 2022 12:57:45 +0200 Subject: [PATCH 05/13] testDogsndParents - writing test --- mygorm/breedingbook.go | 24 +++++++++++++++------- mygorm/gorm.go | 4 ++-- mygorm/gorm_test.go | 44 +++++++++++++++++++++++++++++++++++++---- mygorm/test.db | Bin 81920 -> 131072 bytes 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/mygorm/breedingbook.go b/mygorm/breedingbook.go index c165df9..52a771e 100644 --- a/mygorm/breedingbook.go +++ b/mygorm/breedingbook.go @@ -62,15 +62,25 @@ func NewTypeEnum(s string) TypeEnum { return TypeUnknown } -type MetaType struct { +type BaseMetaFeature struct { gorm.Model - Name string `gorm:"unique"` - Group string - Type TypeEnum `gorm:"unique"` + Name string `gorm:"unique"` + ShortName string `gorm:"unique"` + Type TypeEnum + GroupID uint + Group FeatureGroup `gorm:"foreignkey:GroupID;association_autocreate:false;association_autoupdate:false"` } -type MetaGroup struct { +type FeatureGroup struct { gorm.Model - Name string `gorm:"unique"` - Color string `gorm:"unique"` + Name string `gorm:"unique"` + ShortName string `gorm:"unique"` + ColorID uint + Color Color `gorm:"foreignkey:ColorID;association_autocreate:false;association_autoupdate:false"` +} + +type Color struct { + gorm.Model + Name string `gorm:"unique"` + HexValue string `gorm:"unique"` } diff --git a/mygorm/gorm.go b/mygorm/gorm.go index fbb3782..d165479 100644 --- a/mygorm/gorm.go +++ b/mygorm/gorm.go @@ -482,8 +482,8 @@ func Init(dbFname string) (*gorm.DB, error) { } if err = db.AutoMigrate(&Dog{}, &Chick{}, &Litter{}, &Mate1{}, &Mate2{}, &Mate3{}, - &Mate4{}, &Mate5{}, &Mate6{}, &Mate7{}, &Mate8{}, &Mate9{}, &Mate10{}).Error; err != nil { - + &Mate4{}, &Mate5{}, &Mate6{}, &Mate7{}, &Mate8{}, &Mate9{}, &Mate10{}, + &Color{}, &FeatureGroup{}, &BaseMetaFeature{}).Error; err != nil { return nil, fmt.Errorf("unable to migrate DB to current state: %v", err) } diff --git a/mygorm/gorm_test.go b/mygorm/gorm_test.go index e9d15fc..003bdd0 100644 --- a/mygorm/gorm_test.go +++ b/mygorm/gorm_test.go @@ -32,14 +32,27 @@ func TestDogsAndParents(t *testing.T) { f := &Dog{Name: "Rex", HD: "A2", Gender: "M"} // write to DB - db.Create(m) - db.Create(f) + if err := db.Create(m).Error; err != nil { + t.Fatalf("Unable to create the Mother, %v", err) + } + + if err := db.Create(f).Error; err != nil { + t.Fatalf("Unable to create the Father, %v", err) + } + p1.MotherID = m.ID p1.FatherID = f.ID - db.Create(p1) + + if err := db.Create(p1).Error; err != nil { + t.Fatalf("Unable to create Puppy 1, %v", err) + } + p2.MotherID = m.ID p2.FatherID = f.ID - db.Create(p2) + + if err := db.Create(p2).Error; err != nil { + t.Fatalf("Unable to create Puppy 2, %v", err) + } // read from DB p1New := &Dog{} @@ -76,3 +89,26 @@ func TestDogsAndParents(t *testing.T) { t.Errorf("p2New should have got '%s' as father but instead it is '%s': %s", f.Name, p2New.Father.Name, spew.Sdump(p2New)) } } + +func TestColorAndFeatureGroups(t *testing.T) { + // create colors + c1 := &Color{Name: "red"} + c2 := &Color{Name: "green"} + c3 := &Color{Name: "blue"} + + // write to DB + if err := db.Create(c1).Error; err != nil { + t.Fatalf("Unable to create Color 1, %v", err) + } + + if err := db.Create(c2).Error; err != nil { + t.Fatalf("Unable to create Color 2, %v", err) + } + + if err := db.Create(c3).Error; err != nil { + t.Fatalf("Unable to create Color 3, %v", err) + } + + // create feature groups + +} diff --git a/mygorm/test.db b/mygorm/test.db index 74f2790df8c3d1becb0a583b2ef6e20613a16e61..c72cdcd7a831c50cc494c5f3d9dc2f9dcfc20a28 100644 GIT binary patch delta 2196 zcmcgu-*4Mg6u#F^{3D5dn`Wz71A}vFE5^Y zV>ufWit46(Q7Lbz0)J7_R*Q-@Dy34<1D=nL9cld>hhn_w!A*o_8T|<_zEfLs9LAVx+hvjmIa)<4Imj z%_LGYDRDwfr&CgTEH2H&;Cw+$V+2*kT#R6KYE${j)3So zK-b%uyoTO-4U(Nq1`f@jB#KkX9jK22Jh`$nXQu_ zO$A{CFRc~S%~D}gHeXjRsAaXL7G$Mn0s{vXeQNP!c7;FGkk2ierLI+l(Lem7JOJeE zUo}eq|I;b`_D%tSpm$jT-s^OW7k5+b6oSu}ATLrYz>h5e&tv*$Izs(K-J;GCUsJ>6 zH$>ibgFx=vuIKRtw!qx&cmP1H=>EO|3~v-8t?)Fw2g9w3BhYz-xa9&&AsK}*)z?ar)>UmY;qnQxFy)CwWi^0Kh z$39hAa$=Fpu;o&B(z58p!VNq~a<4{V<2g&313_ftOx?2BiI78*ZoXdW_B8b9rYnDH zipy|-!5cZ7=5;Sl;r-4nS*RYr{~2vXCDXu;wB%pD*hQaxehS`bG83VeE-E9 bybJO7L;UWO6bxa|qr;^q$3HpSXFk6J?Yo9| delta 603 zcmZo@;Am)IogghJ%D})N0>m&NI8nzKD5&Rrh!rTr$p0H8Au_Q*j)hT>|HouOfqLe~ zJfZ1klNsM_|2~tEm1#3O%Xe-eVQyZaIu^d^4E)RZ{rNugP2Vgi(9TyM#lp|v>&qa{ zz{|lQ&cVpZYh++#q-$WNYha{cXl7+%Vr6QsXJ%w*YG$r&U}R-rKuF%Bv^b;E(NMwB zh$)JhpxKr{!woG=3{CMEjwJ7snUe!Ge6qj1lp(Sk4NZ)UEbtivlAkmOir fK4N8VkrCPcWG Date: Tue, 7 Jun 2022 21:10:51 +0200 Subject: [PATCH 06/13] cleanin the code --- mygorm/gorm_test.go | 56 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/mygorm/gorm_test.go b/mygorm/gorm_test.go index 003bdd0..cbcfc9c 100644 --- a/mygorm/gorm_test.go +++ b/mygorm/gorm_test.go @@ -57,15 +57,15 @@ func TestDogsAndParents(t *testing.T) { // read from DB p1New := &Dog{} db.First(p1New, p1.ID) - if db.Model(p1New).Association("Mother").Error != nil { - t.Fatalf("Mother association error: %v", db.Model(p1New).Association("Mother").Error) + if err := db.Model(p1New).Association("Mother").Error; err != nil { + t.Fatalf("Mother association error: %v", err) } db.Model(p1New).Association("Mother").Find(&(p1New.Mother)) if p1New.Mother.ID != m.ID { t.Errorf("p1New should have got '%s' as mother but instead it is '%s': %s", m.Name, p1New.Mother.Name, spew.Sdump(p1New)) } - if db.Model(p1New).Association("Father").Error != nil { - t.Fatalf("Father association error: %v", db.Model(p1New).Association("Father").Error) + if err := db.Model(p1New).Association("Father").Error; err != nil { + t.Fatalf("Father association error: %v", err) } db.Model(p1New).Association("Father").Find(&(p1New.Father)) if p1New.Father.ID != f.ID { @@ -74,15 +74,15 @@ func TestDogsAndParents(t *testing.T) { p2New := &Dog{} db.First(p2New, p2.ID) - if db.Model(p2New).Association("Mother").Error != nil { - t.Fatalf("Mother association error: %v", db.Model(p2New).Association("Mother").Error) + if err := db.Model(p2New).Association("Mother").Error; err != nil { + t.Fatalf("Mother association error: %v", err) } db.Model(p2New).Association("Mother").Find(&(p2New.Mother)) if p2New.Mother.ID != m.ID { t.Errorf("p2New should have got '%s' as mother but instead it is '%s': %s", m.Name, p2New.Mother.Name, spew.Sdump(p2New)) } - if db.Model(p2New).Association("Father").Error != nil { - t.Fatalf("Father association error: %v", db.Model(p2New).Association("Father").Error) + if err := db.Model(p2New).Association("Father").Error; err != nil { + t.Fatalf("Father association error: %v", err) } db.Model(p2New).Association("Father").Find(&(p2New.Father)) if p2New.Father.ID != f.ID { @@ -110,5 +110,45 @@ func TestColorAndFeatureGroups(t *testing.T) { } // create feature groups + fg1 := &FeatureGroup{Name: "pigmente", ColorID: c1.ID} + fg2 := &FeatureGroup{Name: "Teeth", ColorID: c2.ID} + + // write to DB + if err := db.Create(fg1).Error; err != nil { + t.Fatalf("Unable to create feature group 1, %v", err) + } + + if err := db.Create(fg2).Error; err != nil { + t.Fatalf("Unable to create feature group 2, %v", err) + } + + // read from DB + fgNew := &FeatureGroup{} + if err := db.First(fgNew, fg1.ID).Error; err != nil { + t.Fatalf("Unable to read the feature group 1 , %v", err) + } + + if err := db.First(fgNew, fg2.ID).Error; err != nil { + t.Fatalf("Unable to read the feature group 2 , %v", err) + } + + // checking the association + if err := db.Model(fgNew).Association("Color").Error; err != nil { + t.Fatalf("Color association error: %v", err) + } + + // population association + db.Model(fgNew).Association("Color").Find(&(fgNew.Color)) + if fgNew.Color.ID != c1.ID { + t.Errorf("p1New should have got '%s' as color but instead it is '%s': %s", c1.Name, fgNew.Color.Name, spew.Sdump(fgNew)) + } + + if fgNew.Color.ID != c2.ID { + t.Errorf("p1New should have got '%s' as color but instead it is '%s': %s", c2.Name, fgNew.Color.Name, spew.Sdump(fgNew)) + } + + if fgNew.Color.ID != c3.ID { + t.Errorf("p1New should have got '%s' as color but instead it is '%s': %s", c3.Name, fgNew.Color.Name, spew.Sdump(fgNew)) + } } From 2e683bef1c1f1909cd651dfc7dad5a2a2d63c334 Mon Sep 17 00:00:00 2001 From: Alcione Date: Wed, 8 Jun 2022 15:21:06 +0200 Subject: [PATCH 07/13] Finished test --- .gitignore | 1 + mygorm/gorm_test.go | 56 +++++++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index fee9c28..da0c271 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ # Test binary, build with `go test -c` *.test +test.db # Output of the go coverage tool, specifically when used with LiteIDE *.out diff --git a/mygorm/gorm_test.go b/mygorm/gorm_test.go index cbcfc9c..e25330e 100644 --- a/mygorm/gorm_test.go +++ b/mygorm/gorm_test.go @@ -56,7 +56,10 @@ func TestDogsAndParents(t *testing.T) { // read from DB p1New := &Dog{} - db.First(p1New, p1.ID) + if err := db.First(p1New, p1.ID).Error; err != nil { + t.Fatalf("Unable to read puppy1 with ID %d: %v", p1.ID, err) + } + if err := db.Model(p1New).Association("Mother").Error; err != nil { t.Fatalf("Mother association error: %v", err) } @@ -73,7 +76,10 @@ func TestDogsAndParents(t *testing.T) { } p2New := &Dog{} - db.First(p2New, p2.ID) + if err := db.First(p2New, p2.ID).Error; err != nil { + t.Fatalf("Unable to read puppy2 with ID %d: %v", p2.ID, err) + } + if err := db.Model(p2New).Association("Mother").Error; err != nil { t.Fatalf("Mother association error: %v", err) } @@ -92,9 +98,8 @@ func TestDogsAndParents(t *testing.T) { func TestColorAndFeatureGroups(t *testing.T) { // create colors - c1 := &Color{Name: "red"} - c2 := &Color{Name: "green"} - c3 := &Color{Name: "blue"} + c1 := &Color{Name: "red", HexValue: "ff0000"} + c2 := &Color{Name: "green", HexValue: "00ff00"} // write to DB if err := db.Create(c1).Error; err != nil { @@ -105,13 +110,9 @@ func TestColorAndFeatureGroups(t *testing.T) { t.Fatalf("Unable to create Color 2, %v", err) } - if err := db.Create(c3).Error; err != nil { - t.Fatalf("Unable to create Color 3, %v", err) - } - // create feature groups - fg1 := &FeatureGroup{Name: "pigmente", ColorID: c1.ID} - fg2 := &FeatureGroup{Name: "Teeth", ColorID: c2.ID} + fg1 := &FeatureGroup{Name: "pigmente", ColorID: c1.ID, ShortName: "pigments"} + fg2 := &FeatureGroup{Name: "Teeth", ColorID: c2.ID, ShortName: "Teeth"} // write to DB if err := db.Create(fg1).Error; err != nil { @@ -123,32 +124,37 @@ func TestColorAndFeatureGroups(t *testing.T) { } // read from DB - fgNew := &FeatureGroup{} - if err := db.First(fgNew, fg1.ID).Error; err != nil { + fg1New := &FeatureGroup{} + if err := db.First(fg1New, fg1.ID).Error; err != nil { t.Fatalf("Unable to read the feature group 1 , %v", err) } - if err := db.First(fgNew, fg2.ID).Error; err != nil { - t.Fatalf("Unable to read the feature group 2 , %v", err) - } - // checking the association - if err := db.Model(fgNew).Association("Color").Error; err != nil { + if err := db.Model(fg1New).Association("Color").Error; err != nil { t.Fatalf("Color association error: %v", err) } // population association - db.Model(fgNew).Association("Color").Find(&(fgNew.Color)) - if fgNew.Color.ID != c1.ID { - t.Errorf("p1New should have got '%s' as color but instead it is '%s': %s", c1.Name, fgNew.Color.Name, spew.Sdump(fgNew)) + db.Model(fg1New).Association("Color").Find(&(fg1New.Color)) + if fg1New.Color.ID != c1.ID { + t.Errorf("p1New should have got '%s' as color but instead it is '%s': %s", c1.Name, fg1New.Color.Name, spew.Sdump(fg1New)) + } + + fg2New := &FeatureGroup{} + // read from DB + if err := db.First(fg2New, fg2.ID).Error; err != nil { + t.Fatalf("Unable to read the feature group 2 , %v", err) } - if fgNew.Color.ID != c2.ID { - t.Errorf("p1New should have got '%s' as color but instead it is '%s': %s", c2.Name, fgNew.Color.Name, spew.Sdump(fgNew)) + // checking the association + if err := db.Model(fg2New).Association("Color").Error; err != nil { + t.Fatalf("Color association error: %v", err) } - if fgNew.Color.ID != c3.ID { - t.Errorf("p1New should have got '%s' as color but instead it is '%s': %s", c3.Name, fgNew.Color.Name, spew.Sdump(fgNew)) + // population association + db.Model(fg2New).Association("Color").Find(&(fg2New.Color)) + if fg2New.Color.ID != c2.ID { + t.Errorf("p2New should have got '%s' as color but instead it is '%s': %s", c2.Name, fg2New.Color.Name, spew.Sdump(fg2New)) } } From 56d0c44914fcaa7618b08d5c6c8e9b8638204264 Mon Sep 17 00:00:00 2001 From: Alcione Date: Thu, 9 Jun 2022 14:59:47 +0200 Subject: [PATCH 08/13] teste Test Base Meta Feature And Feature Groups --- mygorm/breedingbook.go | 20 +++--- mygorm/gorm_test.go | 142 +++++++++++++++++++++++++++++++++++++++++ mygorm/test.db | Bin 131072 -> 131072 bytes 3 files changed, 152 insertions(+), 10 deletions(-) diff --git a/mygorm/breedingbook.go b/mygorm/breedingbook.go index 52a771e..0111e88 100644 --- a/mygorm/breedingbook.go +++ b/mygorm/breedingbook.go @@ -64,23 +64,23 @@ func NewTypeEnum(s string) TypeEnum { type BaseMetaFeature struct { gorm.Model - Name string `gorm:"unique"` - ShortName string `gorm:"unique"` - Type TypeEnum - GroupID uint + Name string `gorm:"unique; not null"` + ShortName string `gorm:"unique; not null"` + Type TypeEnum `gorm:"not null"` + GroupID uint `gorm:"not null"` Group FeatureGroup `gorm:"foreignkey:GroupID;association_autocreate:false;association_autoupdate:false"` } type FeatureGroup struct { gorm.Model - Name string `gorm:"unique"` - ShortName string `gorm:"unique"` - ColorID uint - Color Color `gorm:"foreignkey:ColorID;association_autocreate:false;association_autoupdate:false"` + Name string `gorm:"unique; not null"` + ShortName string `gorm:"unique; not null"` + ColorID uint `gorm:"not null"` + Color Color `gorm:"foreignkey:ColorID;association_autocreate:false;association_autoupdate:false"` } type Color struct { gorm.Model - Name string `gorm:"unique"` - HexValue string `gorm:"unique"` + Name string `gorm:"unique; not null"` + HexValue string `gorm:"unique; not null"` } diff --git a/mygorm/gorm_test.go b/mygorm/gorm_test.go index e25330e..8a97363 100644 --- a/mygorm/gorm_test.go +++ b/mygorm/gorm_test.go @@ -63,13 +63,16 @@ func TestDogsAndParents(t *testing.T) { if err := db.Model(p1New).Association("Mother").Error; err != nil { t.Fatalf("Mother association error: %v", err) } + db.Model(p1New).Association("Mother").Find(&(p1New.Mother)) if p1New.Mother.ID != m.ID { t.Errorf("p1New should have got '%s' as mother but instead it is '%s': %s", m.Name, p1New.Mother.Name, spew.Sdump(p1New)) } + if err := db.Model(p1New).Association("Father").Error; err != nil { t.Fatalf("Father association error: %v", err) } + db.Model(p1New).Association("Father").Find(&(p1New.Father)) if p1New.Father.ID != f.ID { t.Errorf("p1New should have got '%s' as father but instead it is '%s': %s", f.Name, p1New.Father.Name, spew.Sdump(p1New)) @@ -83,13 +86,16 @@ func TestDogsAndParents(t *testing.T) { if err := db.Model(p2New).Association("Mother").Error; err != nil { t.Fatalf("Mother association error: %v", err) } + db.Model(p2New).Association("Mother").Find(&(p2New.Mother)) if p2New.Mother.ID != m.ID { t.Errorf("p2New should have got '%s' as mother but instead it is '%s': %s", m.Name, p2New.Mother.Name, spew.Sdump(p2New)) } + if err := db.Model(p2New).Association("Father").Error; err != nil { t.Fatalf("Father association error: %v", err) } + db.Model(p2New).Association("Father").Find(&(p2New.Father)) if p2New.Father.ID != f.ID { t.Errorf("p2New should have got '%s' as father but instead it is '%s': %s", f.Name, p2New.Father.Name, spew.Sdump(p2New)) @@ -158,3 +164,139 @@ func TestColorAndFeatureGroups(t *testing.T) { } } + +func TestBaseMetaFeatureAndFeatureGroups(t *testing.T) { + // create colors + c3 := &Color{Name: "blue", HexValue: "0000ff"} + + // write to DB + if err := db.Create(c3).Error; err != nil { + t.Fatalf("Unable to create Color 3, %v", err) + } + + // create feature groups + fg3 := &FeatureGroup{Name: "pigmente2", ColorID: c3.ID, ShortName: "pigments2"} + fg4 := &FeatureGroup{Name: "teeth", ColorID: c3.ID, ShortName: "teeth"} + + // write to DB + if err := db.Create(fg3).Error; err != nil { + t.Fatalf("Unable to create feature group 1, %v", err) + } + + // write to DB + if err := db.Create(fg4).Error; err != nil { + t.Fatalf("Unable to create feature group 2, %v", err) + } + + // create BaseMetaFeature + f1 := &BaseMetaFeature{Name: "pigmente2", GroupID: fg3.ID, ShortName: "pigments2"} + f2 := &BaseMetaFeature{Name: "pigmente3", GroupID: fg3.ID, ShortName: "pigments3"} + f3 := &BaseMetaFeature{Name: "pigmente4", GroupID: fg3.ID, ShortName: "pigments4"} + f4 := &BaseMetaFeature{Name: "teeth", GroupID: fg4.ID, ShortName: "teeth"} + f5 := &BaseMetaFeature{Name: "teeth2", GroupID: fg4.ID, ShortName: "teeth2"} + + // f1 ------------------------ + + // write to DB + if err := db.Create(f1).Error; err != nil { + t.Fatalf("Unable to create feature 1, %v", err) + } + + // read from DB + f1New := &BaseMetaFeature{} + if err := db.First(f1New, f1.ID).Error; err != nil { + t.Fatalf("Unable to read the feature 1 , %v", err) + } + + // checking the association + if err := db.Model(f1New).Association("Group").Error; err != nil { + t.Fatalf("Group association error: %v", err) + } + + // population association + db.Model(f1New).Association("Group").Find(&(f1New.Group)) + if f1New.Group.ID != fg3.ID { + t.Errorf("f1New should have got '%s' as group but instead it is '%s': %s", fg3.Name, f1New.Group.Name, spew.Sdump(f1New)) + } + + // f2 ------------------------ + // write to DB + if err := db.Create(f2).Error; err != nil { + t.Fatalf("Unable to create feature 2, %v", err) + } + + // read from DB + f2New := &BaseMetaFeature{} + if err := db.First(f2New, f2.ID).Error; err != nil { + t.Fatalf("Unable to read the feature group 2, %v", err) + } + + // checking the association + if err := db.Model(f2New).Association("Group").Error; err != nil { + t.Fatalf("Group association error: %v", err) + } + + // population association + db.Model(f2New).Association("Group").Find(&(f2New.Group)) + if f2New.Group.ID != fg3.ID { + t.Errorf("f2New should have got '%s' as group but instead it is '%s': %s", fg3.Name, f2New.Group.Name, spew.Sdump(f2New)) + } + + // f3 ------------------------ + if err := db.Create(f3).Error; err != nil { + t.Fatalf("Unable to create feature group 3, %v", err) + } + + f3New := &BaseMetaFeature{} + if err := db.First(f3New, f3.ID).Error; err != nil { + t.Fatalf("Unable to reade the feature group 3, %v", err) + } + + if err := db.Model(f3New).Association("Group").Error; err != nil { + t.Fatalf("Group association error: %v", err) + } + + db.Model(f3New).Association("Group").Find(&(f3New.Group)) + if f3New.Group.ID != fg3.ID { + t.Errorf("f3new should have got '%s' as group but instead it is '%s': %s", fg3.Name, f3New.Group.Name, spew.Sdump(f3New)) + } + + // f4 ------------------------ + if err := db.Create(f4).Error; err != nil { + t.Fatalf("Unable to create feature group 4, %v", err) + } + + f4New := &BaseMetaFeature{} + if err := db.First(f4New, f4.ID).Error; err != nil { + t.Fatalf("Unable to reade the feature group 4, %v", err) + } + + if err := db.Model(f4New).Association("Group").Error; err != nil { + t.Fatalf("Group association err: %v", err) + } + + db.Model(f4New).Association("Group").Find(&(f4New.Group)) + if f4New.Group.ID != fg4.ID { + t.Errorf("f4New should have got '%s' as group but instead it is '%s': %s", fg4.Name, f4New.Group.Name, spew.Sdump(f4New)) + } + + // f5 ------------------------ + if err := db.Create(f5).Error; err != nil { + t.Fatalf("Unable to create feature group 5, %v", err) + } + + f5New := &BaseMetaFeature{} + if err := db.First(f5New, f5.ID).Error; err != nil { + t.Fatalf("Unable to reade the feature group 5, %v", err) + } + + if err := db.Model(f5New).Association("Group").Error; err != nil { + t.Fatalf("Group association err: %v", err) + } + + db.Model(f5New).Association("Group").Find(&(f5New.Group)) + if f5New.Group.ID != fg4.ID { + t.Errorf("f5New should have got '%s' as group but instead it is '%s': %s", fg4.Name, + f5New.Group.Name, spew.Sdump(f5New)) + } +} diff --git a/mygorm/test.db b/mygorm/test.db index c72cdcd7a831c50cc494c5f3d9dc2f9dcfc20a28..4aa6c94818c78ce9e58b5cf201b564653ef7c5cc 100644 GIT binary patch delta 2433 zcmbW2T}&KR6vywKJIl;0yK~qgUAKkoN{nTLrFUk(Ng8b$wWbtk08@(*Xc;I8EzJ%* z7)=(#lW$#VJ7S^@F=_flwA+NYeIUjMlfE>u8dDQmYg4~tRm9M$cV>6?qbx(>JlxF8 zx%W3`&iS8nW@p9OS@GO%yeHdykS)Xea6Wsk!~OR74#6J?;JI-2>&s$yPk*R;psQ;> zgP$rrhgm`%Y!DZ-?|CASUzJ_2~%*Gy17F4k)1mDtC+kI(*oXoiO1MHRi-FnY$(?CyVI$ zp5QK}%0sHAR40mQpMO92Ox3AKB9V+coU-h>--3+|9v<=t*5C)Y3Hh8av;@hWJW=q8 z5nUTPtxb;%jcFs(GignC?I0wKi%&!2>8Y8sI`8I40H2(ioJ#8?xAvU8>Lwr|Sc2C; zVzdo8bCd{XBANm<0~}Wq@q~k;74{R8Ga6;r*jO(oSn;ooj71VknV8v>^Rj(Bt!ZaW zAf>(7^0ILYq(bAVGIKMsY)@;WCXZ4#lO=(B0)l(+EBu}F(XXIQBu&`-4UXvGDy=CQ0A1_+<=Et@3oQx!$3N2o?PixxrDQh8v#DWHcTR>xKvY6^j z?XQ+MoShgyt(}?H)Z&e7SR$kS@%5PI`Nt#MoT{W}CTq|v$)FN67zfHNZnc_H#D(tqzGErN; zQ8HL4x2=jf5u=LJ$f~g0^oR|QkU>^;Y|1BmWRj;DzRaCu5y|t4Gf~DFNF?YpUYIyRZ?b}b5LaWU5WBdfBx5t{#1qRVmoqACUcea7 zC&#h(&CKD5N4uGHL=t+GQ?-Bi6u%|1 z|4#<~pFoS>^9!;u3vV-pyYIoPdHQp)rNiHs>sY@FNw%wl9=-OiQH_={sROTb@w zLyiarK_(9duHT&BIpsM%aUA7HV7tX3&3=z9gk={SKkF$L6=q{558j7ByMcfsVzZ!t z7}Ivf$&AHJoV-%(;)aHd&92jHr!tMyc&{r!fjKax#jsi)(5!Hrr0$ zF`aQASXwgF&oeO8RYwUN*zuVuN(z~IC8_DDMbl5uV60){{xjWkCgU+q^rXK1!z@N# iCKh1eJ>AYYm+>Lv_D2&K<(U|{HZunN*I$$%06_pG1Ir8m From 7ec062491d7212b24746c3bede8cfd471123cf73 Mon Sep 17 00:00:00 2001 From: Alcione Date: Fri, 10 Jun 2022 13:56:31 +0200 Subject: [PATCH 09/13] delete test.db --- mygorm/test.db | Bin 131072 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 mygorm/test.db diff --git a/mygorm/test.db b/mygorm/test.db deleted file mode 100644 index 4aa6c94818c78ce9e58b5cf201b564653ef7c5cc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 131072 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 From ca95e02fc53fedd9ec8063320cb0af31be1dc025 Mon Sep 17 00:00:00 2001 From: Alcione Date: Fri, 10 Jun 2022 16:31:18 +0200 Subject: [PATCH 10/13] adding more meta struct --- mygorm/breedingbook.go | 149 +++++++++++++++++++++++++++-------------- mygorm/gorm_test.go | 16 +++-- 2 files changed, 108 insertions(+), 57 deletions(-) diff --git a/mygorm/breedingbook.go b/mygorm/breedingbook.go index 0111e88..88e4839 100644 --- a/mygorm/breedingbook.go +++ b/mygorm/breedingbook.go @@ -4,62 +4,46 @@ import ( "github.com/jinzhu/gorm" ) -type TypeEnum struct { - slug string -} - -func (te TypeEnum) String() string { - return te.slug -} +type TypeEnum string -var ( - TypeUnknown = TypeEnum{""} - TypeString = TypeEnum{"string"} - TypeText = TypeEnum{"text"} - TypeCheckbox = TypeEnum{"checkbox"} - TypeInt = TypeEnum{"integer"} - TypeFloat = TypeEnum{"floating point"} - TypeDate = TypeEnum{"date"} - TypeDateTime = TypeEnum{"timestamp"} - TypeSelectOne = TypeEnum{"select one"} - TypeSelectMany = TypeEnum{"select many"} +const ( + TypeUnknown = TypeEnum("") + TypeString = TypeEnum("string") // done + TypeText = TypeEnum("text") // done + TypeCheckbox = TypeEnum("checkbox") // done + TypeInt = TypeEnum("integer") // int64 + TypeFloat = TypeEnum("floating point") //float64 + TypeDate = TypeEnum("date") //time.Time + TypeDateTime = TypeEnum("timestamp") //time.Time + TypeSelectOne = TypeEnum("select one") // string done + TypeSelectMany = TypeEnum("select many") // []string ) -var AllTypeEnums = []string{ - TypeUnknown.slug, - TypeString.slug, - TypeText.slug, - TypeCheckbox.slug, - TypeInt.slug, - TypeFloat.slug, - TypeDate.slug, - TypeDateTime.slug, - TypeSelectOne.slug, - TypeSelectMany.slug, +var AllTypeEnums = []TypeEnum{ + TypeUnknown, + TypeString, + TypeText, + TypeCheckbox, + TypeInt, + TypeFloat, + TypeDate, + TypeDateTime, + TypeSelectOne, + TypeSelectMany, } -func NewTypeEnum(s string) TypeEnum { - switch s { - case TypeString.slug: - return TypeString - case TypeText.slug: - return TypeText - case TypeCheckbox.slug: - return TypeCheckbox - case TypeInt.slug: - return TypeInt - case TypeFloat.slug: - return TypeFloat - case TypeDate.slug: - return TypeDate - case TypeDateTime.slug: - return TypeDateTime - case TypeSelectOne.slug: - return TypeSelectOne - case TypeSelectMany.slug: - return TypeSelectMany - } - return TypeUnknown +type QualityEnum string + +const ( + QualityNeutral = QualityEnum("neutral") + QualityBad = QualityEnum("bad") + QualityPerfect = QualityEnum("perfect") +) + +var AllQualityEnums = []QualityEnum{ + QualityNeutral, + QualityBad, + QualityPerfect, } type BaseMetaFeature struct { @@ -84,3 +68,66 @@ type Color struct { Name string `gorm:"unique; not null"` HexValue string `gorm:"unique; not null"` } + +type SelectOneMetaFeature struct { + BaseID uint `gorm:"not null"` + Value string `gorm:"not null"` + Quality QualityEnum `gorm:"not null"` +} + +type SelectOneFeature struct { + FeatureID uint `gorm:"not null"` + DogID uint `gorm:"not null"` + Value string `gorm:"not null"` +} + +type CheckBoxMetaFeature struct { + BaseID uint `gorm:"not null"` + Value bool `gorm:"not null"` + Quality QualityEnum `gorm:"not null"` +} + +type CheckBoxFeature struct { + FeatureID uint `gorm:"not null"` + DogID uint `gorm:"not null"` + Value bool `gorm:"not null"` +} + +type StringMetaFeature struct { + BaseID uint `gorm:"not null"` + MinLength uint `gorm:"not null"` + MaxLength uint `gorm:"not null"` +} + +type StringFeature struct { + FeatureID uint `gorm:"not null"` + DogID uint `gorm:"not null"` + Value string `gorm:"not null"` + Quality QualityEnum `gorm:"not null"` +} + +type TextMetaFeature struct { + BaseID uint `gorm:"not null"` + MinLength uint `gorm:"not null"` + MaxLength uint `gorm:"not null"` +} + +type TextFeature struct { + FeatureID uint `gorm:"not null"` + DogID uint `gorm:"not null"` + Value string `gorm:"not null"` + Quality QualityEnum `gorm:"not null"` +} + +type IntegerMetaFeature struct { + BaseID uint `gorm:"not null"` + Value int64 `gorm:"not null"` + SmallerThan bool `gorm:"not null"` + Quality QualityEnum `gorm:"not null"` +} + +type IntegerFeature struct { + FeatureID uint `gorm:"not null"` + DogID uint `gorm:"not null"` + Value int64 `gorm:"not null"` +} diff --git a/mygorm/gorm_test.go b/mygorm/gorm_test.go index 8a97363..a04cf03 100644 --- a/mygorm/gorm_test.go +++ b/mygorm/gorm_test.go @@ -189,11 +189,11 @@ func TestBaseMetaFeatureAndFeatureGroups(t *testing.T) { } // create BaseMetaFeature - f1 := &BaseMetaFeature{Name: "pigmente2", GroupID: fg3.ID, ShortName: "pigments2"} - f2 := &BaseMetaFeature{Name: "pigmente3", GroupID: fg3.ID, ShortName: "pigments3"} - f3 := &BaseMetaFeature{Name: "pigmente4", GroupID: fg3.ID, ShortName: "pigments4"} - f4 := &BaseMetaFeature{Name: "teeth", GroupID: fg4.ID, ShortName: "teeth"} - f5 := &BaseMetaFeature{Name: "teeth2", GroupID: fg4.ID, ShortName: "teeth2"} + f1 := &BaseMetaFeature{Name: "pigmente2", GroupID: fg3.ID, ShortName: "pigments2", Type: TypeText} + f2 := &BaseMetaFeature{Name: "pigmente3", GroupID: fg3.ID, ShortName: "pigments3", Type: TypeString} + f3 := &BaseMetaFeature{Name: "pigmente4", GroupID: fg3.ID, ShortName: "pigments4", Type: TypeCheckbox} + f4 := &BaseMetaFeature{Name: "teeth", GroupID: fg4.ID, ShortName: "teeth", Type: TypeDate} + f5 := &BaseMetaFeature{Name: "teeth2", GroupID: fg4.ID, ShortName: "teeth2", Type: TypeFloat} // f1 ------------------------ @@ -205,7 +205,11 @@ func TestBaseMetaFeatureAndFeatureGroups(t *testing.T) { // read from DB f1New := &BaseMetaFeature{} if err := db.First(f1New, f1.ID).Error; err != nil { - t.Fatalf("Unable to read the feature 1 , %v", err) + t.Fatalf("Unable to read the feature 1, %v", err) + } + + if f1New.Type != TypeText { + t.Errorf("f1New should have got '%s' as type but instead it is '%s': %s", TypeText, f1New.Type, spew.Sdump(f1New)) } // checking the association From ed2b6a419ef21fae3bd91406f8c214f44ed8eb80 Mon Sep 17 00:00:00 2001 From: Alcione Date: Mon, 13 Jun 2022 16:14:38 +0200 Subject: [PATCH 11/13] add some meta data --- mygorm/breedingbook.go | 68 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/mygorm/breedingbook.go b/mygorm/breedingbook.go index 88e4839..987ca12 100644 --- a/mygorm/breedingbook.go +++ b/mygorm/breedingbook.go @@ -2,21 +2,22 @@ package mygorm import ( "github.com/jinzhu/gorm" + "time" ) type TypeEnum string const ( TypeUnknown = TypeEnum("") - TypeString = TypeEnum("string") // done - TypeText = TypeEnum("text") // done - TypeCheckbox = TypeEnum("checkbox") // done - TypeInt = TypeEnum("integer") // int64 - TypeFloat = TypeEnum("floating point") //float64 - TypeDate = TypeEnum("date") //time.Time - TypeDateTime = TypeEnum("timestamp") //time.Time - TypeSelectOne = TypeEnum("select one") // string done - TypeSelectMany = TypeEnum("select many") // []string + TypeString = TypeEnum("string") + TypeText = TypeEnum("text") + TypeCheckbox = TypeEnum("checkbox") + TypeInt = TypeEnum("integer") + TypeFloat = TypeEnum("floating point") + TypeDate = TypeEnum("date") + TypeDateTime = TypeEnum("timestamp") + TypeSelectOne = TypeEnum("select one") + TypeSelectMany = TypeEnum("select many") // []string ) var AllTypeEnums = []TypeEnum{ @@ -120,10 +121,13 @@ type TextFeature struct { } type IntegerMetaFeature struct { - BaseID uint `gorm:"not null"` - Value int64 `gorm:"not null"` - SmallerThan bool `gorm:"not null"` - Quality QualityEnum `gorm:"not null"` + BaseID uint `gorm:"not null"` + NeutralMin int64 `gorm:"not null"` + NeutralMax int64 `gorm:"not null"` + BadMin int64 `gorm:"not null"` + BadMax int64 `gorm:"not null"` + PerfectMin int64 `gorm:"not null"` + PerfectMax int64 `gorm:"not null"` } type IntegerFeature struct { @@ -131,3 +135,41 @@ type IntegerFeature struct { DogID uint `gorm:"not null"` Value int64 `gorm:"not null"` } + +type FloatMetaFeature struct { + BaseID uint `gorm:"not null"` + NeutralMin float64 `gorm:"not null"` + NeutralMax float64 `gorm:"not null"` + BadMin float64 `gorm:"not null"` + BadMax float64 `gorm:"not null"` + PerfectMin float64 `gorm:"not null"` + PerfectMax float64 `gorm:"not null"` +} + +type FloatFeature struct { + FeatureID uint `gorm:"not null"` + DogID uint `gorm:"not null"` + Value float64 `gorm:"not null"` +} + +type DateMetaFeature struct { + BaseID uint `gorm:"not null"` + // still decide +} + +type DateFeature struct { + FeatureID uint `gorm:"not null"` + DogID uint `gorm:"not null"` + Value time.Time `gorm:"not null"` +} + +type TimestampMetaFeature struct { + BaseID uint `gorm:"not null"` + // still decide +} + +type TimestampFeature struct { + FeatureID uint `gorm:"not null"` + DogID uint `gorm:"not null"` + Value time.Time `gorm:"not null"` +} From b631336691ef50442f129f274743fbd5602e8fe7 Mon Sep 17 00:00:00 2001 From: Alcione Date: Thu, 16 Jun 2022 14:03:14 +0200 Subject: [PATCH 12/13] add new meta data --- mygorm/breedingbook.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mygorm/breedingbook.go b/mygorm/breedingbook.go index 987ca12..16794aa 100644 --- a/mygorm/breedingbook.go +++ b/mygorm/breedingbook.go @@ -173,3 +173,15 @@ type TimestampFeature struct { DogID uint `gorm:"not null"` Value time.Time `gorm:"not null"` } + +type SelectManyMetaFeature struct { + BaseID uint `gorm:"not null"` + Value string `gorm:"not null"` + Quality QualityEnum `gorm:"not null"` +} + +type SelectManyFeature struct { + FeatureID uint `gorm:"not null"` + DogID uint `gorm:"not null"` + Values []string `gorm:"not null"` +} From b05ec3fc42b188776a57ff480e7155e50d57f652 Mon Sep 17 00:00:00 2001 From: Alcione Date: Mon, 20 Jun 2022 16:10:33 +0200 Subject: [PATCH 13/13] changing the dog struct and meta data --- mygorm/breedingbook.go | 109 ++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 67 deletions(-) diff --git a/mygorm/breedingbook.go b/mygorm/breedingbook.go index 16794aa..ed3d84e 100644 --- a/mygorm/breedingbook.go +++ b/mygorm/breedingbook.go @@ -47,6 +47,26 @@ var AllQualityEnums = []QualityEnum{ QualityPerfect, } +type DogTest struct { + gorm.Model + Name string `gorm:"unique; not null"` + SelectOne1 string `gorm:"not null"` + SelectOne2 string `gorm:"not null"` + SelectOne3 string `gorm:"not null"` + CheckBox1 bool `gorm:"not null"` + CheckBox2 bool `gorm:"not null"` + CheckBox3 bool `gorm:"not null"` + String1 string `gorm:"not null"` + String1Quality QualityEnum `gorm:"not null"` + Text1 string `gorm:"not null"` + Text1Quality QualityEnum `gorm:"not null"` + Integer1 int64 `gorm:"not null"` + Float1 float64 `gorm:"not null"` + Date1 time.Time `gorm:"not null"` + Timestamp1 time.Time `gorm:"not null"` + SelectMany1 []string `gorm:"not null"` +} + type BaseMetaFeature struct { gorm.Model Name string `gorm:"unique; not null"` @@ -71,57 +91,37 @@ type Color struct { } type SelectOneMetaFeature struct { - BaseID uint `gorm:"not null"` - Value string `gorm:"not null"` - Quality QualityEnum `gorm:"not null"` -} - -type SelectOneFeature struct { - FeatureID uint `gorm:"not null"` - DogID uint `gorm:"not null"` - Value string `gorm:"not null"` + BaseID uint `gorm:"not null"` + ColumnNum int `gorm:"not null"` + Order int `gorm:"not null"` + Value string `gorm:"not null"` + Quality QualityEnum `gorm:"not null"` } type CheckBoxMetaFeature struct { - BaseID uint `gorm:"not null"` - Value bool `gorm:"not null"` - Quality QualityEnum `gorm:"not null"` -} - -type CheckBoxFeature struct { - FeatureID uint `gorm:"not null"` - DogID uint `gorm:"not null"` - Value bool `gorm:"not null"` + BaseID uint `gorm:"not null"` + ColumnNum int `gorm:"not null"` + QualityChecked QualityEnum `gorm:"not null"` + QualityUnchecked QualityEnum `gorm:"not null"` } type StringMetaFeature struct { BaseID uint `gorm:"not null"` + ColumnNum int `gorm:"not null"` MinLength uint `gorm:"not null"` MaxLength uint `gorm:"not null"` } -type StringFeature struct { - FeatureID uint `gorm:"not null"` - DogID uint `gorm:"not null"` - Value string `gorm:"not null"` - Quality QualityEnum `gorm:"not null"` -} - type TextMetaFeature struct { BaseID uint `gorm:"not null"` + ColumnNum int `gorm:"not null"` MinLength uint `gorm:"not null"` MaxLength uint `gorm:"not null"` } -type TextFeature struct { - FeatureID uint `gorm:"not null"` - DogID uint `gorm:"not null"` - Value string `gorm:"not null"` - Quality QualityEnum `gorm:"not null"` -} - type IntegerMetaFeature struct { BaseID uint `gorm:"not null"` + ColumnNum int `gorm:"not null"` NeutralMin int64 `gorm:"not null"` NeutralMax int64 `gorm:"not null"` BadMin int64 `gorm:"not null"` @@ -130,14 +130,9 @@ type IntegerMetaFeature struct { PerfectMax int64 `gorm:"not null"` } -type IntegerFeature struct { - FeatureID uint `gorm:"not null"` - DogID uint `gorm:"not null"` - Value int64 `gorm:"not null"` -} - type FloatMetaFeature struct { BaseID uint `gorm:"not null"` + ColumnNum int `gorm:"not null"` NeutralMin float64 `gorm:"not null"` NeutralMax float64 `gorm:"not null"` BadMin float64 `gorm:"not null"` @@ -146,42 +141,22 @@ type FloatMetaFeature struct { PerfectMax float64 `gorm:"not null"` } -type FloatFeature struct { - FeatureID uint `gorm:"not null"` - DogID uint `gorm:"not null"` - Value float64 `gorm:"not null"` -} - type DateMetaFeature struct { - BaseID uint `gorm:"not null"` + BaseID uint `gorm:"not null"` + ColumnNum int `gorm:"not null"` // still decide } -type DateFeature struct { - FeatureID uint `gorm:"not null"` - DogID uint `gorm:"not null"` - Value time.Time `gorm:"not null"` -} - type TimestampMetaFeature struct { - BaseID uint `gorm:"not null"` + BaseID uint `gorm:"not null"` + ColumnNum int `gorm:"not null"` // still decide } -type TimestampFeature struct { - FeatureID uint `gorm:"not null"` - DogID uint `gorm:"not null"` - Value time.Time `gorm:"not null"` -} - type SelectManyMetaFeature struct { - BaseID uint `gorm:"not null"` - Value string `gorm:"not null"` - Quality QualityEnum `gorm:"not null"` -} - -type SelectManyFeature struct { - FeatureID uint `gorm:"not null"` - DogID uint `gorm:"not null"` - Values []string `gorm:"not null"` + BaseID uint `gorm:"not null"` + ColumnNum int `gorm:"not null"` + Order int `gorm:"not null"` + Value string `gorm:"not null"` + Quality QualityEnum `gorm:"not null"` }