Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
jairad26 committed Jan 3, 2025
1 parent b483510 commit 0cbe924
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
11 changes: 3 additions & 8 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,14 @@ func Upsert[T any](db *DB, object T, ns ...uint64) (uint64, T, bool, error) {
return 0, object, false, err
}

if gid != 0 {
gid, _, err = getByGidWithObject[T](ctx, n, gid, object)
if err != nil && err != utils.ErrNoObjFound {
return 0, object, false, err
}
wasFound = err == nil
} else if cf != nil {
gid, _, err = getByConstrainedFieldWithObject[T](ctx, n, *cf, object)
if gid != 0 || cf != nil {
gid, err = getExistingObject[T](ctx, n, gid, cf, object)
if err != nil && err != utils.ErrNoObjFound {
return 0, object, false, err
}
wasFound = err == nil
}

if gid == 0 {
gid, err = db.z.nextUID()
if err != nil {
Expand Down
File renamed without changes.
12 changes: 2 additions & 10 deletions mutation_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,8 @@ func getUidOrMutate[T any](ctx context.Context, db *DB, n *Namespace, object T)
if err != nil {
return 0, err
}
if gid != 0 {
gid, _, err = getByGidWithObject[T](ctx, n, gid, object)
if err != nil && err != utils.ErrNoObjFound {
return 0, err
}
if err == nil {
return gid, nil
}
} else if cf != nil {
gid, _, err = getByConstrainedFieldWithObject[T](ctx, n, *cf, object)
if gid != 0 || cf != nil {
gid, err = getExistingObject(ctx, n, gid, cf, object)
if err != nil && err != utils.ErrNoObjFound {
return 0, err
}
Expand Down
13 changes: 13 additions & 0 deletions query_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,16 @@ func executeQuery[T any](ctx context.Context, n *Namespace, queryParams QueryPar

return gids, objs, nil
}

func getExistingObject[T any](ctx context.Context, n *Namespace, gid uint64, cf *ConstrainedField, object T) (uint64, error) {
var err error
if gid != 0 {
gid, _, err = getByGidWithObject[T](ctx, n, gid, object)
} else if cf != nil {
gid, _, err = getByConstrainedFieldWithObject[T](ctx, n, *cf, object)
}
if err != nil {
return 0, err
}
return gid, nil
}

0 comments on commit 0cbe924

Please sign in to comment.