fisch/types.go
2025-03-04 20:18:55 +01:00

100 lines
1.5 KiB
Go
Executable file

package main
import (
"database/sql"
"fmt"
)
// Web
type NavItem struct {
Caption string
Destination string
}
func NewNavItem(caption, destination string) NavItem {
return NavItem{caption, destination}
}
type Stylename string
func NewStyleItemList(stylenames ...Stylename) []Stylename {
return stylenames
}
type TableColumns []string
type TableRow struct {
Columns TableColumns
Id int
}
type Table struct {
Collumns TableColumns
Rows []TableRow
}
// Database
type Location struct {
Id sql.NullInt64
Parent sql.NullInt64
Name sql.NullString
Description sql.NullString
}
func (l *Location) ToTableRow() TableRow {
columns := make(TableColumns, 4)
tr := TableRow{}
if l.Id.Valid {
columns[0] = fmt.Sprintf("%d", l.Id.Int64)
tr.Id = int(l.Id.Int64)
} else {
columns[0] = "NULL"
tr.Id = -1
}
if l.Parent.Valid {
columns[1] = fmt.Sprintf("%d", l.Parent.Int64)
} else {
columns[1] = "NULL"
}
if l.Name.Valid {
columns[2] = l.Name.String
} else {
columns[2] = "NULL"
}
if l.Description.Valid {
columns[3] = l.Description.String
} else {
columns[3] = "NULL"
}
tr.Columns = columns
return tr
}
func (l *Location) GetParent() *Location {
return nil
}
type Container struct {
Id sql.NullInt64
Name sql.NullString
}
type Part struct {
Id sql.NullInt64
Name sql.NullString
Tags sql.NullString
Location Location
Container Container
}
// Interfaces
type DatabaseType interface {
ToTableRow() TableRow
}