SurrealDB
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
use std::future::Future;
|
||||
use std::net::{IpAddr, Ipv6Addr};
|
||||
use std::sync::Arc;
|
||||
use futures::future::{self};
|
||||
use futures::StreamExt;
|
||||
use surrealdb::engine::remote::ws::Ws;
|
||||
use surrealdb::opt::auth::Root;
|
||||
use surrealdb::Surreal;
|
||||
use tarpc::{
|
||||
server::{Channel},
|
||||
tokio_serde::formats::Json,
|
||||
@@ -17,6 +21,18 @@ async fn spawn(fut: impl Future<Output = ()> + Send + 'static) {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
// Connect to the server
|
||||
let db = Arc::new(Surreal::new::<Ws>("127.0.0.1:8000").await?);
|
||||
|
||||
// Signin as a namespace, database, or root user
|
||||
db.signin(Root {
|
||||
username: "root",
|
||||
password: "root",
|
||||
}).await?;
|
||||
|
||||
// Select a specific namespace / database
|
||||
db.use_ns("realmchat").use_db("test").await?;
|
||||
|
||||
let server_addr = (IpAddr::V6(Ipv6Addr::LOCALHOST), 5051);
|
||||
|
||||
// JSON transport is provided by the json_transport tarpc module. It makes it easy
|
||||
@@ -33,7 +49,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
// serve is generated by the service attribute. It takes as input any type implementing
|
||||
// the generated World trait.
|
||||
.map(|channel| {
|
||||
let server = RealmChatServer(channel.transport().peer_addr().unwrap());
|
||||
let server = RealmChatServer::new(channel.transport().peer_addr().unwrap(), db.clone());
|
||||
channel.execute(server.serve()).for_each(spawn)
|
||||
})
|
||||
// Max 10 channels.
|
||||
|
||||
Reference in New Issue
Block a user