Worked examples of using SurrealKit's library API for both sync and rollouts in a Rust application.
Worked examples of using SurrealKit's library API directly in Rust, covering both sync (for development and ephemeral databases) and rollouts (for shared and production databases).
DbCfg::from_env reads SURREALDB_HOST, SURREALDB_NAMESPACE, SURREALDB_NAME, SURREALDB_USER, and SURREALDB_PASSWORD from the environment or a .env file.
Sync
Use sync against local or ephemeral databases where fast iteration matters and pruning is safe. Schema files are embedded at compile time with include_str!, then applied with the Sync builder.
// Optionally load seed data after syncing. seed(&db,"database",&TemplateVars::default()).await?;
Ok(()) }
Cargo re-compiles whenever an include_str!-referenced file changes, so the binary always reflects the latest schema. Sync::embedded(...).run(...) applies new or changed definitions and removes any that have been deleted from the schema files.
Seed files run on every startup, so use UPSERT or guard inserts if idempotency matters.
Rollouts
Use rollouts for shared and production databases. Build a RolloutSpec with the builder, wrap it in the Rollout facade, then call start and complete at the appropriate points around your application deployment.
// `&[]` here means the steps fully describe the entity changes. Pass the // desired post-rollout schema files to have SurrealKit compute the catalog. letrollout=Rollout::new(spec,&[]);
rollout.start(&db).await?;
Ok(()) }
After start succeeds, deploy your application. Once the new version is stable, call complete to apply the contract phase:
rollout.complete(&db).await?;
If something goes wrong before completing, roll back the start phase:
rollout.rollback(&db).await?;
If a process is killed mid-rollout, the __rollout row can be left in a running_* state. Inspect it with rollout.status(&db).await? and recover it with the CLI rollout repair command or Rollout::abandon(&db, "20260604__add_account").await?.