(ctx context.Context, key string, target ...string)
| 117 | }) |
| 118 | } |
| 119 | func (h *Store[H]) Latest(ctx context.Context, key string, target ...string) ([]*Commit[H], error) { |
| 120 | |
| 121 | wheres := make([]string, 0, 2) |
| 122 | args := make([]interface{}, 0, 2) |
| 123 | if key == "" && len(target) == 0 { |
| 124 | return nil, errors.New("key or target is required") |
| 125 | } |
| 126 | if key != "" { |
| 127 | wheres = append(wheres, "`key` = ?") |
| 128 | args = append(args, key) |
| 129 | } |
| 130 | if len(target) > 0 { |
| 131 | if len(target) > 1 { |
| 132 | wheres = append(wheres, "`target` in ?") |
| 133 | args = append(args, target) |
| 134 | } else { |
| 135 | wheres = append(wheres, "`target` = ?") |
| 136 | args = append(args, target[0]) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | latest := make([]*Latest, 0) |
| 141 | err := h.db.DB(ctx).Debug().Table(h.latestTableName).Where(strings.Join(wheres, " and "), args...).Find(&latest).Error |
| 142 | |
| 143 | if err != nil { |
| 144 | return nil, err |
| 145 | } |
| 146 | latestUUUID := utils.SliceToSlice(latest, func(l *Latest) string { return l.Latest }) |
| 147 | ho := make([]*Commit[H], 0, len(latest)) |
| 148 | if len(latestUUUID) == 0 { |
| 149 | return nil, nil |
| 150 | } |
| 151 | if len(latestUUUID) > 1 { |
| 152 | err = h.db.DB(ctx).Table(h.commitTableName).Where("`uuid` in ?", latestUUUID).Find(&ho).Error |
| 153 | |
| 154 | } else { |
| 155 | err = h.db.DB(ctx).Table(h.commitTableName).Where("`uuid` = ?", latestUUUID[0]).Find(&ho).Error |
| 156 | } |
| 157 | if err != nil { |
| 158 | return nil, err |
| 159 | } |
| 160 | return ho, nil |
| 161 | } |
| 162 | func (h *Store[H]) Get(ctx context.Context, uuid string) (*Commit[H], error) { |
| 163 | var commit = new(Commit[H]) |
| 164 | err := h.db.DB(ctx).Table(h.commitTableName).Where("`uuid` = ?", uuid).First(commit).Error |
nothing calls this directly
no outgoing calls
no test coverage detected