Files
sql-utilities/docs/SqlUtilities.Snowflake.md

66 lines
2.1 KiB
Markdown

# Strata.SqlTools.Snowflake
Snowflake SQL specific implementations for the Strata.SqlTools library.
## Features
- **QueryBreakdown**: Parse and generate Snowflake SQL SELECT queries
- **DeleteBreakdown**: Parse and generate DELETE statements
- **InsertBreakdown**: Parse and generate INSERT statements
- **UpdateBreakdown**: Parse and generate UPDATE statements
- **ProcedureBreakdown**: Parse and generate stored procedure CALL statements
- **Statement Parsing**: Token-based Snowflake SQL parsing
- **Command Visitor**: Snowflake-specific SQL generation
- **Parameter Support**: Both `:parameter` and `@parameter` syntax
## Installation
```bash
dotnet add package Strata.SqlTools.Snowflake
```
## Usage
```csharp
using Strata.SqlTools.Breakdowns.Snowflake;
// Parse a Snowflake SQL query (supports both @ and : parameters)
var query = QueryBreakdown.Parse(@"
SELECT customer_id, customer_name
FROM customers
WHERE region = :region
");
// Parameters are automatically extracted during parsing
Assert.That(query.Parameters, Does.ContainKey(":region"));
// Modify and regenerate - parameters are automatically extracted
query.AddWhereClause("is_active = true", "and");
query.AddWhereClause("created_date > :start_date", "and", false); // false = Snowflake parsing
// The :start_date parameter is now in the Parameters dictionary
query.SetParameterValue(":start_date", "2024-01-01");
query.SetParameterValue(":region", "WEST");
string sql = query.GetSql();
```
### Automatic Parameter Extraction
The `AddWhereClause` method automatically extracts both `:parameter` (Snowflake) and `@parameter` (T-SQL) references:
- Parameters are created with `null` values initially
- Use `SetParameterValue` to assign actual values
- Supports both `:param` and `@param` syntax based on the `isMicrosoftSql` flag
- Existing parameter values are preserved when adding additional WHERE clauses
- Type mismatches throw `InvalidOperationException` for safety
## Dependencies
- Strata.SqlTools.SqlServer (inherits SQL Server functionality)
- Strata.SqlTools (core library)
## License
MIT License - see LICENSE.txt for details