(ctx context.Context, val *anypb.Any, db *gorm.DB)
| 154 | type queryBuilder idm.WorkspaceSingleQuery |
| 155 | |
| 156 | func (c *queryBuilder) Convert(ctx context.Context, val *anypb.Any, db *gorm.DB) (*gorm.DB, bool, error) { |
| 157 | |
| 158 | q := new(idm.WorkspaceSingleQuery) |
| 159 | if err := anypb.UnmarshalTo(val, q, proto.UnmarshalOptions{}); err != nil { |
| 160 | return nil, false, nil |
| 161 | } |
| 162 | count := 0 |
| 163 | |
| 164 | if len(q.Uuid) > 0 { |
| 165 | count++ |
| 166 | db = sql.GormConvertString(db, q.Not, "uuid", q.Uuid) |
| 167 | } |
| 168 | |
| 169 | if len(q.Slug) > 0 { |
| 170 | count++ |
| 171 | db = sql.GormConvertString(db, q.Not, "slug", q.Slug) |
| 172 | } |
| 173 | |
| 174 | if len(q.Label) > 0 { |
| 175 | count++ |
| 176 | db = sql.GormConvertString(db, q.Not, "label", q.Label) |
| 177 | } |
| 178 | |
| 179 | if q.Scope != idm.WorkspaceScope_ANY { |
| 180 | count++ |
| 181 | if q.Not { |
| 182 | db = db.Not(map[string]interface{}{"scope": q.Scope}) |
| 183 | } else { |
| 184 | db = db.Where(map[string]interface{}{"scope": q.Scope}) |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | if q.LastUpdated != "" { |
| 189 | if lt, d, e := q.ParseLastUpdated(); e == nil { |
| 190 | ref := int32(time.Now().Add(-d).Unix()) |
| 191 | count++ |
| 192 | if lt || q.Not { |
| 193 | db = db.Where("last_updated < ?", ref) |
| 194 | } else { |
| 195 | db = db.Where("last_updated > ?", ref) |
| 196 | } |
| 197 | } else { |
| 198 | return db, false, e |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if q.HasAttribute != "" { |
| 203 | count++ |
| 204 | db = sql.GormConvertString(db, q.Not, "attributes", `*"`+q.HasAttribute+`":*`) |
| 205 | } |
| 206 | if q.AttributeName != "" && q.AttributeValue != "" { |
| 207 | count++ |
| 208 | db = sql.GormConvertString(db, q.Not, "attributes", `*"`+q.AttributeName+`":"`+q.AttributeValue+`"*`) |
| 209 | } |
| 210 | |
| 211 | return db, count > 0, nil |
| 212 | |
| 213 | } |
nothing calls this directly
no test coverage detected