Dgraph REST client for crystal
-
Add the dependency to your
shard.yml
:dependencies: dgraph: github: wonderix/dgraph.cr
-
Run
shards install
require "dgraph"
struct Employment
include Dgraph::Facets
property salery : Int32
property role : Int32
def initialize(@salery, @role)
end
end
struct Person
end
struct Company
include Dgraph::Base
property name : String
edge peoples : Array(Dgraph::Edge(Person, Employment)), name: "company", reverse: true
def initialize(@name)
end
end
struct Person
include Dgraph::Base
property firstname : String
property lastname : String
property email : String
edge company : Dgraph::Edge(Company, Employment), name: "company"
def initialize(@firstname, @lastname, @email, @company)
end
end
Dgraph.setup
Dgraph.client.alter(drop_all: true)
Dgraph.client.alter("
firstname: string @index(trigram,exact) .
lastname: string @index(trigram,exact) .
company: uid @reverse .
type Person {
firstname
lastname
company
}
type Company {
}
")
company = Company.new("Enterprise").insert
person = Person.new("Max", "Mustermann", "max.mustermann@web.de", Dgraph::Edge.new(company, Employment.new(10000, 1))).insert
p person.uid
p Person.get(person.uid)
p Person.all.to_a
p Company.all.to_a
person.delete
mkdir -p ~/dgraph
docker rm -f dpgraph || true
docker run -d -p 5080:5080 -p 6080:6080 -p 8080:8080 -p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph --name dgraph dgraph/standalone:v21.03.1
TODO: Write development instructions here
See Log
- Fork it (https://github.com/wonderix/dgraph.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Ulrich Kramer - creator and maintainer