-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchanges.go
65 lines (59 loc) · 1.47 KB
/
changes.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package dal
// Changes accumulates DB changes
type Changes struct {
records []Record
}
// IsChanged returns true if entity changed
func (changes *Changes) IsChanged(record Record) bool {
for _, r := range changes.records {
if r == record {
return true
} else if EqualKeys(r.Key(), record.Key()) {
return true
}
}
return false
}
// FlagAsChanged flags a record as changed
func (changes *Changes) FlagAsChanged(record Record) {
if record == nil {
panic("record == nil")
}
record.MarkAsChanged()
for _, r := range changes.records {
if r == record {
return
} else if EqualKeys(record.Key(), r.Key()) {
return
}
}
changes.records = append(changes.records, record)
}
// Records returns list of entity holders
func (changes *Changes) Records() (records []Record) {
records = make([]Record, len(changes.records))
copy(records, changes.records)
return records
//return changes.records[:]
}
// HasChanges returns true if there are changes
func (changes *Changes) HasChanges() bool {
return len(changes.records) > 0
//// Records are always marked as changed
//for _, r := range changes.records {
// if r.HasChanged() {
// return true
// }
//}
//return false
}
// Remove as records are always marked as changed
//// ChangedRecords returns slice of changed records
//func (changes *Changes) ChangedRecords() (changed []Record) {
// for _, r := range changes.records {
// if r.HasChanged() {
// changed = append(changed, r)
// }
// }
// return changed
//}