diff --git a/api.go b/api.go index 22ff6a7..e8d759f 100644 --- a/api.go +++ b/api.go @@ -103,6 +103,8 @@ func valueToValType(v any) *api.Value { } func Create[T any](ctx context.Context, n *Namespace, object *T) (uint64, *T, error){ + n.db.mutex.Lock() + defer n.db.mutex.Unlock() uids, err := n.db.z.nextUIDs(&pb.Num{Val: uint64(1), Type: pb.Num_UID}) if err != nil { return 0, object, err @@ -152,9 +154,6 @@ func Create[T any](ctx context.Context, n *Namespace, object *T) (uint64, *T, er } ctx = x.AttachNamespace(ctx, n.ID()) - n.db.mutex.Lock() - defer n.db.mutex.Unlock() - err = n.alterSchemaWithParsed(ctx, sch) if err != nil { return 0, object, err