-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathref.go
More file actions
43 lines (36 loc) · 1.31 KB
/
ref.go
File metadata and controls
43 lines (36 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package debefix
import (
"github.com/google/uuid"
)
// InternalIDRef is a reference to one table's row by internal id.
// It refers to an entire row instead of a specific field, so it don't implement Value. Use ValueForField to return
// a Value implementation for one of its fields.
// It implements QueryRow, and can return a UpdateQuery.
type InternalIDRef struct {
NotAValue
TableID TableID
InternalID uuid.UUID
}
func NewInternalIDRef(tableID TableID, internalID uuid.UUID) InternalIDRef {
return InternalIDRef{
TableID: tableID,
InternalID: internalID,
}
}
var _ QueryRow = (*InternalIDRef)(nil)
// ValueForField returns a Value that resolves one specific field of the referenced table row.
func (v InternalIDRef) ValueForField(fieldName string) ValueInternalIDData {
return ValueInternalID(v.TableID, v.InternalID, fieldName)
}
// QueryRow is the implementation of the QueryRow interface.
func (v InternalIDRef) QueryRow(data *Data) (QueryRowResult, error) {
row, err := data.FindInternalIDRow(v.TableID, v.InternalID)
if err != nil {
return QueryRowResult{}, err
}
return QueryRowResult{TableID: v.TableID, Row: row}, nil
}
// UpdateQuery returns an UpdateQuery targetting the referenced table row.
func (v InternalIDRef) UpdateQuery(keyFields []string) UpdateQuery {
return UpdateQueryRow(v, keyFields)
}