pub async fn create_record(
model_name: String,
request: MutationRequest,
site: Arc<AdminSite>,
db: Arc<AdminDatabase>,
) -> Result<MutationResponse, ServerFnError>Available on non-WebAssembly only.
Expand description
Create a new model instance
Inserts a new record into the database using the provided field data. Returns the number of affected rows (typically 1) on success.
§Server Function
This function is automatically exposed as an HTTP endpoint by the #[server_fn] macro.
AdminSite and AdminDatabase dependencies are automatically injected via the DI system.
§Example
ⓘ
use reinhardt_admin::server::create_record;
use reinhardt_admin::types::MutationRequest;
use std::collections::HashMap;
// Client-side usage (automatically generates HTTP request)
let mut data = HashMap::new();
data.insert("username".to_string(), serde_json::json!("alice"));
data.insert("email".to_string(), serde_json::json!("alice@example.com"));
let request = MutationRequest { data };
let response = create_record("User".to_string(), request).await?;
println!("Created: {}", response.message);