rawsql-ts 0.10.2-beta → 0.10.4-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -17
- package/dist/esm/index.min.js +11 -11
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/parsers/FunctionExpressionParser.js +18 -4
- package/dist/esm/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/esm/parsers/ValueParser.js +56 -11
- package/dist/esm/parsers/ValueParser.js.map +1 -1
- package/dist/esm/transformers/CTECollector.js +6 -1
- package/dist/esm/transformers/CTECollector.js.map +1 -1
- package/dist/esm/transformers/SqlParamInjector.js +301 -17
- package/dist/esm/transformers/SqlParamInjector.js.map +1 -1
- package/dist/esm/transformers/TableSourceCollector.js +8 -1
- package/dist/esm/transformers/TableSourceCollector.js.map +1 -1
- package/dist/esm/types/parsers/FunctionExpressionParser.d.ts +6 -1
- package/dist/esm/types/parsers/ValueParser.d.ts +9 -1
- package/dist/esm/types/transformers/CTECollector.d.ts +1 -0
- package/dist/esm/types/transformers/SqlParamInjector.d.ts +11 -1
- package/dist/esm/types/transformers/TableSourceCollector.d.ts +1 -0
- package/dist/esm/types/utils/OperatorPrecedence.d.ts +29 -0
- package/dist/esm/types/utils/ParameterRemover.d.ts +225 -0
- package/dist/esm/utils/OperatorPrecedence.js +79 -0
- package/dist/esm/utils/OperatorPrecedence.js.map +1 -0
- package/dist/esm/utils/ParameterRemover.js +777 -0
- package/dist/esm/utils/ParameterRemover.js.map +1 -0
- package/dist/index.min.js +11 -11
- package/dist/index.min.js.map +4 -4
- package/dist/parsers/FunctionExpressionParser.d.ts +6 -1
- package/dist/parsers/FunctionExpressionParser.js +18 -4
- package/dist/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/parsers/ValueParser.d.ts +9 -1
- package/dist/parsers/ValueParser.js +55 -10
- package/dist/parsers/ValueParser.js.map +1 -1
- package/dist/transformers/CTECollector.d.ts +1 -0
- package/dist/transformers/CTECollector.js +5 -0
- package/dist/transformers/CTECollector.js.map +1 -1
- package/dist/transformers/SqlParamInjector.d.ts +11 -1
- package/dist/transformers/SqlParamInjector.js +301 -17
- package/dist/transformers/SqlParamInjector.js.map +1 -1
- package/dist/transformers/TableSourceCollector.d.ts +1 -0
- package/dist/transformers/TableSourceCollector.js +7 -0
- package/dist/transformers/TableSourceCollector.js.map +1 -1
- package/dist/utils/OperatorPrecedence.d.ts +29 -0
- package/dist/utils/OperatorPrecedence.js +83 -0
- package/dist/utils/OperatorPrecedence.js.map +1 -0
- package/dist/utils/ParameterRemover.d.ts +225 -0
- package/dist/utils/ParameterRemover.js +781 -0
- package/dist/utils/ParameterRemover.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
@@ -23,7 +23,7 @@ It is designed for extensibility and advanced SQL analysis, with initial focus o
|
|
23
23
|
- High-speed SQL parsing and AST analysis (over 3x faster than major libraries)
|
24
24
|
- Rich utilities for SQL structure transformation and analysis
|
25
25
|
- Advanced SQL formatting capabilities, including multi-line formatting and customizable styles
|
26
|
-
- Dynamic SQL parameter injection for building flexible search queries with `SqlParamInjector`
|
26
|
+
- Dynamic SQL parameter injection for building flexible search queries with `SqlParamInjector` (supports like, ilike, in, any, range queries, OR/AND conditions and more)
|
27
27
|
- Type-safe schema management and JSON mapping conversion with full TypeScript support
|
28
28
|
- Static query validation and regression testing against your database schema with `SqlSchemaValidator`, enabling early error detection and robust unit tests for schema changes.
|
29
29
|
|
@@ -64,43 +64,46 @@ npm install rawsql-ts
|
|
64
64
|
|
65
65
|
## Quick Start
|
66
66
|
|
67
|
-
---
|
68
|
-
|
69
67
|
Kickstart your project by dynamically injecting parameters with `SqlParamInjector` for flexible query generation right from the start!
|
70
68
|
|
71
69
|
```typescript
|
72
70
|
import { SqlParamInjector, SqlFormatter } from 'rawsql-ts';
|
73
71
|
|
74
|
-
// Define a base SQL query with an alias
|
75
|
-
const baseSql = `SELECT u.user_id, u.user_name, u.email FROM users as u WHERE u.active = TRUE`;
|
72
|
+
// Define a base SQL query with an alias
|
73
|
+
const baseSql = `SELECT u.user_id, u.user_name, u.email, u.phone FROM users as u WHERE u.active = TRUE`;
|
76
74
|
|
77
|
-
//
|
75
|
+
// Search parameters with OR conditions and AND combination
|
78
76
|
const searchParams = {
|
79
|
-
|
80
|
-
|
77
|
+
name_or_email: {
|
78
|
+
or: [
|
79
|
+
{ column: 'user_name', ilike: '%alice%' },
|
80
|
+
{ column: 'email', ilike: '%alice%' }
|
81
|
+
]
|
82
|
+
},
|
83
|
+
phone: { like: '%080%' } // AND condition
|
81
84
|
};
|
82
85
|
|
83
86
|
const injector = new SqlParamInjector();
|
84
87
|
// Dynamically inject searchParams into the baseSql
|
85
88
|
const query = injector.inject(baseSql, searchParams);
|
86
89
|
|
87
|
-
// Format the dynamically generated query
|
90
|
+
// Format the dynamically generated query
|
88
91
|
const formatter = new SqlFormatter({ preset: 'postgres' });
|
89
92
|
const { formattedSql, params } = formatter.format(query);
|
90
93
|
|
91
|
-
console.log('
|
94
|
+
console.log('Generated SQL:');
|
92
95
|
console.log(formattedSql);
|
93
|
-
//
|
94
|
-
// select "u"."user_id", "u"."user_name", "u"."email"
|
96
|
+
// Output:
|
97
|
+
// select "u"."user_id", "u"."user_name", "u"."email", "u"."phone"
|
95
98
|
// from "users" as "u"
|
96
99
|
// where "u"."active" = true
|
97
|
-
//
|
98
|
-
//
|
100
|
+
// and ("u"."user_name" ilike :name_or_email_or_0_ilike
|
101
|
+
// or "u"."email" ilike :name_or_email_or_1_ilike)
|
102
|
+
// and "u"."phone" like :phone_like
|
99
103
|
|
100
|
-
console.log('
|
104
|
+
console.log('Parameters:');
|
101
105
|
console.log(params);
|
102
|
-
//
|
103
|
-
// { user_name_like: '%Alice%', email: 'specific.email@example.com' }
|
106
|
+
// Output: { name_or_email_or_0_ilike: '%alice%', name_or_email_or_1_ilike: '%alice%', phone_like: '%080%' }
|
104
107
|
```
|
105
108
|
|
106
109
|
---
|
@@ -177,6 +180,8 @@ Key benefits include:
|
|
177
180
|
- **Performance-Oriented**: Conditions are intelligently inserted as close to the data source as possible, significantly improving query performance by filtering data early.
|
178
181
|
- **Zero Conditional Logic in Code**: Forget writing complex IF statements in your application code to handle different filters.
|
179
182
|
- **Enhanced SQL Reusability**: Your base SQL remains clean and can be reused across different scenarios with varying search criteria.
|
183
|
+
- **Rich Operator Support**: Supports various SQL operators including equality, comparison, range (min/max), pattern matching (like/ilike), IN clauses, and PostgreSQL array operators.
|
184
|
+
- **Advanced Condition Logic**: Supports OR/AND conditions, automatic parentheses grouping, and explicit column mapping for flexible query construction.
|
180
185
|
|
181
186
|
```typescript
|
182
187
|
import { SqlParamInjector, SqlFormatter } from 'rawsql-ts';
|