This project demonstrates a basic Actix-Web server interfacing with SurrealDB to insert and query person records. It uses Rust's powerful async capabilities alongside SurrealDB's flexible schema-less data storage.
- Rust Programming Language
- SurrealDB installed locally
Start your SurrealDB instance with the following command:
surreal start file:demo-db --user root --password root
This command initializes a new SurrealDB instance using file-based storage.
-
Clone the repository
git clone https://github.com/ASoldo/surrealdb-proj.git cd surrealdb-proj
-
Build the project:
cargo build
-
Start the SurrealDB
surreal start file:db-demo --user root --password root
-
Run the Actix-Web server:
cargo run
The server will start on http://127.0.0.1:8080
.
The server exposes two endpoints:
-
Insert Person: Inserts a new person record into the database.
curl -v 127.0.0.1:8080/insert_person
Response:
[ { "id": { "tb": "person", "id": { "String": "up0a5uelp375nziy2lx8" } }, "marketing": true, "name": "Rootster", "title": "Founder & CEO" } ]
-
Query Person: Retrieves all person records from the database.
curl 127.0.0.1:8080/query_person
Response:
Query result: [Object {"id": Object {"tb": String("person"), "id": Object {"String": String("up0a5uelp375nziy2lx8")}}, "marketing": Bool(true), "name": String("Rootster"), "title": String("Founder & CEO")}]
The project's dependencies are defined in Cargo.toml
:
actix-web
for the web server framework.serde
andserde_json
for serializing and deserializing the JSON data.surrealdb
for interacting with the SurrealDB database.
tiup playground --tag surrealdb --mode tikv-slim --pd 1 --kv 1
or
tiup playground --tag surrealdb --pd 1 --kv 1
surreal start --log trace tikv://127.0.0.1:2379
surreal start file:demo-db --user root --password root
surreal sql --endpoint http://127.0.0.1:8000 --username root --password root --namespace test --database test
Use to profile application and generate flamegraph
cargo flamegraph --dev -- --no-rosegment