At the end of this guide, you will have created a simple Rust
Hello, World! program that connects to the Memgraph database and executes simple queries.
To follow this guide, you will need:
- A running Memgraph instance. If you need to setup Memgraph, take a look at the Installation guide.
- A basic understanding of graph databases and the property graph model.
- Docker installed and running. Instructions on how to setup Docker can be found on the official Docker website.
- The rsmgclient driver. A Memgraph database adapter for the Rust programming language. (if you are not using Docker)
NOTE: We recommend using Docker because it simplifies installing the driver dependencies. If you don't wish to use Docker, you will need to install the rsmgclient driver locally.
We'll be using a Dockerized Rust program to demonstrate how to connect to a running Memgraph database instance.
If you don't wish to use Docker, the steps might be slightly different, but the code is most likley the same or very similar.
Let's jump in and connect a simple program to Memgraph.
1. Create a new Rust project with the name memgraph_rust by running the following command:
2. Add the following line to the
Cargo.toml file under the line
3. To create the actual program, add the following code to the
4. Create a new file in the project root directory
/memgraph_rust and name it
Dockerfile. Add the following code to it:
5. Don't forget to change the host address in your code.
CONTAINER ID with
docker ps and use it in the following command to retrieve the address:
6. To run the application, first, you need to create a Docker image with:
7. Now, you can start the application with the following command:
You should see an output similar to the following:
For real-world examples of how to use Memgraph, we suggest you take a look at the Tutorials page. You can also browse through the Database functionalities section to get an overview of all the functionalities Memgraph offers.
Visit the Getting help page in case you run into any kind of problem or you have additional questions.