prax-mssql
Microsoft SQL Server query engine for Prax ORM.
Overview
prax-mssql provides an async SQL Server backend using tiberius with bb8 connection pooling.
Features
- Async query execution with Tokio
- Connection pooling via bb8
- Transaction support with savepoints
- Row-Level Security (RLS) policy generation
- Session context management for RLS
- SQL Server authentication and Windows Authentication support
- TLS/SSL encryption support
Usage
use ;
let pool = builder
.host
.database
.username
.password
.max_connections
.trust_cert // For development
.build
.await?;
// Create engine for Prax queries
let engine = new;
Connection Strings
Both URL-style and ADO.NET-style connection strings are supported:
// URL-style
let config = from_connection_string?;
// ADO.NET-style
let config = from_connection_string?;
Row-Level Security
Generate SQL Server security policies from Prax schema definitions:
use ;
// Generate security policy from Prax policy
let generator = new;
let security_policy = generator.generate?;
// Apply the policy
conn.batch_execute.await?;
// Set session context for RLS
conn.set_session_context.await?;
Policy Generation
The generator converts Prax policies to SQL Server security policies:
-- Generated schema
;
GO
-- Generated predicate function
(@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);
Session Context
Set up RLS context for a connection:
use RlsContextBuilder;
let sql = new
.user_id
.tenant_id
.custom
.to_sql;
conn.batch_execute.await?;
Configuration
use ;
use Duration;
let config = builder
.host
.port
.database
.username
.password
.encryption
.trust_cert
.connect_timeout
.application_name
.build?;
Azure SQL Database
For Azure SQL Database, use these recommended settings:
let pool = builder
.host
.database
.username
.password
.encryption
.trust_cert
.build
.await?;
SQL Dialect Conversion
The engine automatically converts PostgreSQL-style queries to SQL Server:
- Parameter placeholders:
$1→@P1 - Boolean literals:
true/false→1/0 - LIMIT/OFFSET →
OFFSET FETCH - RETURNING →
OUTPUT INSERTED.*
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Microsoft SQL Server query engine for Prax ORM.
Overview
prax-mssql provides an async SQL Server backend using tiberius with bb8 connection pooling.
Features
- Async query execution with Tokio
- Connection pooling via bb8
- Transaction support with savepoints
- Row-Level Security (RLS) policy generation
- Session context management for RLS
- SQL Server authentication and Windows Authentication support
- TLS/SSL encryption support
Usage
use ;
let pool = builder
.host
.database
.username
.password
.max_connections
.trust_cert // For development
.build
.await?;
// Create engine for Prax queries
let engine = new;
Connection Strings
Both URL-style and ADO.NET-style connection strings are supported:
// URL-style
let config = from_connection_string?;
// ADO.NET-style
let config = from_connection_string?;
Row-Level Security
Generate SQL Server security policies from Prax schema definitions:
use ;
// Generate security policy from Prax policy
let generator = new;
let security_policy = generator.generate?;
// Apply the policy
conn.batch_execute.await?;
// Set session context for RLS
conn.set_session_context.await?;
Policy Generation
The generator converts Prax policies to SQL Server security policies:
-- Generated schema
;
GO
-- Generated predicate function
(@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);
Session Context
Set up RLS context for a connection:
use RlsContextBuilder;
let sql = new
.user_id
.tenant_id
.custom
.to_sql;
conn.batch_execute.await?;
Configuration
use ;
use Duration;
let config = builder
.host
.port
.database
.username
.password
.encryption
.trust_cert
.connect_timeout
.application_name
.build?;
Azure SQL Database
For Azure SQL Database, use these recommended settings:
let pool = builder
.host
.database
.username
.password
.encryption
.trust_cert
.build
.await?;
SQL Dialect Conversion
The engine automatically converts PostgreSQL-style queries to SQL Server:
- Parameter placeholders:
$1→@P1 - Boolean literals:
true/false→1/0 - LIMIT/OFFSET →
OFFSET FETCH - RETURNING →
OUTPUT INSERTED.*
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Microsoft SQL Server query engine for Prax ORM.
Overview
prax-mssql provides an async SQL Server backend using tiberius with bb8 connection pooling.
Features
- Async query execution with Tokio
- Connection pooling via bb8
- Transaction support with savepoints
- Row-Level Security (RLS) policy generation
- Session context management for RLS
- SQL Server authentication and Windows Authentication support
- TLS/SSL encryption support
Usage
use ;
let pool = builder
.host
.database
.username
.password
.max_connections
.trust_cert // For development
.build
.await?;
// Create engine for Prax queries
let engine = new;
Connection Strings
Both URL-style and ADO.NET-style connection strings are supported:
// URL-style
let config = from_connection_string?;
// ADO.NET-style
let config = from_connection_string?;
Row-Level Security
Generate SQL Server security policies from Prax schema definitions:
use ;
// Generate security policy from Prax policy
let generator = new;
let security_policy = generator.generate?;
// Apply the policy
conn.batch_execute.await?;
// Set session context for RLS
conn.set_session_context.await?;
Policy Generation
The generator converts Prax policies to SQL Server security policies:
-- Generated schema
;
GO
-- Generated predicate function
(@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);
Session Context
Set up RLS context for a connection:
use RlsContextBuilder;
let sql = new
.user_id
.tenant_id
.custom
.to_sql;
conn.batch_execute.await?;
Configuration
use ;
use Duration;
let config = builder
.host
.port
.database
.username
.password
.encryption
.trust_cert
.connect_timeout
.application_name
.build?;
Azure SQL Database
For Azure SQL Database, use these recommended settings:
let pool = builder
.host
.database
.username
.password
.encryption
.trust_cert
.build
.await?;
SQL Dialect Conversion
The engine automatically converts PostgreSQL-style queries to SQL Server:
- Parameter placeholders:
$1→@P1 - Boolean literals:
true/false→1/0 - LIMIT/OFFSET →
OFFSET FETCH - RETURNING →
OUTPUT INSERTED.*
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Microsoft SQL Server query engine for Prax ORM.
Overview
prax-mssql provides an async SQL Server backend using tiberius with bb8 connection pooling.
Features
- Async query execution with Tokio
- Connection pooling via bb8
- Transaction support with savepoints
- Row-Level Security (RLS) policy generation
- Session context management for RLS
- SQL Server authentication and Windows Authentication support
- TLS/SSL encryption support
Usage
use ;
let pool = builder
.host
.database
.username
.password
.max_connections
.trust_cert // For development
.build
.await?;
// Create engine for Prax queries
let engine = new;
Connection Strings
Both URL-style and ADO.NET-style connection strings are supported:
// URL-style
let config = from_connection_string?;
// ADO.NET-style
let config = from_connection_string?;
Row-Level Security
Generate SQL Server security policies from Prax schema definitions:
use ;
// Generate security policy from Prax policy
let generator = new;
let security_policy = generator.generate?;
// Apply the policy
conn.batch_execute.await?;
// Set session context for RLS
conn.set_session_context.await?;
Policy Generation
The generator converts Prax policies to SQL Server security policies:
-- Generated schema
;
GO
-- Generated predicate function
(@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);
Session Context
Set up RLS context for a connection:
use RlsContextBuilder;
let sql = new
.user_id
.tenant_id
.custom
.to_sql;
conn.batch_execute.await?;
Configuration
use ;
use Duration;
let config = builder
.host
.port
.database
.username
.password
.encryption
.trust_cert
.connect_timeout
.application_name
.build?;
Azure SQL Database
For Azure SQL Database, use these recommended settings:
let pool = builder
.host
.database
.username
.password
.encryption
.trust_cert
.build
.await?;
SQL Dialect Conversion
The engine automatically converts PostgreSQL-style queries to SQL Server:
- Parameter placeholders:
$1→@P1 - Boolean literals:
true/false→1/0 - LIMIT/OFFSET →
OFFSET FETCH - RETURNING →
OUTPUT INSERTED.*
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.