Skip to content

ASoldo/surrealdb-proj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SurrealDB Project with Actix-Web

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.

Getting Started

Prerequisites

  • Rust Programming Language
  • SurrealDB installed locally

Running SurrealDB

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.

Setting Up the Project

  1. Clone the repository

    git clone https://github.com/ASoldo/surrealdb-proj.git
    cd surrealdb-proj
  2. Build the project:

    cargo build
  3. Start the SurrealDB

    surreal start file:db-demo --user root --password root
  4. Run the Actix-Web server:

    cargo run

The server will start on http://127.0.0.1:8080.

API Endpoints

The server exposes two endpoints:

  1. 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"
      }
    ]
  2. 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")}]

Dependencies

The project's dependencies are defined in Cargo.toml:

  • actix-web for the web server framework.
  • serde and serde_json for serializing and deserializing the JSON data.
  • surrealdb for interacting with the SurrealDB database.

Start TiKV

tiup playground --tag surrealdb --mode tikv-slim --pd 1 --kv 1

or

tiup playground --tag surrealdb --pd 1 --kv 1

Start SurrealDB with TiKV

surreal start --log trace tikv://127.0.0.1:2379

Start SurrealDB with local db file

surreal start file:demo-db --user root --password root

Connect to local SurrealDB

surreal sql --endpoint http://127.0.0.1:8000 --username root --password root --namespace test --database test

Profiling

Use to profile application and generate flamegraph

cargo flamegraph --dev -- --no-rosegment

About

SurrealDB + Actix-Web project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages