feat: update SurrealDB dependency to version 3 and reflect changes in documentation

This commit is contained in:
Jacob Schmidt 2026-04-27 18:20:15 -05:00
parent 355e784628
commit df719041dd
8 changed files with 40 additions and 12 deletions

View File

@ -18,7 +18,7 @@ forge-services = { path = "../../../lib/services" }
forge-shared = { path = "../../../lib/shared" } forge-shared = { path = "../../../lib/shared" }
serde = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true } serde_json = { workspace = true }
surrealdb = { version = "2", default-features = false, features = ["protocol-http", "rustls"] } surrealdb = { version = "3", default-features = false, features = ["protocol-http", "rustls"] }
tokio = { workspace = true } tokio = { workspace = true }
toml = "1.1.2" toml = "1.1.2"
uuid = { workspace = true } uuid = { workspace = true }

View File

@ -4,6 +4,8 @@ The Forge server extension is the Rust backend for server-side game systems.
It exposes domain commands through `arma-rs`, runs a shared Tokio runtime, and It exposes domain commands through `arma-rs`, runs a shared Tokio runtime, and
persists durable state through SurrealDB. persists durable state through SurrealDB.
This extension build targets SurrealDB `3.x`.
## Responsibilities ## Responsibilities
- Register extension command groups for actor, bank, garage, locker, org, - Register extension command groups for actor, bank, garage, locker, org,

View File

@ -1,4 +1,5 @@
use super::*; use super::*;
use serde_json::Value as JsonValue;
pub(super) fn surreal_select<T>( pub(super) fn surreal_select<T>(
table: &'static str, table: &'static str,
@ -10,11 +11,17 @@ where
{ {
let id = id.to_string(); let id = id.to_string();
RUNTIME.block_on(async move { RUNTIME.block_on(async move {
surreal::client() let value: Option<JsonValue> = surreal::client()
.await? .await?
.select((table, id.as_str())) .select((table, id.as_str()))
.await .await
.map_err(|error| format!("SurrealDB {} select failed: {}", label, error)) .map_err(|error| format!("SurrealDB {} select failed: {}", label, error))?;
value
.map(|record| {
serde_json::from_value(record)
.map_err(|error| format!("SurrealDB {} decode failed: {}", label, error))
})
.transpose()
}) })
} }
@ -23,11 +30,18 @@ where
T: DeserializeOwned, T: DeserializeOwned,
{ {
RUNTIME.block_on(async move { RUNTIME.block_on(async move {
surreal::client() let values: Vec<JsonValue> = surreal::client()
.await? .await?
.select(table) .select(table)
.await .await
.map_err(|error| format!("SurrealDB {} select all failed: {}", label, error)) .map_err(|error| format!("SurrealDB {} select all failed: {}", label, error))?;
values
.into_iter()
.map(|record| {
serde_json::from_value(record)
.map_err(|error| format!("SurrealDB {} decode failed: {}", label, error))
})
.collect()
}) })
} }
@ -44,7 +58,7 @@ where
let record = serde_json::to_value(record) let record = serde_json::to_value(record)
.map_err(|error| format!("SurrealDB {} serialize failed: {}", label, error))?; .map_err(|error| format!("SurrealDB {} serialize failed: {}", label, error))?;
RUNTIME.block_on(async move { RUNTIME.block_on(async move {
let _: Option<T> = surreal::client() let _: Option<JsonValue> = surreal::client()
.await? .await?
.upsert((table, id.as_str())) .upsert((table, id.as_str()))
.content(record) .content(record)
@ -60,7 +74,7 @@ where
{ {
let id = id.to_string(); let id = id.to_string();
RUNTIME.block_on(async move { RUNTIME.block_on(async move {
let _: Option<T> = surreal::client() let _: Option<JsonValue> = surreal::client()
.await? .await?
.delete((table, id.as_str())) .delete((table, id.as_str()))
.await .await
@ -97,9 +111,16 @@ where
.bind(("value", value)) .bind(("value", value))
.await .await
.map_err(|error| format!("SurrealDB {} select by field failed: {}", label, error))?; .map_err(|error| format!("SurrealDB {} select by field failed: {}", label, error))?;
response let values: Vec<JsonValue> = response
.take(0) .take(0)
.map_err(|error| format!("SurrealDB {} select by field failed: {}", label, error)) .map_err(|error| format!("SurrealDB {} select by field failed: {}", label, error))?;
values
.into_iter()
.map(|record| {
serde_json::from_value(record)
.map_err(|error| format!("SurrealDB {} decode failed: {}", label, error))
})
.collect()
}) })
} }

View File

@ -200,6 +200,7 @@ struct GarageUnlockRecord {
uid: String, uid: String,
category: String, category: String,
classname: String, classname: String,
#[serde(skip_serializing_if = "Option::is_none")]
source: Option<String>, source: Option<String>,
} }

View File

@ -189,6 +189,7 @@ struct LockerUnlockRecord {
uid: String, uid: String,
category: String, category: String,
classname: String, classname: String,
#[serde(skip_serializing_if = "Option::is_none")]
source: Option<String>, source: Option<String>,
} }

View File

@ -96,7 +96,7 @@ impl OrgRepository for OrgStorageRepository {
} }
} }
#[derive(Debug, Default, Serialize, Deserialize)] #[derive(Debug, Default, Clone, Serialize, Deserialize)]
struct SurrealOrgRecord { struct SurrealOrgRecord {
#[serde(default)] #[serde(default)]
org_id: String, org_id: String,

View File

@ -109,8 +109,8 @@ async fn connect(config: SurrealConfig) -> Result<SurrealDb, String> {
if let (Some(username), Some(password)) = (&config.username, &config.password) { if let (Some(username), Some(password)) = (&config.username, &config.password) {
db.signin(Root { db.signin(Root {
username: username.as_str(), username: username.clone(),
password: password.as_str(), password: password.clone(),
}) })
.await .await
.map_err(|error| error.to_string())?; .map_err(|error| error.to_string())?;

View File

@ -4,6 +4,9 @@ Forge uses SurrealDB for durable storage. The Rust server extension connects to
SurrealDB on startup and applies Forge schema modules automatically, so setup SurrealDB on startup and applies Forge schema modules automatically, so setup
comes down to running a reachable database and matching the Forge config. comes down to running a reachable database and matching the Forge config.
Forge currently targets the SurrealDB `3.x` server line. Do not pair this
build of the extension with a `2.x` SurrealDB server.
## Choose the Right Path ## Choose the Right Path
### Developer or Server Operator ### Developer or Server Operator