diff --git a/backends/ent/annotations.go b/backends/ent/annotations.go index 040b447..617a531 100644 --- a/backends/ent/annotations.go +++ b/backends/ent/annotations.go @@ -182,6 +182,7 @@ func (backend *Backend) GetDocumentAnnotations(documentID string, names ...strin predicates := []predicate.Annotation{ annotation.HasDocumentWith(document.HasMetadataWith(metadata.NativeIDEQ(documentID))), + annotation.Not(annotation.HasNode()), } if len(names) > 0 { @@ -203,7 +204,10 @@ func (backend *Backend) GetDocumentsByAnnotation(name string, values ...string) return nil, errUninitializedClient } - predicates := []predicate.Annotation{annotation.NameEQ(name)} + predicates := []predicate.Annotation{ + annotation.NameEQ(name), + annotation.Not(annotation.HasNode()), + } if len(values) > 0 { predicates = append(predicates, annotation.ValueIn(values...)) @@ -241,6 +245,7 @@ func (backend *Backend) GetDocumentUniqueAnnotation(documentID, name string) (st ), annotation.NameEQ(name), annotation.IsUniqueEQ(true), + annotation.Not(annotation.HasNode()), ). Only(backend.ctx) if err != nil { diff --git a/backends/ent/annotations_test.go b/backends/ent/annotations_test.go index 491a1e2..5a248f0 100644 --- a/backends/ent/annotations_test.go +++ b/backends/ent/annotations_test.go @@ -243,7 +243,7 @@ func (as *annotationsSuite) TestBackend_GetDocumentsByAnnotation() { "test-value-" + strconv.Itoa(idx+2), "test-value-" + strconv.Itoa(idx+3), } { - _, err = as.Backend.Client().ExecContext(as.Backend.Context(), query, uniqueID, false, annotationName, value) + _, err = as.Backend.Ent().ExecContext(as.Backend.Context(), query, uniqueID, false, annotationName, value) as.Require().NoError(err) } } @@ -307,7 +307,7 @@ func (as *annotationsSuite) TestBackend_GetNodesByAnnotation() { "test-node-value-" + strconv.Itoa(idx+2), "test-node-value-" + strconv.Itoa(idx+3), } { - _, err := as.Backend.Client().ExecContext( + _, err := as.Backend.Ent().ExecContext( as.Backend.Context(), query, uniqueID, nodeUUID, false, annotationName, value, ) as.Require().NoError(err) @@ -362,7 +362,7 @@ func (as *annotationsSuite) TestBackend_GetDocumentUniqueAnnotation() { annotationValue := "unique-value" query := "INSERT INTO annotations (document_id, is_unique, name, value) VALUES (?, ?, ?, ?)" - _, err = as.Backend.Client().ExecContext(as.Backend.Context(), query, id, true, annotationName, annotationValue) + _, err = as.Backend.Ent().ExecContext(as.Backend.Context(), query, id, true, annotationName, annotationValue) as.Require().NoError(err) got, err := as.Backend.GetDocumentUniqueAnnotation(as.documents[0].GetMetadata().GetId(), annotationName) @@ -382,7 +382,7 @@ func (as *annotationsSuite) TestBackend_GetNodeUniqueAnnotation() { annotationValue := "unique-value" query := "INSERT INTO annotations (document_id, node_id, is_unique, name, value) VALUES (?, ?, ?, ?, ?)" - _, err = as.Backend.Client().ExecContext( + _, err = as.Backend.Ent().ExecContext( as.Backend.Context(), query, docUUID, nodeUUID, true, annotationName, annotationValue, ) as.Require().NoError(err) @@ -423,7 +423,7 @@ func (as *annotationsSuite) TestBackend_RemoveDocumentAnnotations() { as.Run(name, func() { for _, value := range []string{"test-value-1", "test-value-2", "test-value-3"} { - _, err = as.Backend.Client().ExecContext(ctx, query, uniqueID, false, annotationName, value) + _, err = as.Backend.Ent().ExecContext(ctx, query, uniqueID, false, annotationName, value) as.Require().NoError(err) } @@ -476,7 +476,7 @@ func (as *annotationsSuite) TestBackend_RemoveNodeAnnotations() { as.Run(name, func() { for _, value := range []string{"test-node-value-1", "test-node-value-2", "test-node-value-3"} { - _, err = as.Backend.Client().ExecContext(ctx, query, docUUID, nodeID, false, annotationName, value) + _, err = as.Backend.Ent().ExecContext(ctx, query, docUUID, nodeID, false, annotationName, value) as.Require().NoError(err) } @@ -632,7 +632,7 @@ func (as *annotationsSuite) TestBackend_SetNodeUniqueAnnotation() { //nolint:dup func (as *annotationsSuite) getTestResult(annotationName string) ent.Annotations { as.T().Helper() - result, err := as.Backend.Client().QueryContext( + result, err := as.Backend.Ent().QueryContext( as.Backend.Context(), "SELECT * FROM annotations WHERE name == ?", annotationName, diff --git a/backends/ent/backend.go b/backends/ent/backend.go index 25215b2..f85f79e 100644 --- a/backends/ent/backend.go +++ b/backends/ent/backend.go @@ -43,6 +43,10 @@ func NewBackend(opts ...Option) *Backend { return backend } +func (backend *Backend) Ent() *ent.Client { + return backend.client +} + func (backend *Backend) InitClient() error { if backend.Options == nil { backend.Options = NewBackendOptions() diff --git a/backends/ent/internal_test.go b/backends/ent/internal_test.go index 9d81424..62aa16f 100644 --- a/backends/ent/internal_test.go +++ b/backends/ent/internal_test.go @@ -6,15 +6,7 @@ package ent -import ( - "context" - - "github.com/protobom/storage/internal/backends/ent" -) - -func (backend *Backend) Client() *ent.Client { - return backend.client -} +import "context" func (backend *Backend) Context() context.Context { return backend.ctx diff --git a/backends/ent/store_test.go b/backends/ent/store_test.go index 29d51cd..214ce0c 100644 --- a/backends/ent/store_test.go +++ b/backends/ent/store_test.go @@ -65,7 +65,7 @@ func (ss *storeSuite) TestBackend_Store() { ss.Require().NoError(ss.Backend.Store(document, nil)) } - results, err := ss.Backend.Client().Document. + results, err := ss.Backend.Ent().Document. Query(). WithMetadata(). WithNodeList().