Skip to content

Commit

Permalink
expose API that can be used outside Dgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Oct 11, 2024
1 parent ecbc356 commit 83b3085
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions query/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
func ApplyMutations(ctx context.Context, m *pb.Mutations) (*api.TxnContext, error) {
// In expandEdges, for non * type prredicates, we prepend the namespace directly and for
// * type predicates, we fetch the predicates and prepend the namespace.
edges, err := expandEdges(ctx, m)
edges, err := ExpandEdges(ctx, m)
if err != nil {
return nil, errors.Wrapf(err, "While adding pb.edges")
}
Expand All @@ -57,7 +57,7 @@ func ApplyMutations(ctx context.Context, m *pb.Mutations) (*api.TxnContext, erro
return tctx, err
}

func expandEdges(ctx context.Context, m *pb.Mutations) ([]*pb.DirectedEdge, error) {
func ExpandEdges(ctx context.Context, m *pb.Mutations) ([]*pb.DirectedEdge, error) {
edges := make([]*pb.DirectedEdge, 0, 2*len(m.Edges))
namespace, err := x.ExtractNamespace(ctx)
if err != nil {
Expand Down
47 changes: 47 additions & 0 deletions worker/embedded.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package worker

import (
"context"

"github.com/dgraph-io/badger/v4"
"github.com/dgraph-io/dgraph/v24/conn"
"github.com/dgraph-io/dgraph/v24/protos/pb"
"github.com/dgraph-io/dgraph/v24/schema"
)

func InitForLite(ps *badger.DB) {
pstore = ps
groups().state = &pb.MembershipState{}
groups().Node = &node{Node: &conn.Node{Id: 1}}
groups().gid = 1
}

func InitTablet(pred string) {
groups().Lock()
defer groups().Unlock()
groups().tablets[pred] = &pb.Tablet{GroupId: 1, Predicate: pred}
}

func ApplyMutations(ctx context.Context, p *pb.Proposal) error {
return groups().Node.applyMutations(ctx, p)
}

func ApplyCommited(ctx context.Context, delta *pb.OracleDelta) error {
return groups().Node.commitOrAbort(1, delta)
}

func ApplyInitialSchema() error {
for _, su := range schema.InitialSchema(0) {
if err := updateSchema(su, 1); err != nil {
return err
}
}
gr.applyInitialTypes()
return nil
}

func SetMaxUID(uid uint64) {
groups().Lock()
defer groups().Unlock()
groups().state.MaxUID = uid
}

0 comments on commit 83b3085

Please sign in to comment.