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!.
Cargo re-compiles whenever a include_str!-referenced file changes, so the binary always reflects the latest schema. run_sync_embedded_with_opts 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. You build a RolloutSpec that describes the steps for each phase, then call run_start_with_spec and run_complete_with_spec at the appropriate points around your application deployment.
After run_start_with_spec succeeds, deploy your application. Once the new version is stable, call run_complete_with_spec to apply the contract phase:
run_complete_with_spec(&db,&spec).await?;
If something goes wrong before completing, roll back the start phase:
usesurrealkit::run_rollback_with_spec;
run_rollback_with_spec(&db,&spec).await?;
In practice, RolloutSpec is typically deserialised from a generated .toml manifest rather than constructed by hand. The CLI's rollout plan command produces these manifests, which your deployment tooling can load and pass to the library functions.