package graph import ( "context" "log" "github.com/dgraph-io/dgo/v2" "github.com/dgraph-io/dgo/v2/protos/api" "google.golang.org/grpc" ) func ConnectToDgraph() (*dgo.Dgraph, error) { client, err := grpc.Dial("localhost:9080", grpc.WithInsecure()) if err != nil { log.Fatal(err) } return dgo.NewDgraphClient( api.NewDgraphClient(client), ), err } func InitSchema(c *dgo.Dgraph) error { err := c.Alter(context.Background(), &api.Operation{ // DropOp: api.Operation_ALL, Schema: ` averageSpeed: uid . circuit: uid . constructor: uid . constructorId: string . date: string . dateOfBirth: string @index(term) . driver: uid . fastestLap: uid . givenName: string . grid: string . lap: string . laps: string . familyName: string @index(term) . location: string @index(term) . millis: string . name: string @index(term) . nationality: string @index(term) . number: string . points: string . position: string @index(term) . race: [uid] . raceName: string @index(term) . rank: string . round: string . results: [uid] . season: string @index(term) . speed: string . status: string . time: string . type: string @index(term) . units: string . url: string . driver_name: string @index(exact) . type Driver { dateOfBirth driver_name familyName givenName nationality type } constructor_name: string @index(fulltext) . type Constructor { constructorId constructor_name name nationality type url } type Result { constructor driver grid laps number points position race status time type } circuit_name: string @index(fulltext) . type Circuit { circuit_name location name type url } race_name: string @index(fulltext) . type Race { circuit date raceName race_name results round season type url }`}) if err != nil { return err } return nil }