An async Rust client for SurrealDB's RPC endpoint

Overview

An async Rust client for SurrealDB's RPC endpoint

This crate serves as a temporary yet complete implementation of an async Rust client to connect to a remote SurrealDB instance via its RPC endpoint until the official SurrealDB client crate comes out.

The crate is aimed to be used in Rust backends and was not tested in a WASM environment. It probably doesn't work at all

Example

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  let mut client = SurrealClient::new("ws://127.0.0.1:8000/rpc")
    .await
    .expect("RPC handshake error");

  client.signin("root", "root").await.expect("Signin error");
  client.use_namespace("my_namespace", "my_namespace").await.expect("Namespace error");

  client.send_query("create User set username = $username".to_owned(), json!({ "username": "John" }),)
    .await
    .unwrap();

  let some_user: Option<User> = client.find_one("select * from User".to_owned(), Value::Null)
    .await
    .unwrap();

  if let Some(user) = some_user {
    print!("found user: {:?}", user);
  }
}

The SurrealClient type offers utility functions to:

  • send a query in order to get a raw, unparsed response: client.send_query()
  • send a query and get the first element of type <T> from the response: client.find_one()
  • send a query and get the many elements of type <T> in the form of a Vec<T> from the response: client.find_many()

You can find a complete example in the ./tests directory.

Running tests

The tests require a SurrealDB instance to run locally, a justfile was created to allow anyone to boot a in-memory instance using the just db command.

If just is not installed then the following command will do the trick:

surreal start --log debug --user root --pass root memory

then use the following command to run the tests:

