新增 NOT LIKE、IS NULL 和 IS NOT NULL 操作符,并更新文档示例
This commit is contained in:
40
README.md
40
README.md
@@ -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` 值。
|
||||
|
||||
Reference in New Issue
Block a user