Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion v2/arangodb/collection_documents_replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type CollectionDocumentReplaceResponseReader interface {
}

type CollectionDocumentReplaceResponse struct {
DocumentMeta
DocumentMetaWithOldRev
shared.ResponseStruct `json:",inline"`
Old, New interface{}
}
Expand Down
18 changes: 9 additions & 9 deletions v2/arangodb/collection_documents_replace_impl.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,13 +59,13 @@ func (c collectionDocumentReplace) ReplaceDocumentWithOptions(ctx context.Contex
}

response := struct {
*DocumentMeta `json:",inline"`
*shared.ResponseStruct `json:",inline"`
Old *UnmarshalInto `json:"old,omitempty"`
New *UnmarshalInto `json:"new,omitempty"`
*DocumentMetaWithOldRev `json:",inline"`
*shared.ResponseStruct `json:",inline"`
Old *UnmarshalInto `json:"old,omitempty"`
New *UnmarshalInto `json:"new,omitempty"`
}{
DocumentMeta: &meta.DocumentMeta,
ResponseStruct: &meta.ResponseStruct,
DocumentMetaWithOldRev: &meta.DocumentMetaWithOldRev,
ResponseStruct: &meta.ResponseStruct,

Old: newUnmarshalInto(meta.Old),
New: newUnmarshalInto(meta.New),
Expand Down Expand Up @@ -142,7 +142,7 @@ type collectionDocumentReplaceResponseReader struct {
array *connection.Array
options *CollectionDocumentReplaceOptions
response struct {
*DocumentMeta
*DocumentMetaWithOldRev
*shared.ResponseStruct `json:",inline"`
Old *UnmarshalInto `json:"old,omitempty"`
New *UnmarshalInto `json:"new,omitempty"`
Expand All @@ -161,7 +161,7 @@ func (c *collectionDocumentReplaceResponseReader) Read() (CollectionDocumentRepl
meta.New = c.options.NewObject
}

c.response.DocumentMeta = &meta.DocumentMeta
c.response.DocumentMetaWithOldRev = &meta.DocumentMetaWithOldRev
c.response.ResponseStruct = &meta.ResponseStruct

if err := c.array.Unmarshal(&c.response); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion v2/arangodb/collection_documents_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type CollectionDocumentUpdateResponseReader interface {
}

type CollectionDocumentUpdateResponse struct {
DocumentMeta
DocumentMetaWithOldRev
shared.ResponseStruct `json:",inline"`
Old, New interface{}
}
Expand Down
18 changes: 9 additions & 9 deletions v2/arangodb/collection_documents_update_impl.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2020-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,13 +59,13 @@ func (c collectionDocumentUpdate) UpdateDocumentWithOptions(ctx context.Context,
}

response := struct {
*DocumentMeta `json:",inline"`
*shared.ResponseStruct `json:",inline"`
Old *UnmarshalInto `json:"old,omitempty"`
New *UnmarshalInto `json:"new,omitempty"`
*DocumentMetaWithOldRev `json:",inline"`
*shared.ResponseStruct `json:",inline"`
Old *UnmarshalInto `json:"old,omitempty"`
New *UnmarshalInto `json:"new,omitempty"`
}{
DocumentMeta: &meta.DocumentMeta,
ResponseStruct: &meta.ResponseStruct,
DocumentMetaWithOldRev: &meta.DocumentMetaWithOldRev,
ResponseStruct: &meta.ResponseStruct,

Old: newUnmarshalInto(meta.Old),
New: newUnmarshalInto(meta.New),
Expand Down Expand Up @@ -142,7 +142,7 @@ type collectionDocumentUpdateResponseReader struct {
array *connection.Array
options *CollectionDocumentUpdateOptions
response struct {
*DocumentMeta
*DocumentMetaWithOldRev
*shared.ResponseStruct `json:",inline"`
Old *UnmarshalInto `json:"old,omitempty"`
New *UnmarshalInto `json:"new,omitempty"`
Expand All @@ -161,7 +161,7 @@ func (c *collectionDocumentUpdateResponseReader) Read() (CollectionDocumentUpdat
meta.New = c.options.NewObject
}

c.response.DocumentMeta = &meta.DocumentMeta
c.response.DocumentMetaWithOldRev = &meta.DocumentMetaWithOldRev
c.response.ResponseStruct = &meta.ResponseStruct

if err := c.array.Unmarshal(&c.response); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion v2/arangodb/meta.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2020-2021 ArangoDB GmbH, Cologne, Germany
// Copyright 2020-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,6 +44,11 @@ type DocumentMeta struct {
Rev string `json:"_rev,omitempty"`
}

type DocumentMetaWithOldRev struct {
DocumentMeta
OldRev string `json:"_oldRev,omitempty"`
}

// validateKey returns an error if the given key is empty otherwise invalid.
func validateKey(key string) error {
if key == "" {
Expand Down
29 changes: 28 additions & 1 deletion v2/tests/database_collection_doc_replace_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -126,6 +126,33 @@ func Test_DatabaseCollectionDocReplaceIgnoreRevs(t *testing.T) {
})
}

func Test_DatabaseCollectionDocReplaceReturnOldRev(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
WithDatabase(t, client, nil, func(db arangodb.Database) {
WithCollection(t, db, nil, func(col arangodb.Collection) {
withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) {
doc := DocWithRev{
Name: "test-ORG",
}

metaOrg, err := col.CreateDocument(ctx, doc)
require.NoError(t, err)

docReplace := DocWithRev{
Name: "test-REPLACED",
}

t.Run("OldRev should match", func(t *testing.T) {
metaRep, err := col.ReplaceDocumentWithOptions(ctx, metaOrg.Key, docReplace, nil)
require.NoError(t, err)
require.Equal(t, metaOrg.Rev, metaRep.OldRev)
})
})
})
})
})
}

func Test_DatabaseCollectionDocReplaceSilent(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
WithDatabase(t, client, nil, func(db arangodb.Database) {
Expand Down
29 changes: 28 additions & 1 deletion v2/tests/database_collection_doc_update_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2025 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -126,6 +126,33 @@ func Test_DatabaseCollectionDocUpdateIgnoreRevs(t *testing.T) {
})
}

func Test_DatabaseCollectionDocUpdateReturnOldRev(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
WithDatabase(t, client, nil, func(db arangodb.Database) {
WithCollection(t, db, nil, func(col arangodb.Collection) {
withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) {
doc := DocWithRev{
Name: "test-ORG",
}

metaOrg, err := col.CreateDocument(ctx, doc)
require.NoError(t, err)

docUpdate := DocWithRev{
Name: "test-UPDATED",
}

t.Run("OldRev should match", func(t *testing.T) {
metaRep, err := col.UpdateDocumentWithOptions(ctx, metaOrg.Key, docUpdate, nil)
require.NoError(t, err)
require.Equal(t, metaOrg.Rev, metaRep.OldRev)
})
})
})
})
})
}

func Test_DatabaseCollectionDocUpdateKeepNull(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
WithDatabase(t, client, nil, func(db arangodb.Database) {
Expand Down