Back to articles
Adding a Scripting Engine to a Rust CLI with Rhai
How-ToTools

Adding a Scripting Engine to a Rust CLI with Rhai

via Dev.toAlex Yarotsky

diesel-guard is a linter for Postgres migrations. It catches operations that lock tables or cause downtime before they reach production. It ships with 28 built-in checks, but over time, users started asking for custom checks: "Our DBA requires all indexes to follow the naming convention idx_<table>_<column> . Can I enforce that?" "Our team convention is that every new table must have an updated_at column. Can diesel-guard catch tables that don't?" Each request is completely reasonable. But each one is unique enough that it did not make sense to add a built-in check for it. So telling users "open a PR" for a one-off team convention felt like the wrong answer. The solution was to let users write the rule themselves, as a script, loaded at runtime, without recompiling. This post covers how I did it with Rhai . Why Rhai Rhai is an embedded scripting language written in Rust. You drop it into your project as you would any other crate, and scripts run within your process at runtime. I came a

Continue reading on Dev.to

Opens in a new tab

Read Full Article
6 views

Related Articles