新增 NOT LIKE、IS NULL 和 IS NOT NULL 操作符,并更新文档示例

This commit is contained in:
2025-12-31 13:11:07 +08:00
parent 8a4a720f5b
commit ae4fcacd9d
4 changed files with 97 additions and 8 deletions

View File

@@ -7,7 +7,7 @@
- **WHERE**: 条件过滤
- **ORDER BY**: 排序
- **LIMIT**: 限制结果数量
- **操作符**: `=`, `!=`, `>`, `<`, `>=`, `<=`, `IN`, `CONTAINS`, `LIKE`
- **操作符**: `=`, `!=`, `>`, `<`, `>=`, `<=`, `IN`, `CONTAINS`, `LIKE`, `NOT LIKE`, `IS NULL`, `IS NOT NULL`
- **逻辑**: `AND`, `OR`
## 语法示例
@@ -32,6 +32,15 @@ filter(users, "WHERE metadata.region IN ['beijing', 'shanghai']");
filter(products, "WHERE name LIKE '%Apple%'");
filter(products, "WHERE name LIKE 'Apple%'");
filter(products, "WHERE name LIKE '%Phone'");
// NOT LIKE 操作 (排除匹配模式的项)
filter(products, "WHERE name NOT LIKE '%Apple%'");
// IS NULL 操作 (匹配 null 或 undefined 的值)
filter(users, "WHERE email IS NULL");
// IS NOT NULL 操作 (匹配非 null 且非 undefined 的值)
filter(users, "WHERE email IS NOT NULL");
```
## 使用方法
@@ -72,3 +81,32 @@ const premiumUsers = filter(users, "WHERE metadata.tags CONTAINS 'premium'");
// 查找北京的用户,按创建时间倒序
const beijingUsers = filter(users, "WHERE metadata.region = 'beijing' ORDER BY metadata.created_at DESC");
```
## 新增操作符说明
### NOT LIKE
排除匹配指定模式的数据项。
```javascript
// 查找不包含 "Apple" 的产品
const nonAppleProducts = filter(products, "WHERE name NOT LIKE '%Apple%'");
```
### IS NULL / IS NOT NULL
检查字段值是否为 `null``undefined`
```javascript
const usersWithNullEmail = [
{ name: 'Alice', email: 'alice@example.com', age: 25 },
{ name: 'Bob', email: null, age: 30 },
{ name: 'Charlie', email: undefined, age: 35 },
];
// 查找 email 为 null 或 undefined 的用户
const usersWithoutEmail = filter(usersWithNullEmail, "WHERE email IS NULL");
// 查找 email 不为 null 且不为 undefined 的用户
const usersWithEmail = filter(usersWithNullEmail, "WHERE email IS NOT NULL");
```
**注意**: `IS NULL``IS NOT NULL` 会同时检查 JavaScript 的 `null``undefined` 值。