File tree Expand file tree Collapse file tree 6 files changed +83
-1
lines changed
Expand file tree Collapse file tree 6 files changed +83
-1
lines changed Original file line number Diff line number Diff line change 11import { executeTestGroups } from './common'
22import { ORM , provisionOrm } from './orm'
3+ import { countTests } from './tests/count'
34import { createTests } from './tests/create'
45import { deleteTests } from './tests/delete'
6+ import { existsTests } from './tests/exists'
57import { getTests } from './tests/get'
68import { updateTests } from './tests/update'
79
@@ -13,6 +15,8 @@ const init = async () => {
1315 updateTests ,
1416 deleteTests ,
1517 createTests ,
18+ countTests ,
19+ existsTests ,
1620 )
1721 await ORM . db . client . end ( )
1822}
Original file line number Diff line number Diff line change 1+ import { DataFilterLogic , Operator } from '@samhuk/data-filter/dist/types'
2+ import { test } from '../../common'
3+
4+ export const basicTest = test ( 'basic' , async ( stores , assert ) => {
5+ const result = await stores . user . count ( {
6+ filter : {
7+ logic : DataFilterLogic . OR ,
8+ nodes : [
9+ { field : 'name' , op : Operator . EQUALS , val : 'User 1' } ,
10+ { field : 'name' , op : Operator . EQUALS , val : 'User 2' } ,
11+ ] ,
12+ } ,
13+ } )
14+
15+ assert ( result , 2 )
16+
17+ const result2 = await stores . user . count ( {
18+ filter : {
19+ logic : DataFilterLogic . AND ,
20+ nodes : [
21+ { field : 'name' , op : Operator . EQUALS , val : 'User 1' } ,
22+ { field : 'name' , op : Operator . EQUALS , val : 'User 2' } ,
23+ ] ,
24+ } ,
25+ } )
26+
27+ assert ( result2 , 0 )
28+ } )
Original file line number Diff line number Diff line change 1+ import { testGroup } from '../../common'
2+ import { basicTest } from './basic'
3+
4+ export const countTests = testGroup (
5+ 'count' ,
6+ basicTest ,
7+ )
Original file line number Diff line number Diff line change 1+ import { DataFilterLogic , Operator } from '@samhuk/data-filter/dist/types'
2+ import { test } from '../../common'
3+
4+ export const basicTest = test ( 'basic' , async ( stores , assert ) => {
5+ const result = await stores . user . exists ( {
6+ filter : {
7+ logic : DataFilterLogic . OR ,
8+ nodes : [
9+ { field : 'name' , op : Operator . EQUALS , val : 'User 1' } ,
10+ { field : 'name' , op : Operator . EQUALS , val : 'User 2' } ,
11+ ] ,
12+ } ,
13+ } )
14+
15+ assert ( result , true )
16+
17+ const result2 = await stores . user . exists ( {
18+ filter : {
19+ logic : DataFilterLogic . AND ,
20+ nodes : [
21+ { field : 'name' , op : Operator . EQUALS , val : 'User 1' } ,
22+ { field : 'name' , op : Operator . EQUALS , val : 'User 2' } ,
23+ ] ,
24+ } ,
25+ } )
26+
27+ assert ( result2 , false )
28+ } )
Original file line number Diff line number Diff line change 1+ import { testGroup } from '../../common'
2+ import { basicTest } from './basic'
3+
4+ export const existsTests = testGroup (
5+ 'exists' ,
6+ basicTest ,
7+ )
Original file line number Diff line number Diff line change @@ -34,5 +34,13 @@ export const count = async (
3434 const sql = sqlParts . filter ( s => s != null ) . join ( '\n' )
3535
3636 const row = await db . queryGetFirstRow ( sql )
37- return ( row as any ) . exact_count
37+ const countRaw = ( row as any ) . exact_count
38+ if ( countRaw == null )
39+ return null
40+ if ( typeof countRaw === 'number' )
41+ return countRaw
42+ if ( typeof countRaw === 'string' )
43+ return parseInt ( countRaw )
44+
45+ return null
3846}
You can’t perform that action at this time.
0 commit comments