Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add string type to gt/lt/gte/lte type definitions #2704

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/content/7.v1/1.getting-started/4.fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const articles = await this.$content('articles').where({ title: { $eq: 'Home' }

// $gt
const articles = await this.$content('articles').where({ age: { $gt: 18 } }).fetch()
// $lte
const articles = await this.$content('articles').where({ createdDateTime: { $lte: new Date().toISOString() } }).fetch()
// $in
const articles = await this.$content('articles').where({ name: { $in: ['odin', 'thor'] } }).fetch()
```
Expand Down
8 changes: 4 additions & 4 deletions src/types/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export interface ContentQueryBuilderWhere extends Partial<Record<keyof ParsedCon
})
```
*/
$gt?: number
$gt?: number | string
/**
* Check if item is greater than or equal to condition
*
Expand All @@ -137,7 +137,7 @@ export interface ContentQueryBuilderWhere extends Partial<Record<keyof ParsedCon
})
```
*/
$gte?: number
$gte?: number | string
/**
* Check if item is less than condition
*
Expand All @@ -150,7 +150,7 @@ export interface ContentQueryBuilderWhere extends Partial<Record<keyof ParsedCon
})
```
*/
$lt?: number
$lt?: number | string
/**
* Check if item is less than or equal to condition
*
Expand All @@ -163,7 +163,7 @@ export interface ContentQueryBuilderWhere extends Partial<Record<keyof ParsedCon
})
```
*/
$lte?: number
$lte?: number | string
/**
* Provides regular expression capabilities for pattern matching strings.
*
Expand Down
10 changes: 9 additions & 1 deletion test/features/query/match.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,33 @@ describe('Match', () => {
})
})

describe('Numerical operators', () => {
describe('Less-than/Greater-than operators', () => {
test('$gt', () => {
expect(match(item, { id: { $gt: 0 } })).toBe(true)
expect(match(item, { id: { $gt: 1 } })).toBe(false)
expect(match(item, { category: { $gt: 'c' } })).toBe(true)
expect(match(item, { category: { $gt: 'c1' } })).toBe(false)
})

test('$gte', () => {
expect(match(item, { id: { $gte: 1 } })).toBe(true)
expect(match(item, { id: { $gte: 2 } })).toBe(false)
expect(match(item, { category: { $gte: 'c1' } })).toBe(true)
expect(match(item, { category: { $gte: 'c11' } })).toBe(false)
})

test('$lt', () => {
expect(match(item, { id: { $lt: 2 } })).toBe(true)
expect(match(item, { id: { $lt: 1 } })).toBe(false)
expect(match(item, { category: { $lt: 'c11' } })).toBe(true)
expect(match(item, { category: { $lt: 'c1' } })).toBe(false)
})

test('$lte', () => {
expect(match(item, { id: { $lte: 1 } })).toBe(true)
expect(match(item, { id: { $lte: 0 } })).toBe(false)
expect(match(item, { category: { $lte: 'c1' } })).toBe(true)
expect(match(item, { category: { $lte: 'c' } })).toBe(false)
})
})

Expand Down
Loading