Skip to content

Commit

Permalink
Where as interface
Browse files Browse the repository at this point in the history
  • Loading branch information
latolukasz committed Jan 8, 2024
1 parent 9925e42 commit 5cf972b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 5 additions & 1 deletion get_by_unique_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ func GetByUniqueIndex[E any](orm ORM, indexName string, attributes ...any) *E {
previousID, inUse := cache.HGet(orm, hSetKey, hField)
if inUse {
id, _ := strconv.ParseUint(previousID, 10, 64)
return GetByID[E](orm, id)
entity := GetByID[E](orm, id)
if entity == nil {
cache.HDel(orm, hSetKey, hField)
}
return entity
}
return nil
}
6 changes: 2 additions & 4 deletions uinque_keys_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ func LoadUniqueKeys(orm ORM, debug bool) {
selectWhere.Append(where.String())

if debug {
poolTemplate := "\u001B[1m\x1b[38;2;175;175;175;48;2;255;255;255m%-94s\u001B[0m\x1b[0m\u001B[0m\n"
row := beeORMLogo
title := fmt.Sprintf("Loading unique key '%s' from %s into redis", indexName, schema.GetType().String())
row += fmt.Sprintf(poolTemplate, title)
row := fmt.Sprintf("Loading unique key '%s' from %s into redis", indexName, schema.GetType().String())
print(row)
print(".")
}
total := uint64(0)
db.QueryRow(orm, NewWhere(whereCount), &total)
if total == 0 {
cache.HSet(orm, hSetKey, "", 0)
if debug {
print(strings.Repeat(".", 100))
println("[DONE]")
Expand Down

0 comments on commit 5cf972b

Please sign in to comment.