You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Added badges for license, code size, last commit, and NuGet version.
- Organized and numbered sections for SQL query parsing and modification.
- Clarified expected SQL output and improved code examples.
- Introduced new features for modifying columns, managing UNION queries, and filtering with outer joins.
- Highlighted the benefits of CarbunqleX for SQL maintainability and reusability.

@@ -32,15 +32,15 @@ Unlike conventional SQL libraries, CarbunqleX automatically determines the most
32
32
33
33
## 📦 Installation
34
34
35
-
To install [Carbunqlex](https://www.nuget.org/packages/Carbunqlex/), use the following command:
35
+
[Carbunqlex](https://www.nuget.org/packages/Carbunqlex/) can be installed from NuGet. To install using the package manager, use the following command:
36
36
37
37
```sh
38
-
PM>NuGet\Install-Package Carbunqlex
38
+
NuGet\Install-Package Carbunqlex
39
39
```
40
40
41
41
## 📖 Documentation
42
42
43
-
### 1️⃣ Parsing a SQL Query
43
+
### 1. Parsing a SQL Query
44
44
45
45
Let's start by parsing a simple SQL query into an AST using `QueryAstParser.Parse`. We will then convert it back to SQL with `ToSql` and inspect its structure using `ToTreeString`.
46
46
@@ -60,9 +60,15 @@ Console.WriteLine("* AST");
60
60
Console.WriteLine(query.ToTreeString());
61
61
```
62
62
63
-
This basic example demonstrates how CarbunqleX converts SQL into a structured AST representation, making it easier to analyze and manipulate queries programmatically.
63
+
#### 🔍 Expected SQL Output
64
+
65
+
```sql
66
+
SELECTa.table_a_id, a.valueFROM table_a AS a
67
+
```
68
+
69
+
This makes it easy to convert between them.
64
70
65
-
### 2️⃣ Modifying the WHERE Clause
71
+
### 2. Modifying the WHERE Clause
66
72
67
73
Now, let's modify the query by injecting a `WHERE` condition.
68
74
@@ -83,11 +89,11 @@ FROM table_a AS a
83
89
WHEREa.value=1;
84
90
```
85
91
86
-
CarbunqleX automatically determines where to insert the condition while maintaining SQL integrity.
92
+
CarbunqleX allows you to inject conditions while still maintaining the integrity of your SQL.
87
93
88
-
### 3️⃣ Handling CTEs and Subqueries
94
+
### 3. Handling CTEs and Subqueries
89
95
90
-
Let's take it a step further by injecting a `WHERE` condition into a query that includes **CTEs and subqueries**.
96
+
Let's try to insert a `WHERE` condition into a query that contains a **CTE and a subquery**.
91
97
92
98
```csharp
93
99
varquery=QueryAstParser.Parse("""
@@ -129,11 +135,11 @@ WHERE orders.region IN (SELECT x.region FROM top_regions x)
129
135
GROUP BYorders.region, orders.product;
130
136
```
131
137
132
-
CarbunqleX **intelligently places the condition in the deepest relevant query**, ensuring correctness.
138
+
CarbunqleX will **intelligently place the condition in the deepest related query**. It will also **dynamically merge CTEs**.
133
139
134
-
### 4️⃣ Advanced Filtering
140
+
### 4. Standardizing filtering
135
141
136
-
Now, let's introduce a **more advanced use case** where we dynamically filter data based on user permissions. We'll define a reusable function to retrieve regions a user has access to and use it in a filtering condition.
142
+
Next, we will introduce a more advanced use case that dynamically filters data based on user permissions. We define the areas that users can access as reusable functions.
137
143
138
144
#### 🔧 Define a Subquery Function
139
145
@@ -186,7 +192,89 @@ WHERE orders.region IN (SELECT x.region FROM top_regions AS x)
186
192
GROUP BYorders.region, orders.product
187
193
```
188
194
189
-
By dynamically injecting permission-based filtering, we can ensure **secure and flexible query customization**.
195
+
By making filtering a function, we can express queries that are **highly maintainable and versatile**.
196
+
197
+
### **5. Modify columns**
198
+
199
+
This feature is useful for enforcing constraints such as **closing date control in accounting** by ensuring a column value does not fall below a specified threshold.
200
+
201
+
```csharp
202
+
varquery=QueryAstParser.Parse("SELECT s.sale_date, s.sales_amount FROM sales AS s");
// left join top_regions as tp on orders.region = tp.region where tp.region is null
276
+
varexpected="with regional_sales as (select orders.region, SUM(orders.amount) as total_sales from orders left join top_regions as tp on orders.region = tp.region where tp.region is null group by orders.region), top_regions as (select rs.region from regional_sales as rs where rs.total_sales > (select SUM(x.total_sales) / 10 from regional_sales as x)) select orders.region, orders.product, SUM(orders.quantity) as product_units, SUM(orders.amount) as product_sales from orders where orders.region in (select x.region from top_regions as x) group by orders.region, orders.product";
0 commit comments