Skip to content

Commit 2b18c97

Browse files
committed
fix(skip,limit): use int object for parameter
Uses a neo4j integer object to pass the skip and limit parameter to neo4j. It was complaining about the old version because it interpreted the number as a floating value. fix #159
1 parent 924895f commit 2b18c97

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

src/clauses/limit.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import neo4jDriver from 'neo4j-driver';
12
import { expect } from 'chai';
23
import { Limit } from './limit';
34

@@ -6,7 +7,7 @@ describe('Limit', () => {
67
it('should add a produce a limit clause', () => {
78
const query = new Limit(10);
89
expect(query.build()).to.equal('LIMIT $limitCount');
9-
expect(query.getParams()).to.eql({ limitCount: 10 });
10+
expect(query.getParams()).to.eql({ limitCount: neo4jDriver.int(10) });
1011
});
1112
});
1213
});

src/clauses/limit.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import neo4jDriver from 'neo4j-driver';
12
import { Clause } from '../clause';
23
import { Parameter } from '../parameter-bag';
34

@@ -6,7 +7,7 @@ export class Limit extends Clause {
67

78
constructor(public amount: number) {
89
super();
9-
this.amountParam = this.addParam(amount, 'limitCount');
10+
this.amountParam = this.addParam(neo4jDriver.int(amount), 'limitCount');
1011
}
1112

1213
build() {

src/clauses/skip.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { expect } from 'chai';
2+
import neo4jDriver from 'neo4j-driver';
23
import { Skip } from './skip';
34

45
describe('Skip', () => {
56
describe('#build', () => {
67
it('should add a produce a skip clause', () => {
78
const query = new Skip(10);
89
expect(query.build()).to.equal('SKIP $skipCount');
9-
expect(query.getParams()).to.eql({ skipCount: 10 });
10+
expect(query.getParams()).to.eql({ skipCount: neo4jDriver.int(10) });
1011
});
1112
});
1213
});

src/clauses/skip.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import neo4jDriver from 'neo4j-driver';
12
import { Clause } from '../clause';
23
import { Parameter } from '../parameter-bag';
34

@@ -6,7 +7,7 @@ export class Skip extends Clause {
67

78
constructor(public amount: number) {
89
super();
9-
this.amountParam = this.addParam(amount, 'skipCount');
10+
this.amountParam = this.addParam(neo4jDriver.int(amount), 'skipCount');
1011
}
1112

1213
build() {

tests/scenarios.test.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { neo4jCredentials, neo4jUrl, waitForNeo } from './utils';
2-
import { Connection } from '../src';
3-
import { expect } from '../test-setup';
41
import { Dictionary, isNil } from 'lodash';
2+
import { Connection } from '../src';
53
import { node, relation } from '../src/clauses';
4+
import { expect } from '../test-setup';
5+
import { neo4jCredentials, neo4jUrl, waitForNeo } from './utils';
66

77
function expectResults(
88
results: any[],
@@ -108,6 +108,16 @@ describe('scenarios', () => {
108108
});
109109
});
110110

111+
it('should fetch a single node using limit', async () => {
112+
const results = await db.matchNode('person', 'Person')
113+
.return('person')
114+
.skip(1)
115+
.limit(1)
116+
.run();
117+
118+
expectResults(results, 1, ['person']);
119+
});
120+
111121
it('should fetch a property of a set of nodes', async () => {
112122
const results = await db.matchNode('person', 'Person')
113123
.return({ 'person.age': 'yearsOld' })

0 commit comments

Comments
 (0)