-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_write.go
31 lines (29 loc) · 1.68 KB
/
search_write.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package dynamodb
import (
"context"
"github.com/aws/aws-sdk-go/service/dynamodb"
"reflect"
)
func NewSearchWriter(db *dynamodb.DynamoDB, tableName string, modelType reflect.Type, partitionKeyName string, sortKeyName string, buildQuery func(interface{}) (dynamodb.ScanInput, error), options ...Mapper) (*Searcher, *Writer) {
return NewSearchWriterWithVersionAndQuery(db, tableName, modelType, partitionKeyName, sortKeyName, "", buildQuery, options...)
}
func NewSearchWriterWithVersionAndQuery(db *dynamodb.DynamoDB, tableName string, modelType reflect.Type, partitionKeyName string, sortKeyName string, versionField string, buildQuery func(interface{}) (dynamodb.ScanInput, error), options ...Mapper) (*Searcher, *Writer) {
var mapper Mapper
if len(options) > 0 && options[0] != nil {
mapper = options[0]
}
if mapper != nil {
writer := NewWriterWithVersion(db, tableName, modelType, partitionKeyName, sortKeyName, versionField, options...)
searcher := NewSearcherWithQuery(db, modelType, buildQuery, mapper.DbToModel)
return searcher, writer
} else {
writer := NewWriterWithVersion(db, tableName, modelType, partitionKeyName, sortKeyName, versionField, options...)
searcher := NewSearcherWithQuery(db, modelType, buildQuery)
return searcher, writer
}
}
func NewSearchWriterWithVersion(db *dynamodb.DynamoDB, tableName string, modelType reflect.Type, partitionKeyName string, sortKeyName string, versionField string, search func(context.Context, interface{}, interface{}, int64, ...int64) (int64, string, error)) (*Searcher, *Writer) {
writer := NewWriterWithVersion(db, tableName, modelType, partitionKeyName, sortKeyName, versionField)
searcher := NewSearcher(search)
return searcher, writer
}