This is a simple repository that demonstrates DGraph usage in golang The main structure was generated using Goxygen If you're not familiar with docker commands, this is a good place to start
You need to have Go, Node.js, Docker, and Docker Compose (comes pre-installed with Docker on Mac and Windows) installed on your computer.
Verify the tools by running the following commands:
go version
npm --version
docker --version
docker-compose --version
If you are using Windows you will also need gcc. It comes installed on Mac and almost all Linux distributions.
The default docker container runs in a self-sufficicent enviroment. If you intend your databse to run in and independent environment outside this docker container, modify the following files:
- docker-compose.yml comment out the code that adds dgraph to the current environment and bundles it with the app
- prod and dev db urls are currelty hard-coded into the app. Modify them to your needs
In this configuration you have a total of 3 different apps running in different ports
- The dgraph server (zero, ratel, dgraph server are all bundled and being counted as one)
- The golang backend, acting as the API endpoint
- The Angular frontend, making requests to the API endpoint
In the project directory run the command (you might
need to prepend it with sudo
depending on your setup):
docker-compose -f docker-compose-dev.yml up
This starts a local DGraph instance on http://localhost:8080
.
Navigate to the server
folder and start the back end:
cd server
go run server.go
The back end will serve on http://localhost:3000.
Navigate to the webapp
folder, install dependencies,
and start the front end development server by running:
cd webapp
npm install
npm start
The application will be available on http://localhost:3030.
In the project directory run the command (you might
need to prepend it with sudo
depending on your setup):
Perform:
docker-compose up
This will build the application and start it together with its database. Access the application on http://localhost:3000.
It also starts a local DGraph instance on http://localhost:8080`. The database will not be populated with test records. Production mode does not expose ratel
Glad you made it this far. You need to initialise the db with somne sample data With the server already running (can be either prod or dev), open http://localhost:8000/?latest and navigate to the schema --> Bulk Edit paste the contents from this file click "Aplly schema"
Open terminal and execute the following command
docker ps
This will give you a list of docker containers running. Note the
id assigned to dgraph zero
In the attached screenshot it's 39ebdf707ae8
Within your project directory run the command
docker exec -it <container_Id> dgraph live -f /testdata/1million.rdf.gz --alpha alpha:9080 --zero zero:5080 -c 1
replacing <container Id>
with the id attained above
There’s around one million triples in the dataset. Dgraph reports
back exactly how many triples were loaded and how long it took.
It’s a big database of movies, but it won’t trouble Dgraph. It is, however, big enough for us to use more complex queries. The dataset is downloaded from the official docs
Disclaimer: This is not a proper ER Diagram (Due to how nodes are different from FK), but it helps explain the structure
Navigate to http://localhost:8000/?latest on your browser paste this query You sould get a response similar to Congratulations!! You've successfully run a dockerised dgraph and loaded it with millions of datasets
This setup can easily be modified to separate frontend from the backend. Modify the environment variable and replace "apiUrl" with desired value
I know I should be writing tests. This is still a WIP