Skip to content

Commit fc95c19

Browse files
authored
Merge pull request #6 from happy-game/refactor
Refactor: 重命名 pg/postgres 相关的函数名/变量名
2 parents 163f7c2 + df696b1 commit fc95c19

File tree

95 files changed

+293
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+293
-290
lines changed

packages/gaussdb-cursor/test/close.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const assert = require('assert')
22
const Cursor = require('../')
3-
const pg = require('gaussdb')
3+
const gaussdb = require('gaussdb')
44

55
const text = 'SELECT generate_series as num FROM generate_series(0, 50)'
66
describe('close', function () {
77
beforeEach(function (done) {
8-
const client = (this.client = new pg.Client())
8+
const client = (this.client = new gaussdb.Client())
99
client.connect(done)
1010
})
1111

packages/gaussdb-cursor/test/error-handling.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict'
22
const assert = require('assert')
33
const Cursor = require('../')
4-
const pg = require('gaussdb')
4+
const gaussdb = require('gaussdb')
55

66
const text = 'SELECT generate_series as num FROM generate_series(0, 4)'
77

88
describe('error handling', function () {
99
it('can continue after error', function (done) {
10-
const client = new pg.Client()
10+
const client = new gaussdb.Client()
1111
client.connect()
1212
const cursor = client.query(new Cursor('asdfdffsdf'))
1313
cursor.read(1, function (err) {
@@ -21,7 +21,7 @@ describe('error handling', function () {
2121
})
2222

2323
it('errors queued reads', async () => {
24-
const client = new pg.Client()
24+
const client = new gaussdb.Client()
2525
await client.connect()
2626

2727
const cursor = client.query(new Cursor('asdfdffsdf'))
@@ -55,7 +55,7 @@ describe('error handling', function () {
5555

5656
describe('read callback does not fire sync', () => {
5757
it('does not fire error callback sync', (done) => {
58-
const client = new pg.Client()
58+
const client = new gaussdb.Client()
5959
client.connect()
6060
const cursor = client.query(new Cursor('asdfdffsdf'))
6161
let after = false
@@ -75,7 +75,7 @@ describe('read callback does not fire sync', () => {
7575
})
7676

7777
it('does not fire result sync after finished', (done) => {
78-
const client = new pg.Client()
78+
const client = new gaussdb.Client()
7979
client.connect()
8080
const cursor = client.query(new Cursor('SELECT NOW()'))
8181
let after = false
@@ -100,7 +100,7 @@ describe('read callback does not fire sync', () => {
100100

101101
describe('proper cleanup', function () {
102102
it('can issue multiple cursors on one client', function (done) {
103-
const client = new pg.Client()
103+
const client = new gaussdb.Client()
104104
client.connect()
105105
const cursor1 = client.query(new Cursor(text))
106106
cursor1.read(8, function (err, rows) {

packages/gaussdb-cursor/test/index.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const assert = require('assert')
22
const Cursor = require('../')
3-
const pg = require('gaussdb')
3+
const gaussdb = require('gaussdb')
44

55
const text = 'SELECT generate_series as num FROM generate_series(0, 5)'
66

77
describe('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)

packages/gaussdb-cursor/test/no-data-handling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const assert = require('assert')
2-
const pg = require('gaussdb')
2+
const gaussdb = require('gaussdb')
33
const Cursor = require('../')
44

55
describe('queries with no data', function () {
66
beforeEach(function (done) {
7-
const client = (this.client = new pg.Client())
7+
const client = (this.client = new gaussdb.Client())
88
client.connect(done)
99
})
1010

packages/gaussdb-cursor/test/pool.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22
const assert = require('assert')
33
const Cursor = require('../')
4-
const pg = require('gaussdb')
4+
const gaussdb = require('gaussdb')
55

66
const text = 'SELECT generate_series as num FROM generate_series(0, 50)'
77

@@ -33,7 +33,7 @@ function poolQueryPromise(pool, readRowCount) {
3333

3434
describe('pool', function () {
3535
beforeEach(function () {
36-
this.pool = new pg.Pool({ max: 1 })
36+
this.pool = new gaussdb.Pool({ max: 1 })
3737
})
3838

3939
afterEach(function () {
@@ -85,7 +85,7 @@ describe('pool', function () {
8585
})
8686

8787
it('can close multiple times on a pool', async function () {
88-
const pool = new pg.Pool({ max: 1 })
88+
const pool = new gaussdb.Pool({ max: 1 })
8989
const run = async () => {
9090
const cursor = new Cursor(text)
9191
const client = await pool.connect()

packages/gaussdb-cursor/test/promises.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const assert = require('assert')
22
const Cursor = require('../')
3-
const pg = require('gaussdb')
3+
const gaussdb = require('gaussdb')
44

55
const text = 'SELECT generate_series as num FROM generate_series(0, 5)'
66

77
describe('cursor using promises', 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,21 +19,21 @@ describe('cursor using promises', function () {
1919
})
2020

2121
it('resolve with result', async function () {
22-
const cursor = this.pgCursor(text)
22+
const cursor = this.gaussdbCursor(text)
2323
const res = await cursor.read(6)
2424
assert.strictEqual(res.length, 6)
2525
})
2626

2727
it('reject with error', function (done) {
28-
const cursor = this.pgCursor('select asdfasdf')
28+
const cursor = this.gaussdbCursor('select asdfasdf')
2929
cursor.read(1).catch((err) => {
3030
assert(err)
3131
done()
3232
})
3333
})
3434

3535
it('read multiple times', async function () {
36-
const cursor = this.pgCursor(text)
36+
const cursor = this.gaussdbCursor(text)
3737
let res
3838

3939
res = await cursor.read(2)

packages/gaussdb-cursor/test/query-config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict'
22
const assert = require('assert')
33
const Cursor = require('../')
4-
const pg = require('gaussdb')
4+
const gaussdb = require('gaussdb')
55

66
describe('query config passed to result', () => {
77
it('passes rowMode to result', (done) => {
8-
const client = new pg.Client()
8+
const client = new gaussdb.Client()
99
client.connect()
1010
const text = 'SELECT generate_series as num FROM generate_series(0, 5)'
1111
const cursor = client.query(new Cursor(text, null, { rowMode: 'array' }))
@@ -18,7 +18,7 @@ describe('query config passed to result', () => {
1818
})
1919

2020
it('passes types to result', (done) => {
21-
const client = new pg.Client()
21+
const client = new gaussdb.Client()
2222
client.connect()
2323
const text = 'SELECT generate_series as num FROM generate_series(0, 2)'
2424
const types = {

packages/gaussdb-cursor/test/transactions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const assert = require('assert')
22
const Cursor = require('../')
3-
const pg = require('gaussdb')
3+
const gaussdb = require('gaussdb')
44

55
// SKIP: 不支持 LISTEN/NOFITY statement
66
// https://github.com/HuaweiCloudDeveloper/gaussdb-drivers/blob/master-dev/diff-gaussdb-postgres.md#%E4%B8%8D%E6%94%AF%E6%8C%81-listennofity-statement
77
describe.skip('transactions', () => {
88
it('can execute multiple statements in a transaction', async () => {
9-
const client = new pg.Client()
9+
const client = new gaussdb.Client()
1010
await client.connect()
1111
await client.query('begin')
1212
await client.query('CREATE TEMP TABLE foobar(id SERIAL PRIMARY KEY)')
@@ -20,7 +20,7 @@ describe.skip('transactions', () => {
2020
})
2121

2222
it('can execute multiple statements in a transaction if ending cursor early', async () => {
23-
const client = new pg.Client()
23+
const client = new gaussdb.Client()
2424
await client.connect()
2525
await client.query('begin')
2626
await client.query('CREATE TEMP TABLE foobar(id SERIAL PRIMARY KEY)')
@@ -31,7 +31,7 @@ describe.skip('transactions', () => {
3131
})
3232

3333
it('can execute multiple statements in a transaction if no data', async () => {
34-
const client = new pg.Client()
34+
const client = new gaussdb.Client()
3535
await client.connect()
3636
await client.query('begin')
3737
// create a cursor that has no data response

packages/gaussdb-esm-test/common-js-imports.test.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ for (const path of paths) {
2020

2121
describe('pg-native', () => {
2222
it('should work with commonjs', async () => {
23-
const pg = require('gaussdb')
23+
const gaussdb = require('gaussdb')
2424

25-
const pool = new pg.native.Pool()
25+
const pool = new gaussdb.native.Pool()
2626
const result = await pool.query('SELECT 1')
2727
assert.strictEqual(result.rowCount, 1)
2828
pool.end()

packages/gaussdb-esm-test/gaussdb.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from 'node:assert'
22
import { describe, it } from 'node:test'
3-
import pg, {
3+
import gaussdb, {
44
Client,
55
Pool,
66
Connection,
@@ -13,7 +13,7 @@ import pg, {
1313
TypeOverrides,
1414
} from 'gaussdb'
1515

16-
describe('pg', () => {
16+
describe('gaussdb', () => {
1717
it('should export Client constructor', () => {
1818
assert.ok(new Client())
1919
})
@@ -23,7 +23,7 @@ describe('pg', () => {
2323
})
2424

2525
it('should still provide default export', () => {
26-
assert.ok(new pg.Pool())
26+
assert.ok(new gaussdb.Pool())
2727
})
2828

2929
it('should export Connection constructor', () => {

0 commit comments

Comments
 (0)