Skip to content

Commit 274e328

Browse files
committed
expose API that can be used outside Dgraph
1 parent ecbc356 commit 274e328

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

query/mutation.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
func ApplyMutations(ctx context.Context, m *pb.Mutations) (*api.TxnContext, error) {
3939
// In expandEdges, for non * type prredicates, we prepend the namespace directly and for
4040
// * type predicates, we fetch the predicates and prepend the namespace.
41-
edges, err := expandEdges(ctx, m)
41+
edges, err := ExpandEdges(ctx, m)
4242
if err != nil {
4343
return nil, errors.Wrapf(err, "While adding pb.edges")
4444
}
@@ -57,7 +57,7 @@ func ApplyMutations(ctx context.Context, m *pb.Mutations) (*api.TxnContext, erro
5757
return tctx, err
5858
}
5959

60-
func expandEdges(ctx context.Context, m *pb.Mutations) ([]*pb.DirectedEdge, error) {
60+
func ExpandEdges(ctx context.Context, m *pb.Mutations) ([]*pb.DirectedEdge, error) {
6161
edges := make([]*pb.DirectedEdge, 0, 2*len(m.Edges))
6262
namespace, err := x.ExtractNamespace(ctx)
6363
if err != nil {

worker/embedded.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package worker
2+
3+
import (
4+
"context"
5+
6+
"github.com/dgraph-io/badger/v4"
7+
"github.com/dgraph-io/dgraph/v24/conn"
8+
"github.com/dgraph-io/dgraph/v24/protos/pb"
9+
"github.com/dgraph-io/dgraph/v24/schema"
10+
)
11+
12+
func InitForLite(ps *badger.DB) {
13+
pstore = ps
14+
groups().state = &pb.MembershipState{}
15+
groups().Node = &node{Node: &conn.Node{Id: 1}}
16+
groups().gid = 1
17+
}
18+
19+
func InitTablet(pred string) {
20+
groups().Lock()
21+
defer groups().Unlock()
22+
groups().tablets[pred] = &pb.Tablet{GroupId: 1, Predicate: pred}
23+
}
24+
25+
func ApplyMutations(ctx context.Context, p *pb.Proposal) error {
26+
return groups().Node.applyMutations(ctx, p)
27+
}
28+
29+
func ApplyCommited(ctx context.Context, delta *pb.OracleDelta) error {
30+
return groups().Node.commitOrAbort(1, delta)
31+
}
32+
33+
func ApplyInitialSchema() error {
34+
for _, su := range schema.InitialSchema(0) {
35+
if err := updateSchema(su, 1); err != nil {
36+
return err
37+
}
38+
39+
func() {
40+
groups().Lock()
41+
defer groups().Unlock()
42+
groups().tablets[su.Predicate] = &pb.Tablet{GroupId: groups().groupId(), Predicate: su.Predicate}
43+
}()
44+
}
45+
gr.applyInitialTypes()
46+
return nil
47+
}
48+
49+
func SetMaxUID(uid uint64) {
50+
groups().Lock()
51+
defer groups().Unlock()
52+
groups().state.MaxUID = uid
53+
}

0 commit comments

Comments
 (0)