feat(storage): rpc based implementation
All checks were successful
arcad/edge/pipeline/pr-master This commit looks good
All checks were successful
arcad/edge/pipeline/pr-master This commit looks good
This commit is contained in:
26
pkg/storage/driver/rpc/server/document/delete_document.go
Normal file
26
pkg/storage/driver/rpc/server/document/delete_document.go
Normal file
@ -0,0 +1,26 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/storage"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type DeleteDocumentArgs struct {
|
||||
Collection string
|
||||
DocumentID storage.DocumentID
|
||||
}
|
||||
|
||||
type DeleteDocumentReply struct {
|
||||
}
|
||||
|
||||
func (s *Service) DeleteDocument(ctx context.Context, args DeleteDocumentArgs, reply *DeleteDocumentReply) error {
|
||||
if err := s.store.Delete(ctx, args.Collection, args.DocumentID); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
*reply = DeleteDocumentReply{}
|
||||
|
||||
return nil
|
||||
}
|
30
pkg/storage/driver/rpc/server/document/get_document.go
Normal file
30
pkg/storage/driver/rpc/server/document/get_document.go
Normal file
@ -0,0 +1,30 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/storage"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type GetDocumentArgs struct {
|
||||
Collection string
|
||||
DocumentID storage.DocumentID
|
||||
}
|
||||
|
||||
type GetDocumentReply struct {
|
||||
Document storage.Document
|
||||
}
|
||||
|
||||
func (s *Service) GetDocument(ctx context.Context, args GetDocumentArgs, reply *GetDocumentReply) error {
|
||||
document, err := s.store.Get(ctx, args.Collection, args.DocumentID)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
*reply = GetDocumentReply{
|
||||
Document: document,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
53
pkg/storage/driver/rpc/server/document/query_documents.go
Normal file
53
pkg/storage/driver/rpc/server/document/query_documents.go
Normal file
@ -0,0 +1,53 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/storage"
|
||||
"forge.cadoles.com/arcad/edge/pkg/storage/filter"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type QueryDocumentsArgs struct {
|
||||
Collection string
|
||||
Filter map[string]any
|
||||
Options *storage.QueryOptions
|
||||
}
|
||||
|
||||
type QueryDocumentsReply struct {
|
||||
Documents []storage.Document
|
||||
}
|
||||
|
||||
func (s *Service) QueryDocuments(ctx context.Context, args QueryDocumentsArgs, reply *QueryDocumentsReply) error {
|
||||
var (
|
||||
argsFilter *filter.Filter
|
||||
err error
|
||||
)
|
||||
|
||||
if args.Filter != nil {
|
||||
argsFilter, err = filter.NewFrom(args.Filter)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
documents, err := s.store.Query(ctx, args.Collection, argsFilter, withQueryOptions(args.Options))
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
*reply = QueryDocumentsReply{
|
||||
Documents: documents,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func withQueryOptions(opts *storage.QueryOptions) storage.QueryOptionFunc {
|
||||
return func(o *storage.QueryOptions) {
|
||||
o.Limit = opts.Limit
|
||||
o.Offset = opts.Offset
|
||||
o.OrderBy = opts.OrderBy
|
||||
o.OrderDirection = opts.OrderDirection
|
||||
}
|
||||
}
|
11
pkg/storage/driver/rpc/server/document/service.go
Normal file
11
pkg/storage/driver/rpc/server/document/service.go
Normal file
@ -0,0 +1,11 @@
|
||||
package document
|
||||
|
||||
import "forge.cadoles.com/arcad/edge/pkg/storage"
|
||||
|
||||
type Service struct {
|
||||
store storage.DocumentStore
|
||||
}
|
||||
|
||||
func NewService(store storage.DocumentStore) *Service {
|
||||
return &Service{store}
|
||||
}
|
30
pkg/storage/driver/rpc/server/document/upsert_document.go
Normal file
30
pkg/storage/driver/rpc/server/document/upsert_document.go
Normal file
@ -0,0 +1,30 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/storage"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type UpsertDocumentArgs struct {
|
||||
Collection string
|
||||
Document storage.Document
|
||||
}
|
||||
|
||||
type UpsertDocumentReply struct {
|
||||
Document storage.Document
|
||||
}
|
||||
|
||||
func (s *Service) UpsertDocument(ctx context.Context, args UpsertDocumentArgs, reply *UpsertDocumentReply) error {
|
||||
document, err := s.store.Upsert(ctx, args.Collection, args.Document)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
*reply = UpsertDocumentReply{
|
||||
Document: document,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user