cargo test
Comments
  • feat: simplify RpcChannelError type conversion

    feat: simplify RpcChannelError type conversion

    Adds thiserror::Error derive macro to RpcChannelError to make have it implement std::error::Error and therefore easier to convert the error with crates like thiserror and anyhow.

    opened by tirithen 1
  • v0.2.0

    v0.2.0

    • Allow separately awaiting sending & response response from query (#5)
    • Add unit tests & examples
    • Add utility functions to retrieve the value(s) of specific keys from a vector of objects
    • Improve handling of various formats returned by SurrealDB queries
    opened by Aelto 0
  • Client doesn't return rows from queries with edge traversal

    Client doesn't return rows from queries with edge traversal

    When I run queries which involve edge traversal, I get zero rows returned. My setup:

    CREATE thing:one CONTENT { a: "Blorp" };
    CREATE thing:two CONTENT { b: "Plorp" };
    RELATE thing:one->part->thing:two;
    

    Then in rust,

    let client: surreal_simple_client::Surreal = // ... connect and auth
    
    let params = json!({ });
    let things = client.send_query("SELECT * FROM thing", params).await?; // returns two rows, as is expected
    
    let params = json!({ "tid": "thing:one" });
    let thing = client.send_query("SELECT * FROM $tid->part->thing", params).await? // returns zero rows, but it should return [ thing:two ]
    
    opened by Threadzless 0
  • Documentation: missing documentation & examples

    Documentation: missing documentation & examples

    1. Some functions & types are missing their documentation as well as their example.
    2. More example would be helpful, for example a project demonstrating what the actix feature provides.
    documentation 
    opened by Aelto 0
  • Feature: implement a `SurrealClient::close()` fn

    Feature: implement a `SurrealClient::close()` fn

    There is currently no way to manually close the connection that was opened by the SurrealClient. Same issue for the task the client spawns in its Self::new() function.

    A SurrealClient::close() function should ensure the task is gracefully shut down and the tungstenite connection is closed properly.

    enhancement 
    opened by Aelto 0
Owner
Thibault H
Thibault H
This crate allows you to send cypher queries to the REST endpoint of a neo4j database

rusted_cypher Rust crate for accessing the cypher endpoint of a neo4j server This crate allows you to send cypher queries to the REST endpoint of a ne

Livio Ribeiro 68 Dec 1, 2022
Lightweight unifying client for RPC + BanksClient

Ellipsis Client Lightweight unifying client for RPC + BanksClient There are no good unifying traits for Solana Rust clients. EllipsisClient creates a

Ellipsis Labs 16 Dec 24, 2022
📺 Netflix in Rust/ React-TS/ NextJS, Actix-Web, Async Apollo-GraphQl, Cassandra/ ScyllaDB, Async SQLx, Kafka, Redis, Tokio, Actix, Elasticsearch, Influxdb Iox, Tensorflow, AWS

Fullstack Movie Streaming Platform ?? Netflix in RUST/ NextJS, Actix-Web, Async Apollo-GraphQl, Cassandra/ ScyllaDB, Async SQLx, Spark, Kafka, Redis,

null 34 Apr 17, 2023
High-level async Cassandra client written in 100% Rust.

CDRS tokio CDRS is production-ready Apache Cassandra driver written in pure Rust. Focuses on providing high level of configurability to suit most use

Kamil Rojewski 73 Dec 26, 2022
An async-ready Phoenix Channels v2 client library in Rust

Phoenix Channels This crate implements a Phoenix Channels (v2) client in Rust. Status NOTE: This client is still a work-in-progress, though it has eno

LiveView Native 22 Jan 7, 2023
Lightweight async Redis client with connection pooling written in pure Rust and 100% memory safe

redi-rs (or redirs) redi-rs is a Lightweight Redis client with connection pooling written in Rust and 100% memory safe redi-rs is a Redis client writt

Oğuz Türkay 4 May 20, 2023
Async Lightweight HTTP client using system native library if possible. (Currently under heavy development)

Async Lightweight HTTP Client (aka ALHC) What if we need async but also lightweight http client without using such a large library like reqwest, isahc

SteveXMH 7 Dec 15, 2022
Affine-client is a client for AFFINE based on Tauri

Affine Client affine-client is a client for AFFINE based on Tauri Supported Platforms Windows Linux MacOS Download https://github.com/m1911star/affine

Horus 216 Dec 25, 2022
🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.

SQLx ?? The Rust SQL Toolkit Install | Usage | Docs Built with ❤️ by The LaunchBadge team SQLx is an async, pure Rust† SQL crate featuring compile-tim

launchbadge 7.6k Dec 31, 2022
TDS 7.2+ (mssql / Microsoft SQL Server) async driver for rust

Tiberius A native Microsoft SQL Server (TDS) client for Rust. Supported SQL Server versions Version Support level Notes 2019 Tested on CI 2017 Tested

Prisma 189 Dec 25, 2022
Simple, async embedded Rust

Cntrlr - Simple, asynchronous embedded Cntrlr is an all-in-one embedded platform for writing simple asynchronous applications on top of common hobbyis

Branan Riley 11 Jun 3, 2021
Rust async runtime based on io-uring.

Monoio A thread-per-core Rust runtime with io_uring. 中文说明 Design Goal As a runtime based on io_uring, Monoio is designed to be the most efficient and

Bytedance Inc. 2.4k Jan 6, 2023
🐚 An async & dynamic ORM for Rust

SeaORM ?? An async & dynamic ORM for Rust SeaORM SeaORM is a relational ORM to help you build web services in Rust with the familiarity of dynamic lan

SeaQL 3.5k Jan 6, 2023
Quick Pool: High Performance Rust Async Resource Pool

Quick Pool High Performance Rust Async Resource Pool Usage DBCP Database Backend Adapter Version PostgreSQL tokio-postgres qp-postgres Example use asy

Seungjae Park 13 Aug 23, 2022
Dataloader-rs - Rust implementation of Facebook's DataLoader using async-await.

Dataloader Rust implementation of Facebook's DataLoader using async-await. Documentation Features Batching load requests with caching Batching load re

cksac 229 Nov 27, 2022
Automatically deleted async I/O temporary files in Rust

async-tempfile Provides the TempFile struct, an asynchronous wrapper based on tokio::fs for temporary files that will be automatically deleted when th

Markus Mayer 3 Jan 4, 2023
Go like sync.WaitGroup implementation in Rust. (sync/async)

WAG Go like sync.WaitGroup implementation in Rust. (sync/async) | Examples | Docs | Latest Note | wag = "0.3.0" How to use, use wag::WaitGroup; let w

Doha Lee 2 Dec 15, 2022
Notification demon + web server using async Rust

Async Rust example Road to the asynchronous Rust Table of Contents About the Project Screenshots Tech Stack Features Getting Started Prerequisites Clo

Edem Khadiev 4 Feb 9, 2023
An async executor based on the Win32 thread pool API

wae An async executor based on the Win32 thread pool API use futures::channel::oneshot; #[wae::main] async fn main() { let (tx, rx) = oneshot::ch

Raphaël Thériault 10 Dec 10, 2021