Skip to content

Commit fb25672

Browse files
author
Peng Ren
committed
Update README with new features
1 parent da37a09 commit fb25672

File tree

2 files changed

+22
-71
lines changed

2 files changed

+22
-71
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,28 @@ Parameters are substituted into the MongoDB filter during execution, providing p
223223
- **Logical operators**: `WHERE age > 18 AND status = 'active'`, `WHERE age < 30 OR role = 'admin'`
224224
- **Nested field filtering**: `WHERE profile.status = 'active'`
225225
- **Array filtering**: `WHERE items[0].price > 100`
226+
- **Date/DateTime functions**: `WHERE created_at > date('2023-01-01')`, `WHERE updated_at > datetime('2023-06-01 00:00:00')`
227+
228+
### SQL Functions
229+
230+
PyMongoSQL supports SQL functions in two distinct contexts:
231+
232+
**Projection Functions (SELECT clause)** - Convert MongoDB types to Python types for display:
233+
- **Date/Time**: `DATE()`, `DATETIME()`, `TIMESTAMP()` - Convert MongoDB dates to Python date/datetime objects
234+
- Supports custom format: `DATE(created_at, '%Y-%m-%d')`, `DATETIME(updated_at, '%Y-%m-%d %H:%M:%S')`
235+
- **Type Conversion**: `NUMBER()`, `BOOL()` - Convert values to numeric or boolean types
236+
- **String Manipulation**: `SUBSTR()`, `REPLACE()`, `TRIM()`, `UPPER()`, `LOWER()` - Process string values
237+
238+
Example: `SELECT DATE(created_at) AS date, DATE(created_at, '%d/%m/%Y') AS formatted_date, UPPER(name) AS name FROM users`
239+
240+
**WHERE Clause Functions** - Convert string values to MongoDB types for filtering:
241+
- **Date/Time only**: `DATE()`, `DATETIME()`, `TIMESTAMP()` - Convert string filters to MongoDB date objects
242+
- Supports custom format: `WHERE created_at > date('01/01/2023', '%d/%m/%Y')`
243+
- Returns datetime with UTC timezone for BSON compatibility
244+
245+
Example: `SELECT * FROM users WHERE created_at > date('2023-01-01') AND updated_at > datetime('2023-06-01 00:00:00', '%Y-%m-%d %H:%M:%S')`
246+
247+
Note: WHERE clause supports only date/datetime functions. String functions like UPPER() work differently in WHERE vs SELECT contexts.
226248

227249
### Nested Field Support
228250
- **Single-level**: `profile.name`, `settings.theme`

tests/README.md

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)