11const assert = require ( 'assert' )
22const Cursor = require ( '../' )
3- const pg = require ( 'gaussdb' )
3+ const gaussdb = require ( 'gaussdb' )
44
55const text = 'SELECT generate_series as num FROM generate_series(0, 5)'
66
77describe ( 'cursor' , function ( ) {
88 beforeEach ( function ( done ) {
9- const client = ( this . client = new pg . Client ( ) )
9+ const client = ( this . client = new gaussdb . Client ( ) )
1010 client . connect ( done )
1111
12- this . pgCursor = function ( text , values ) {
12+ this . gaussdbCursor = function ( text , values ) {
1313 return client . query ( new Cursor ( text , values || [ ] ) )
1414 }
1515 } )
@@ -19,7 +19,7 @@ describe('cursor', function () {
1919 } )
2020
2121 it ( 'fetch 6 when asking for 10' , function ( done ) {
22- const cursor = this . pgCursor ( text )
22+ const cursor = this . gaussdbCursor ( text )
2323 cursor . read ( 10 , function ( err , res ) {
2424 assert . ifError ( err )
2525 assert . strictEqual ( res . length , 6 )
@@ -28,7 +28,7 @@ describe('cursor', function () {
2828 } )
2929
3030 it ( 'end before reading to end' , function ( done ) {
31- const cursor = this . pgCursor ( text )
31+ const cursor = this . gaussdbCursor ( text )
3232 cursor . read ( 3 , function ( err , res ) {
3333 assert . ifError ( err )
3434 assert . strictEqual ( res . length , 3 )
@@ -37,15 +37,15 @@ describe('cursor', function () {
3737 } )
3838
3939 it ( 'callback with error' , function ( done ) {
40- const cursor = this . pgCursor ( 'select asdfasdf' )
40+ const cursor = this . gaussdbCursor ( 'select asdfasdf' )
4141 cursor . read ( 1 , function ( err ) {
4242 assert ( err )
4343 done ( )
4444 } )
4545 } )
4646
4747 it ( 'read a partial chunk of data' , function ( done ) {
48- const cursor = this . pgCursor ( text )
48+ const cursor = this . gaussdbCursor ( text )
4949 cursor . read ( 2 , function ( err , res ) {
5050 assert . ifError ( err )
5151 assert . strictEqual ( res . length , 2 )
@@ -67,7 +67,7 @@ describe('cursor', function () {
6767 } )
6868
6969 it ( 'read return length 0 past the end' , function ( done ) {
70- const cursor = this . pgCursor ( text )
70+ const cursor = this . gaussdbCursor ( text )
7171 cursor . read ( 2 , function ( err ) {
7272 assert ( ! err )
7373 cursor . read ( 100 , function ( err , res ) {
@@ -86,7 +86,7 @@ describe('cursor', function () {
8686 this . timeout ( 10000 )
8787 const text = 'SELECT generate_series as num FROM generate_series(0, 100000)'
8888 const values = [ ]
89- const cursor = this . pgCursor ( text , values )
89+ const cursor = this . gaussdbCursor ( text , values )
9090 let count = 0
9191 const read = function ( ) {
9292 cursor . read ( 100 , function ( err , rows ) {
@@ -108,7 +108,7 @@ describe('cursor', function () {
108108 it ( 'normalizes parameter values' , function ( done ) {
109109 const text = 'SELECT $1::json me'
110110 const values = [ { name : 'brian' } ]
111- const cursor = this . pgCursor ( text , values )
111+ const cursor = this . gaussdbCursor ( text , values )
112112 cursor . read ( 1 , function ( err , rows ) {
113113 if ( err ) return done ( err )
114114 assert . strictEqual ( rows [ 0 ] . me . name , 'brian' )
@@ -121,7 +121,7 @@ describe('cursor', function () {
121121 } )
122122
123123 it ( 'returns result along with rows' , function ( done ) {
124- const cursor = this . pgCursor ( text )
124+ const cursor = this . gaussdbCursor ( text )
125125 cursor . read ( 1 , function ( err , rows , result ) {
126126 assert . ifError ( err )
127127 assert . strictEqual ( rows . length , 1 )
@@ -135,7 +135,7 @@ describe('cursor', function () {
135135 } )
136136
137137 it ( 'emits row events' , function ( done ) {
138- const cursor = this . pgCursor ( text )
138+ const cursor = this . gaussdbCursor ( text )
139139 cursor . read ( 10 )
140140 cursor . on ( 'row' , ( row , result ) => result . addRow ( row ) )
141141 cursor . on ( 'end' , ( result ) => {
@@ -145,7 +145,7 @@ describe('cursor', function () {
145145 } )
146146
147147 it ( 'emits row events when cursor is closed manually' , function ( done ) {
148- const cursor = this . pgCursor ( text )
148+ const cursor = this . gaussdbCursor ( text )
149149 cursor . on ( 'row' , ( row , result ) => result . addRow ( row ) )
150150 cursor . on ( 'end' , ( result ) => {
151151 assert . strictEqual ( result . rows . length , 3 )
@@ -156,19 +156,19 @@ describe('cursor', function () {
156156 } )
157157
158158 it ( 'emits error events' , function ( done ) {
159- const cursor = this . pgCursor ( 'select asdfasdf' )
159+ const cursor = this . gaussdbCursor ( 'select asdfasdf' )
160160 cursor . on ( 'error' , function ( err ) {
161161 assert ( err )
162162 done ( )
163163 } )
164164 } )
165165
166166 it ( 'returns rowCount on insert' , function ( done ) {
167- const pgCursor = this . pgCursor
167+ const gaussdbCursor = this . gaussdbCursor
168168 this . client
169- . query ( 'CREATE TEMPORARY TABLE pg_cursor_test (foo VARCHAR(1), bar VARCHAR(1))' )
169+ . query ( 'CREATE TEMPORARY TABLE gaussdb_cursor_test (foo VARCHAR(1), bar VARCHAR(1))' )
170170 . then ( function ( ) {
171- const cursor = pgCursor ( 'insert into pg_cursor_test values($1, $2)' , [ 'a' , 'b' ] )
171+ const cursor = gaussdbCursor ( 'insert into gaussdb_cursor_test values($1, $2)' , [ 'a' , 'b' ] )
172172 cursor . read ( 1 , function ( err , rows , result ) {
173173 assert . ifError ( err )
174174 assert . strictEqual ( rows . length , 0 )
0 commit comments