No more GORM.
Too much magic. I'll just write a JOIN and create small, composable data types to represent my domain objects. grug brain smile, complexity demon no visit todaymain
parent
4fec3f685b
commit
d9671822b7
@ -1,27 +1,34 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gorm.io/gorm"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Area struct {
|
type Area struct {
|
||||||
gorm.Model
|
Uid, Name, Flags, Color, Texture sql.NullString
|
||||||
Uid string
|
|
||||||
Name, Flags string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Room struct {
|
type Room struct {
|
||||||
gorm.Model
|
Uid, Name, Building, Info, Notes, Flags sql.NullString
|
||||||
Uid string
|
Area Area
|
||||||
Name, Area string
|
AreaName sql.NullString
|
||||||
Building string
|
Norecall, Noportal sql.NullInt64
|
||||||
Info, Notes, Flags string
|
Exits []Exit
|
||||||
X, Y, Z int
|
|
||||||
Norecall, Noportal int
|
|
||||||
Exits []Exit `gorm:"foreignKey:Fromuid"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Exit struct {
|
type Exit struct {
|
||||||
gorm.Model
|
Dir sql.NullString
|
||||||
Dir, Fromuid, Touid, Level string
|
Fromuid, Touid sql.NullString
|
||||||
|
Level int
|
||||||
|
}
|
||||||
|
|
||||||
|
type RoomExit struct {
|
||||||
|
Room
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
|
||||||
|
func (re RoomExit) String() string {
|
||||||
|
|
||||||
|
return fmt.Sprintf("[%s(%s) |%s> %s]", re.Name.String, re.Uid.String, re.Dir.String, re.Touid.String)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue