2025-06-12 11:44:57 +02:00
|
|
|
package fmp
|
|
|
|
|
2025-06-14 16:28:41 +02:00
|
|
|
type FmpTable struct {
|
2025-06-15 21:09:58 +02:00
|
|
|
ID uint64
|
|
|
|
Name string
|
2025-06-22 19:14:22 +02:00
|
|
|
Columns map[uint64]*FmpColumn
|
|
|
|
Records map[uint64]*FmpRecord
|
|
|
|
|
|
|
|
lastRecordID uint64
|
2025-06-15 21:09:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type FmpColumn struct {
|
2025-06-22 18:43:06 +02:00
|
|
|
Index uint64
|
2025-06-15 21:09:58 +02:00
|
|
|
Name string
|
|
|
|
Type FmpFieldType
|
|
|
|
DataType FmpDataType
|
|
|
|
StorageType FmpFieldStorageType
|
|
|
|
AutoEnter FmpAutoEnterOption
|
2025-06-16 11:29:48 +02:00
|
|
|
Repetitions uint8
|
2025-06-15 21:09:58 +02:00
|
|
|
Indexed bool
|
2025-06-14 16:28:41 +02:00
|
|
|
}
|
|
|
|
|
2025-06-22 18:43:06 +02:00
|
|
|
type FmpRecord struct {
|
2025-06-22 19:14:22 +02:00
|
|
|
Table *FmpTable
|
2025-06-22 18:43:06 +02:00
|
|
|
Index uint64
|
|
|
|
Values map[uint64]string
|
|
|
|
}
|
|
|
|
|
2025-06-22 19:14:22 +02:00
|
|
|
func (ctx *FmpFile) Table(name string) *FmpTable {
|
|
|
|
for _, table := range ctx.tables {
|
|
|
|
if table.Name == name {
|
|
|
|
return table
|
2025-06-12 15:12:34 +02:00
|
|
|
}
|
2025-06-22 19:14:22 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2025-06-15 21:09:58 +02:00
|
|
|
|
2025-06-22 19:14:22 +02:00
|
|
|
func (t *FmpTable) Column(name string) *FmpColumn {
|
|
|
|
for _, column := range t.Columns {
|
|
|
|
if column.Name == name {
|
|
|
|
return column
|
2025-06-15 21:09:58 +02:00
|
|
|
}
|
2025-06-22 19:14:22 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2025-06-15 21:09:58 +02:00
|
|
|
|
2025-06-22 19:14:22 +02:00
|
|
|
func (t *FmpTable) NewRecord(values map[string]string) (*FmpRecord, error) {
|
|
|
|
vals := make(map[uint64]string)
|
|
|
|
for k, v := range values {
|
|
|
|
col := t.Column(k)
|
|
|
|
vals[col.Index] = v
|
|
|
|
}
|
2025-06-22 18:43:06 +02:00
|
|
|
|
2025-06-22 19:14:22 +02:00
|
|
|
id := t.lastRecordID + 1
|
|
|
|
t.lastRecordID = id
|
|
|
|
t.Records[id] = &FmpRecord{Table: t, Index: id, Values: vals}
|
2025-06-22 18:43:06 +02:00
|
|
|
|
2025-06-22 19:14:22 +02:00
|
|
|
return t.Records[id], nil
|
|
|
|
}
|
2025-06-12 15:12:34 +02:00
|
|
|
|
2025-06-22 19:14:22 +02:00
|
|
|
func (r *FmpRecord) Value(name string) string {
|
|
|
|
return r.Values[r.Table.Column(name).Index]
|
2025-06-12 11:44:57 +02:00
|
|
|
}
|