mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 09:43:10 -06:00
* - Create CosmosDocument as a base class - Add CT and UT - Refactor all tables to use the CosmosDocument * - Add UpsertDocument method to perform updates in a generic way - Add SetUpdateTime() to update the UT for updates - Refactor it all Co-authored-by: alexf@example.com <alexf@example.com>
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package cosmosdbapi
|
|
|
|
import (
|
|
cosmosapi "github.com/vippsas/go-cosmosdb/cosmosapi"
|
|
)
|
|
|
|
func GetCreateDocumentOptions(pk string) cosmosapi.CreateDocumentOptions {
|
|
return cosmosapi.CreateDocumentOptions{
|
|
IsUpsert: false,
|
|
PartitionKeyValue: pk,
|
|
}
|
|
}
|
|
|
|
func getUpsertDocumentOptions(pk string) cosmosapi.CreateDocumentOptions {
|
|
return cosmosapi.CreateDocumentOptions{
|
|
IsUpsert: true,
|
|
PartitionKeyValue: pk,
|
|
}
|
|
}
|
|
|
|
func GetQueryDocumentsOptions(pk string) cosmosapi.QueryDocumentsOptions {
|
|
return cosmosapi.QueryDocumentsOptions{
|
|
PartitionKeyValue: pk,
|
|
IsQuery: true,
|
|
ContentType: cosmosapi.QUERY_CONTENT_TYPE,
|
|
}
|
|
}
|
|
|
|
func GetQueryAllPartitionsDocumentsOptions() cosmosapi.QueryDocumentsOptions {
|
|
return cosmosapi.QueryDocumentsOptions{
|
|
IsQuery: true,
|
|
EnableCrossPartition: true,
|
|
ContentType: cosmosapi.QUERY_CONTENT_TYPE,
|
|
}
|
|
}
|
|
|
|
func GetGetDocumentOptions(pk string) cosmosapi.GetDocumentOptions {
|
|
return cosmosapi.GetDocumentOptions{
|
|
PartitionKeyValue: pk,
|
|
}
|
|
}
|
|
|
|
func GetReplaceDocumentOptions(pk string, etag string) cosmosapi.ReplaceDocumentOptions {
|
|
return cosmosapi.ReplaceDocumentOptions{
|
|
PartitionKeyValue: pk,
|
|
IfMatch: etag,
|
|
}
|
|
}
|
|
|
|
func GetDeleteDocumentOptions(pk string) cosmosapi.DeleteDocumentOptions {
|
|
return cosmosapi.DeleteDocumentOptions{
|
|
PartitionKeyValue: pk,
|
|
}
|
|
}
|