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 astra/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (a *AstraAdmin) awaitStatus(ctx context.Context, databaseID string, opts Aw
case <-ctx.Done():
return ctx.Err()
case <-ticker.C:
db, err := a.DatabaseInfo(ctx, databaseID, options.DatabaseInfo().SetAPIOptions(opts.APIOptions))
db, err := a.DatabaseInfo(ctx, databaseID, options.DatabaseInfo().UpdateAPIOptions(opts.APIOptions))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion astra/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
"github.com/datastax/astra-db-go/v2/astra/cursors"
"github.com/datastax/astra-db-go/v2/astra/filter"
"github.com/datastax/astra-db-go/v2/astra/internal/command"
"github.com/datastax/astra-db-go/v2/astra/internal/utils"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/ptr"
"github.com/datastax/astra-db-go/v2/astra/results"
"github.com/datastax/astra-db-go/v2/astra/serdes"
"github.com/datastax/astra-db-go/v2/astra/update"
"github.com/datastax/astra-db-go/v2/internal/utils"
)

// CollectionFilter is implemented by [filter.F] and [filter.Filter].
Expand Down
8 changes: 4 additions & 4 deletions astra/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func TestDeleteManyAPIOptionsOverrideToken(t *testing.T) {

_, err := coll.DeleteMany(ctx, filter.F{"x": 1},
options.CollectionDeleteMany().
SetAPIOptions(options.API().SetToken("override-token")),
UpdateAPIOptions(options.API().SetToken("override-token")),
)
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -410,7 +410,7 @@ func TestDeleteOneAPIOptionsOverrideToken(t *testing.T) {

_, err := coll.DeleteOne(ctx, filter.F{"x": 1},
options.CollectionDeleteOne().
SetAPIOptions(options.API().SetToken("override-token")),
UpdateAPIOptions(options.API().SetToken("override-token")),
)
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -434,7 +434,7 @@ func TestUpdateOneAPIOptionsOverrideToken(t *testing.T) {

_, err := coll.UpdateOne(ctx, filter.F{"x": 1}, update.Coll().Set("x", 2),
options.CollectionUpdateOne().
SetAPIOptions(options.API().SetToken("override-token")),
UpdateAPIOptions(options.API().SetToken("override-token")),
)
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -459,7 +459,7 @@ func TestResolveGeneralMethodTimeoutFromAPIOverride(t *testing.T) {
// Set GeneralMethod timeout via APIOptions override
_, err := coll.DeleteMany(ctx, filter.F{"status": "old"},
options.CollectionDeleteMany().
SetAPIOptions(
UpdateAPIOptions(
options.API().UpdateTimeout(
options.Timeout().SetGeneralMethod(250*time.Millisecond),
),
Expand Down
2 changes: 1 addition & 1 deletion astra/common_impls.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (

"github.com/datastax/astra-db-go/v2/astra/filter"
"github.com/datastax/astra-db-go/v2/astra/internal/command"
"github.com/datastax/astra-db-go/v2/astra/internal/utils"
"github.com/datastax/astra-db-go/v2/astra/options"
"github.com/datastax/astra-db-go/v2/astra/ptr"
"github.com/datastax/astra-db-go/v2/astra/results"
"github.com/datastax/astra-db-go/v2/astra/serdes"
"github.com/datastax/astra-db-go/v2/astra/sort"
"github.com/datastax/astra-db-go/v2/internal/utils"
)

type mkCmd = func(name string, payload any, opts ...options.APIOption) command.DataAPI
Expand Down
2 changes: 1 addition & 1 deletion astra/cursors/abstract_cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"reflect"
"sync"

"github.com/datastax/astra-db-go/v2/astra/internal/utils"
"github.com/datastax/astra-db-go/v2/internal/utils"
)

// ErrCursorClosed is returned when operations are attempted on a closed cursor.
Expand Down
2 changes: 1 addition & 1 deletion astra/datatypes/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"
"time"

"github.com/datastax/astra-db-go/v2/astra/internal/utils"
"github.com/datastax/astra-db-go/v2/internal/utils"
)

// DateOnly represents a date (year, month, day) without a time component,
Expand Down
2 changes: 1 addition & 1 deletion astra/datatypes/objectid.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sync/atomic"
"time"

"github.com/datastax/astra-db-go/v2/astra/internal/utils"
"github.com/datastax/astra-db-go/v2/internal/utils"
)

// ObjectId represents an ObjectId that can be used as an _id in the DataAPI.
Expand Down
2 changes: 1 addition & 1 deletion astra/datatypes/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"
"time"

"github.com/datastax/astra-db-go/v2/astra/internal/utils"
"github.com/datastax/astra-db-go/v2/internal/utils"
)

// TimeOnly represents a time (hour, minute, second, nanosecond) without a date component,
Expand Down
2 changes: 1 addition & 1 deletion astra/datatypes/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sync"
"time"

"github.com/datastax/astra-db-go/v2/astra/internal/utils"
"github.com/datastax/astra-db-go/v2/internal/utils"
)

// UUID represents a universally unique identifier with Data API JSON serialization.
Expand Down
2 changes: 1 addition & 1 deletion astra/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (d *Db) Table(name string, opts ...options.GetTableOption) *Table {
//
// // With vector options
// coll, err := db.CreateCollection(ctx, "my_collection",
// options.CreateCollection().SetVector(&options.VectorOptions{
// options.CreateCollection().UpdateVector(&options.VectorOptions{
// Dimension: 1024,
// Metric: "cosine",
// })
Expand Down
2 changes: 1 addition & 1 deletion astra/db_admin_astra.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (a *AstraDatabaseAdmin) ListKeyspaces(ctx context.Context, opts ...options.
return nil, err
}

db, err := a.admin.DatabaseInfo(ctx, a.ID(), options.DatabaseInfo().SetAPIOptions(merged.APIOptions))
db, err := a.admin.DatabaseInfo(ctx, a.ID(), options.DatabaseInfo().UpdateAPIOptions(merged.APIOptions))
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions astra/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestCollectionOptionsMarshal(t *testing.T) {
})

t.Run("with vector", func(t *testing.T) {
opts := options.CreateCollection().SetVector(&options.VectorOptions{
opts := options.CreateCollection().UpdateVector(&options.VectorOptions{
Dimension: ptr.To(1024),
Metric: ptr.To("cosine"),
})
Expand All @@ -112,11 +112,11 @@ func TestCollectionOptionsMarshal(t *testing.T) {
})

t.Run("multiple builders merged", func(t *testing.T) {
opts := options.CreateCollection().SetVector(&options.VectorOptions{
opts := options.CreateCollection().UpdateVector(&options.VectorOptions{
Dimension: ptr.To(512),
Metric: ptr.To("euclidean"),
})
opts.SetVector(&options.VectorOptions{
opts.UpdateVector(&options.VectorOptions{
Dimension: ptr.To(1024),
Metric: ptr.To("cosine"),
})
Expand Down
81 changes: 20 additions & 61 deletions astra/options/api_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ type Caller struct {
Version string
}

// Headers is a custom map type that implements ShouldMerge to accumulate headers additively.
// Headers is a custom map type that implements shouldMerge to accumulate headers additively.
type Headers map[string]string

// Merge implements ShouldMerge for Headers.
func (h Headers) Merge(other ShouldMerge) ShouldMerge {
// Merge implements shouldMerge for Headers.
func (h Headers) merge(other shouldMerge) shouldMerge {
otherHeaders := other.(Headers)
res := make(Headers, len(h)+len(otherHeaders))
maps.Copy(res, h)
maps.Copy(res, otherHeaders)
return res
}

// Callers is a custom slice type that implements ShouldMerge to accumulate callers additively.
// Callers is a custom slice type that implements shouldMerge to accumulate callers additively.
type Callers []Caller

// Merge implements ShouldMerge for Callers.
func (c Callers) Merge(other ShouldMerge) ShouldMerge {
// Merge implements shouldMerge for Callers.
func (c Callers) merge(other shouldMerge) shouldMerge {
otherCallers := other.(Callers)
res := make(Callers, 0, len(c)+len(otherCallers))
res = append(res, c...)
Expand All @@ -118,41 +118,10 @@ type SerdesOptions struct {
UseJSONUnmarshal *bool
}

// Merge implements ShouldMerge for SerdesOptions.
func (o *SerdesOptions) Merge(other ShouldMerge) ShouldMerge {
otherSerdes := other.(*SerdesOptions)
result := &SerdesOptions{}
if o != nil {
*result = *o
}
if otherSerdes.TrustRawMessage != nil {
result.TrustRawMessage = otherSerdes.TrustRawMessage
}
if otherSerdes.SortMapKeys != nil {
result.SortMapKeys = otherSerdes.SortMapKeys
}
if otherSerdes.SerNoCache != nil {
result.SerNoCache = otherSerdes.SerNoCache
}
if otherSerdes.UseJSONMarshal != nil {
result.UseJSONMarshal = otherSerdes.UseJSONMarshal
}
if otherSerdes.SparseRows != nil {
result.SparseRows = otherSerdes.SparseRows
}
if otherSerdes.UseNumber != nil {
result.UseNumber = otherSerdes.UseNumber
}
if otherSerdes.DesNoCache != nil {
result.DesNoCache = otherSerdes.DesNoCache
}
if otherSerdes.ExtendedErrorContext != nil {
result.ExtendedErrorContext = otherSerdes.ExtendedErrorContext
}
if otherSerdes.UseJSONUnmarshal != nil {
result.UseJSONUnmarshal = otherSerdes.UseJSONUnmarshal
}
return result
// Merge implements shouldMerge for SerdesOptions.
func (o *SerdesOptions) merge(other shouldMerge) shouldMerge {
casted, _ := other.(*SerdesOptions)
return Merge[SerdesOptions](o, casted)
}

// GetSerFlags returns the aggregated serialization flags.
Expand Down Expand Up @@ -211,26 +180,10 @@ type TimeoutOptions struct {
GeneralMethod *time.Duration
}

// Merge implements ShouldMerge for TimeoutOptions.
func (o *TimeoutOptions) Merge(other ShouldMerge) ShouldMerge {
otherTimeout := other.(*TimeoutOptions)
result := &TimeoutOptions{}
if o != nil {
*result = *o
}
if otherTimeout.Request != nil {
result.Request = otherTimeout.Request
}
if otherTimeout.Connection != nil {
result.Connection = otherTimeout.Connection
}
if otherTimeout.BulkOperation != nil {
result.BulkOperation = otherTimeout.BulkOperation
}
if otherTimeout.GeneralMethod != nil {
result.GeneralMethod = otherTimeout.GeneralMethod
}
return result
// Merge implements shouldMerge for TimeoutOptions.
func (o *TimeoutOptions) merge(other shouldMerge) shouldMerge {
casted, _ := other.(*TimeoutOptions)
return Merge[TimeoutOptions](o, casted)
}

// GetRequest returns the request timeout or 30 seconds if not set.
Expand Down Expand Up @@ -444,3 +397,9 @@ func (o *APIOptions) GetDesFlags() serdes.DesFlags {
}
return o.Serdes.GetDesFlags()
}

// Merge implements shouldMerge for APIOptions.
func (o *APIOptions) merge(other shouldMerge) shouldMerge {
casted, _ := other.(*APIOptions)
return Merge[APIOptions](o, casted)
}
Loading