| Crates.io | drasi-reaction-storedproc-mssql |
| lib.rs | drasi-reaction-storedproc-mssql |
| version | 0.2.1 |
| created_at | 2026-01-15 06:33:15.193104+00 |
| updated_at | 2026-01-23 06:26:14.458613+00 |
| description | MS SQL Server Stored Procedure reaction plugin for Drasi |
| homepage | |
| repository | https://github.com/drasi-project/drasi-core |
| max_upload_size | |
| id | 2044700 |
| size | 170,094 |
A Drasi reaction plugin that invokes MS SQL Server stored procedures when continuous query results change.
The MS SQL Server Stored Procedure reaction enables you to:
@fieldName syntaxAdd the dependency to your Cargo.toml:
[dependencies]
drasi-reaction-storedproc-mssql = { path = "path/to/drasi-core/components/reactions/storedproc-mssql" }
CREATE PROCEDURE add_user
@p_id INT,
@p_name NVARCHAR(255),
@p_email NVARCHAR(255)
AS
BEGIN
INSERT INTO users_sync (id, name, email)
VALUES (@p_id, @p_name, @p_email);
END;
GO
CREATE PROCEDURE update_user
@p_id INT,
@p_name NVARCHAR(255),
@p_email NVARCHAR(255)
AS
BEGIN
UPDATE users_sync
SET name = @p_name, email = @p_email
WHERE id = @p_id;
END;
GO
CREATE PROCEDURE delete_user
@p_id INT
AS
BEGIN
DELETE FROM users_sync WHERE id = @p_id;
END;
GO
use drasi_reaction_storedproc_mssql::MsSqlStoredProcReaction;
use drasi_lib::DrasiLib;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let reaction = MsSqlStoredProcReaction::builder("user-sync")
.with_connection(
"localhost",
1433,
"mydb",
"sa",
"YourPassword123!"
)
.with_query("user-changes")
.with_added_command("EXEC add_user @id, @name, @email")
.with_updated_command("EXEC update_user @id, @name, @email")
.with_deleted_command("EXEC delete_user @id")
.build()
.await?;
let drasi = DrasiLib::builder()
.with_id("my-app")
.with_reaction(reaction)
.build()
.await?;
drasi.start().await?;
tokio::signal::ctrl_c().await?;
Ok(())
}
let reaction = MsSqlStoredProcReaction::builder("my-reaction")
.with_hostname("localhost")
.with_port(1433)
.with_database("mydb")
.with_user("sa")
.with_password("YourPassword123!")
.with_ssl(true) // Enable TLS encryption
.with_query("query1")
.with_added_command("EXEC add_record @id, @name")
.with_updated_command("EXEC update_record @id, @name")
.with_deleted_command("EXEC delete_record @id")
.with_command_timeout_ms(30000)
.with_retry_attempts(3)
.build()
.await?;
| Option | Description | Type | Default |
|---|---|---|---|
hostname |
Database hostname | String |
"localhost" |
port |
Database port | u16 |
1433 |
user |
Database user | String |
Required |
password |
Database password | String |
Required |
database |
Database name | String |
Required |
ssl |
Enable TLS encryption | bool |
false |
added_command |
Procedure for ADD operations | Option<String> |
None |
updated_command |
Procedure for UPDATE operations | Option<String> |
None |
deleted_command |
Procedure for DELETE operations | Option<String> |
None |
command_timeout_ms |
Command timeout | u64 |
30000 |
retry_attempts |
Number of retries | u32 |
3 |
Use the @fieldName syntax in your command to reference fields from query results. The reaction will automatically map them to MS SQL parameters:
.with_added_command("EXEC add_user @id, @name, @email")
Query result:
{
"id": 1,
"name": "Alice",
"email": "alice@example.com"
}
Executes:
EXEC add_user @p1=1, @p2='Alice', @p3='alice@example.com'
Note: The @fieldName in your command is a placeholder syntax. The actual SQL uses @p1, @p2, @p3 parameter names internally.
.with_added_command("EXEC add_address @user.id, @address.city")
The reaction includes automatic retry logic with exponential backoff:
sa account should have a strong password.with_ssl(true) for production deploymentsCopyright 2025 The Drasi Authors.
Licensed under the Apache License, Version 2.0.