| Crates.io | prax-mssql |
| lib.rs | prax-mssql |
| version | 0.5.0 |
| created_at | 2025-12-29 01:17:12.027898+00 |
| updated_at | 2026-01-07 18:39:17.409653+00 |
| description | Microsoft SQL Server database driver for Prax ORM |
| homepage | |
| repository | https://github.com/pegasusheavy/prax-orm |
| max_upload_size | |
| id | 2009744 |
| size | 170,449 |
Microsoft SQL Server query engine for Prax ORM.
prax-mssql provides an async SQL Server backend using tiberius with bb8 connection pooling.
use prax_mssql::{MssqlPool, MssqlEngine};
let pool = MssqlPool::builder()
.host("localhost")
.database("mydb")
.username("sa")
.password("YourPassword123!")
.max_connections(10)
.trust_cert(true) // For development
.build()
.await?;
// Create engine for Prax queries
let engine = MssqlEngine::new(pool);
Both URL-style and ADO.NET-style connection strings are supported:
// URL-style
let config = MssqlConfig::from_connection_string(
"mssql://sa:Password@localhost:1433/mydb?encrypt=true"
)?;
// ADO.NET-style
let config = MssqlConfig::from_connection_string(
"Server=localhost;Database=mydb;User Id=sa;Password=Password;"
)?;
Generate SQL Server security policies from Prax schema definitions:
use prax_mssql::rls::{SecurityPolicyGenerator, RlsContextBuilder};
// Generate security policy from Prax policy
let generator = SecurityPolicyGenerator::new("Security");
let security_policy = generator.generate(&policy, "dbo.Users", "UserId")?;
// Apply the policy
conn.batch_execute(&security_policy.to_sql()).await?;
// Set session context for RLS
conn.set_session_context("UserId", "123").await?;
The generator converts Prax policies to SQL Server security policies:
-- Generated schema
CREATE SCHEMA Security;
GO
-- Generated predicate function
CREATE FUNCTION Security.fn_UserFilter_predicate(@UserId INT)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN SELECT 1 AS fn_securitypredicate_result
WHERE @UserId = CAST(SESSION_CONTEXT(N'UserId') AS INT);
GO
-- Generated security policy
CREATE SECURITY POLICY Security.UserFilter
ADD FILTER PREDICATE Security.fn_UserFilter_predicate(UserId) ON dbo.Users,
ADD BLOCK PREDICATE Security.fn_UserFilter_predicate(UserId) ON dbo.Users AFTER INSERT
WITH (STATE = ON);
Set up RLS context for a connection:
use prax_mssql::rls::RlsContextBuilder;
let sql = RlsContextBuilder::new()
.user_id("123")
.tenant_id("456")
.custom("Role", "Admin")
.to_sql();
conn.batch_execute(&sql).await?;
use prax_mssql::{MssqlConfig, EncryptionMode};
use std::time::Duration;
let config = MssqlConfig::builder()
.host("myserver.database.windows.net")
.port(1433)
.database("mydb")
.username("myuser")
.password("mypassword")
.encryption(EncryptionMode::Required)
.trust_cert(false)
.connect_timeout(Duration::from_secs(30))
.application_name("my-app")
.build()?;
For Azure SQL Database, use these recommended settings:
let pool = MssqlPool::builder()
.host("myserver.database.windows.net")
.database("mydb")
.username("myuser@myserver")
.password("mypassword")
.encryption(EncryptionMode::Required)
.trust_cert(false)
.build()
.await?;
The engine automatically converts PostgreSQL-style queries to SQL Server:
$1 → @P1true/false → 1/0OFFSET FETCHOUTPUT INSERTED.*Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Microsoft SQL Server query engine for Prax ORM.
prax-mssql provides an async SQL Server backend using tiberius with bb8 connection pooling.
use prax_mssql::{MssqlPool, MssqlEngine};
let pool = MssqlPool::builder()
.host("localhost")
.database("mydb")
.username("sa")
.password("YourPassword123!")
.max_connections(10)
.trust_cert(true) // For development
.build()
.await?;
// Create engine for Prax queries
let engine = MssqlEngine::new(pool);
Both URL-style and ADO.NET-style connection strings are supported:
// URL-style
let config = MssqlConfig::from_connection_string(
"mssql://sa:Password@localhost:1433/mydb?encrypt=true"
)?;
// ADO.NET-style
let config = MssqlConfig::from_connection_string(
"Server=localhost;Database=mydb;User Id=sa;Password=Password;"
)?;
Generate SQL Server security policies from Prax schema definitions:
use prax_mssql::rls::{SecurityPolicyGenerator, RlsContextBuilder};
// Generate security policy from Prax policy
let generator = SecurityPolicyGenerator::new("Security");
let security_policy = generator.generate(&policy, "dbo.Users", "UserId")?;
// Apply the policy
conn.batch_execute(&security_policy.to_sql()).await?;
// Set session context for RLS
conn.set_session_context("UserId", "123").await?;
The generator converts Prax policies to SQL Server security policies:
-- Generated schema
CREATE SCHEMA Security;
GO
-- Generated predicate function
CREATE FUNCTION Security.fn_UserFilter_predicate(@UserId INT)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN SELECT 1 AS fn_securitypredicate_result
WHERE @UserId = CAST(SESSION_CONTEXT(N'UserId') AS INT);
GO
-- Generated security policy
CREATE SECURITY POLICY Security.UserFilter
ADD FILTER PREDICATE Security.fn_UserFilter_predicate(UserId) ON dbo.Users,
ADD BLOCK PREDICATE Security.fn_UserFilter_predicate(UserId) ON dbo.Users AFTER INSERT
WITH (STATE = ON);
Set up RLS context for a connection:
use prax_mssql::rls::RlsContextBuilder;
let sql = RlsContextBuilder::new()
.user_id("123")
.tenant_id("456")
.custom("Role", "Admin")
.to_sql();
conn.batch_execute(&sql).await?;
use prax_mssql::{MssqlConfig, EncryptionMode};
use std::time::Duration;
let config = MssqlConfig::builder()
.host("myserver.database.windows.net")
.port(1433)
.database("mydb")
.username("myuser")
.password("mypassword")
.encryption(EncryptionMode::Required)
.trust_cert(false)
.connect_timeout(Duration::from_secs(30))
.application_name("my-app")
.build()?;
For Azure SQL Database, use these recommended settings:
let pool = MssqlPool::builder()
.host("myserver.database.windows.net")
.database("mydb")
.username("myuser@myserver")
.password("mypassword")
.encryption(EncryptionMode::Required)
.trust_cert(false)
.build()
.await?;
The engine automatically converts PostgreSQL-style queries to SQL Server:
$1 → @P1true/false → 1/0OFFSET FETCHOUTPUT INSERTED.*Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Microsoft SQL Server query engine for Prax ORM.
prax-mssql provides an async SQL Server backend using tiberius with bb8 connection pooling.
use prax_mssql::{MssqlPool, MssqlEngine};
let pool = MssqlPool::builder()
.host("localhost")
.database("mydb")
.username("sa")
.password("YourPassword123!")
.max_connections(10)
.trust_cert(true) // For development
.build()
.await?;
// Create engine for Prax queries
let engine = MssqlEngine::new(pool);
Both URL-style and ADO.NET-style connection strings are supported:
// URL-style
let config = MssqlConfig::from_connection_string(
"mssql://sa:Password@localhost:1433/mydb?encrypt=true"
)?;
// ADO.NET-style
let config = MssqlConfig::from_connection_string(
"Server=localhost;Database=mydb;User Id=sa;Password=Password;"
)?;
Generate SQL Server security policies from Prax schema definitions:
use prax_mssql::rls::{SecurityPolicyGenerator, RlsContextBuilder};
// Generate security policy from Prax policy
let generator = SecurityPolicyGenerator::new("Security");
let security_policy = generator.generate(&policy, "dbo.Users", "UserId")?;
// Apply the policy
conn.batch_execute(&security_policy.to_sql()).await?;
// Set session context for RLS
conn.set_session_context("UserId", "123").await?;
The generator converts Prax policies to SQL Server security policies:
-- Generated schema
CREATE SCHEMA Security;
GO
-- Generated predicate function
CREATE FUNCTION Security.fn_UserFilter_predicate(@UserId INT)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN SELECT 1 AS fn_securitypredicate_result
WHERE @UserId = CAST(SESSION_CONTEXT(N'UserId') AS INT);
GO
-- Generated security policy
CREATE SECURITY POLICY Security.UserFilter
ADD FILTER PREDICATE Security.fn_UserFilter_predicate(UserId) ON dbo.Users,
ADD BLOCK PREDICATE Security.fn_UserFilter_predicate(UserId) ON dbo.Users AFTER INSERT
WITH (STATE = ON);
Set up RLS context for a connection:
use prax_mssql::rls::RlsContextBuilder;
let sql = RlsContextBuilder::new()
.user_id("123")
.tenant_id("456")
.custom("Role", "Admin")
.to_sql();
conn.batch_execute(&sql).await?;
use prax_mssql::{MssqlConfig, EncryptionMode};
use std::time::Duration;
let config = MssqlConfig::builder()
.host("myserver.database.windows.net")
.port(1433)
.database("mydb")
.username("myuser")
.password("mypassword")
.encryption(EncryptionMode::Required)
.trust_cert(false)
.connect_timeout(Duration::from_secs(30))
.application_name("my-app")
.build()?;
For Azure SQL Database, use these recommended settings:
let pool = MssqlPool::builder()
.host("myserver.database.windows.net")
.database("mydb")
.username("myuser@myserver")
.password("mypassword")
.encryption(EncryptionMode::Required)
.trust_cert(false)
.build()
.await?;
The engine automatically converts PostgreSQL-style queries to SQL Server:
$1 → @P1true/false → 1/0OFFSET FETCHOUTPUT INSERTED.*Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Microsoft SQL Server query engine for Prax ORM.
prax-mssql provides an async SQL Server backend using tiberius with bb8 connection pooling.
use prax_mssql::{MssqlPool, MssqlEngine};
let pool = MssqlPool::builder()
.host("localhost")
.database("mydb")
.username("sa")
.password("YourPassword123!")
.max_connections(10)
.trust_cert(true) // For development
.build()
.await?;
// Create engine for Prax queries
let engine = MssqlEngine::new(pool);
Both URL-style and ADO.NET-style connection strings are supported:
// URL-style
let config = MssqlConfig::from_connection_string(
"mssql://sa:Password@localhost:1433/mydb?encrypt=true"
)?;
// ADO.NET-style
let config = MssqlConfig::from_connection_string(
"Server=localhost;Database=mydb;User Id=sa;Password=Password;"
)?;
Generate SQL Server security policies from Prax schema definitions:
use prax_mssql::rls::{SecurityPolicyGenerator, RlsContextBuilder};
// Generate security policy from Prax policy
let generator = SecurityPolicyGenerator::new("Security");
let security_policy = generator.generate(&policy, "dbo.Users", "UserId")?;
// Apply the policy
conn.batch_execute(&security_policy.to_sql()).await?;
// Set session context for RLS
conn.set_session_context("UserId", "123").await?;
The generator converts Prax policies to SQL Server security policies:
-- Generated schema
CREATE SCHEMA Security;
GO
-- Generated predicate function
CREATE FUNCTION Security.fn_UserFilter_predicate(@UserId INT)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN SELECT 1 AS fn_securitypredicate_result
WHERE @UserId = CAST(SESSION_CONTEXT(N'UserId') AS INT);
GO
-- Generated security policy
CREATE SECURITY POLICY Security.UserFilter
ADD FILTER PREDICATE Security.fn_UserFilter_predicate(UserId) ON dbo.Users,
ADD BLOCK PREDICATE Security.fn_UserFilter_predicate(UserId) ON dbo.Users AFTER INSERT
WITH (STATE = ON);
Set up RLS context for a connection:
use prax_mssql::rls::RlsContextBuilder;
let sql = RlsContextBuilder::new()
.user_id("123")
.tenant_id("456")
.custom("Role", "Admin")
.to_sql();
conn.batch_execute(&sql).await?;
use prax_mssql::{MssqlConfig, EncryptionMode};
use std::time::Duration;
let config = MssqlConfig::builder()
.host("myserver.database.windows.net")
.port(1433)
.database("mydb")
.username("myuser")
.password("mypassword")
.encryption(EncryptionMode::Required)
.trust_cert(false)
.connect_timeout(Duration::from_secs(30))
.application_name("my-app")
.build()?;
For Azure SQL Database, use these recommended settings:
let pool = MssqlPool::builder()
.host("myserver.database.windows.net")
.database("mydb")
.username("myuser@myserver")
.password("mypassword")
.encryption(EncryptionMode::Required)
.trust_cert(false)
.build()
.await?;
The engine automatically converts PostgreSQL-style queries to SQL Server:
$1 → @P1true/false → 1/0OFFSET FETCHOUTPUT INSERTED.*Licensed under either of Apache License, Version 2.0 or MIT license at your option.