rawsql-ts 0.10.3-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 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, using TRUE for boolean conditions
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
- // Imagine you have search parameters from a user's input
75
+ // Search parameters with OR conditions and AND combination
78
76
  const searchParams = {
79
- user_name: { like: '%Alice%' }, // Find users whose name contains 'Alice'
80
- email: 'specific.email@example.com' // And have a specific email
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 (e.g., using PostgreSQL preset)
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('Dynamically Generated SQL:');
94
+ console.log('Generated SQL:');
92
95
  console.log(formattedSql);
93
- // Expected output (PostgreSQL style):
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
- // and "u"."user_name" like :user_name_like
98
- // and "u"."email" = :email
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('\\nParameters:');
104
+ console.log('Parameters:');
101
105
  console.log(params);
102
- // Expected output:
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';