Skip to content
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: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"plugins": ["@typescript-eslint", "prettier"],
"parser": "@typescript-eslint/parser",
"extends": ["eslint:recommended", "plugin:prettier/recommended", "prettier"],
"ignorePatterns": ["node_modules", "coverage", "packages/pg-protocol/dist/**/*", "packages/pg-query-stream/dist/**/*"],
"ignorePatterns": ["node_modules", "coverage", "packages/gaussdb-protocol/dist/**/*", "packages/gaussdb-query-stream/dist/**/*"],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "node-postgres",
"description": "node postgres monorepo",
"name": "gaussdb-node",
"description": "node gaussdb monorepo",
"main": "index.js",
"private": true,
"repository": "git@github.com:brianc/node-postgres.git",
"repository": "git@github.com:HuaweiCloudDeveloper/gaussdb-node.git",
"author": "Brian M. Carlson <brian.m.carlson@gmail.com>",
"license": "MIT",
"workspaces": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# pg-cloudflare
# gaussdb-cloudflare

`pg-cloudflare` makes it easier to take an existing package that relies on `tls` and `net`, and make it work in environments where only `connect()` is supported, such as Cloudflare Workers.
`gaussdb-cloudflare` makes it easier to take an existing package that relies on `tls` and `net`, and make it work in environments where only `connect()` is supported, such as Cloudflare Workers.

`pg-cloudflare` wraps `connect()`, the [TCP Socket API](https://github.com/wintercg/proposal-sockets-api) proposed within WinterCG, and implemented in [Cloudflare Workers](https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/), and exposes an interface with methods similar to what the `net` and `tls` modules in Node.js expose. (ex: `net.connect(path[, options][, callback])`). This minimizes the number of changes needed in order to make an existing package work across JavaScript runtimes.
`gaussdb-cloudflare` wraps `connect()`, the [TCP Socket API](https://github.com/wintercg/proposal-sockets-api) proposed within WinterCG, and implemented in [Cloudflare Workers](https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/), and exposes an interface with methods similar to what the `net` and `tls` modules in Node.js expose. (ex: `net.connect(path[, options][, callback])`). This minimizes the number of changes needed in order to make an existing package work across JavaScript runtimes.

## Installation

```
npm i --save-dev pg-cloudflare
npm i --save-dev gaussdb-cloudflare
```

## How to use conditionally, in non-Node.js environments

As implemented in `pg` [here](https://github.com/brianc/node-postgres/commit/07553428e9c0eacf761a5d4541a3300ff7859578#diff-34588ad868ebcb232660aba7ee6a99d1e02f4bc93f73497d2688c3f074e60533R5-R13), a typical use case might look as follows, where in a Node.js environment the `net` module is used, while in a non-Node.js environment, where `net` is unavailable, `pg-cloudflare` is used instead, providing an equivalent interface:
As implemented in `pg` [here](https://github.com/brianc/node-postgres/commit/07553428e9c0eacf761a5d4541a3300ff7859578#diff-34588ad868ebcb232660aba7ee6a99d1e02f4bc93f73497d2688c3f074e60533R5-R13), a typical use case might look as follows, where in a Node.js environment the `net` module is used, while in a non-Node.js environment, where `net` is unavailable, `gaussdb-cloudflare` is used instead, providing an equivalent interface:

```js
module.exports.getStream = function getStream(ssl = false) {
const net = require('net')
if (typeof net.Socket === 'function') {
return net.Socket()
}
const { CloudflareSocket } = require('pg-cloudflare')
const { CloudflareSocket } = require('gaussdb-cloudflare')
return new CloudflareSocket(ssl);
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pg-cloudflare",
"name": "gaussdb-cloudflare",
"version": "1.2.5",
"description": "A socket implementation that can run on Cloudflare Workers using native TCP connections.",
"description": "A socket implementation for GaussDB that can run on Cloudflare Workers using native TCP connections.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
Expand All @@ -24,8 +24,8 @@
},
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-postgres.git",
"directory": "packages/pg-cloudflare"
"url": "git@github.com:HuaweiCloudDeveloper/gaussdb-node.git",
"directory": "packages/gaussdb-cloudflare"
},
"files": [
"/dist/*{js,ts,map}",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"processes":{"4c70412b-c816-446c-afc4-b9c2db64880d":{"parent":null,"children":[]}},"files":{"/home/happy/gaussdb-node/packages/pg-connection-string/index.js":["4c70412b-c816-446c-afc4-b9c2db64880d"]},"externalIds":{}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ESM wrapper for pg-connection-string
// ESM wrapper for gaussdb-connection-string
import connectionString from '../index.js'

// Re-export the parse function
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientConfig } from 'pg'
import { ClientConfig } from 'gaussdb'

export function parse(connectionString: string, options?: Options): ConnectionOptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function parse(str, options = {}) {
return config
}

// convert pg-connection-string ssl config to a ClientConfig.ConnectionOptions
// convert gaussdb-connection-string ssl config to a ClientConfig.ConnectionOptions
function toConnectionOptions(sslConfig) {
const connectionOptions = Object.entries(sslConfig).reduce((c, [key, value]) => {
// we explicitly check for undefined and null instead of `if (value)` because some
Expand All @@ -160,7 +160,7 @@ function toConnectionOptions(sslConfig) {
return connectionOptions
}

// convert pg-connection-string config to a ClientConfig
// convert gaussdb-connection-string config to a ClientConfig
function toClientConfig(config) {
const poolConfig = Object.entries(config).reduce((c, [key, value]) => {
if (key === 'ssl') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pg-connection-string",
"name": "gaussdb-connection-string",
"version": "2.9.0",
"description": "Functions for dealing with a PostgresSQL connection string",
"description": "Functions for dealing with a GaussDB connection string",
"main": "./index.js",
"types": "./index.d.ts",
"exports": {
Expand All @@ -18,21 +18,21 @@
},
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-postgres.git",
"directory": "packages/pg-connection-string"
"url": "git@github.com:HuaweiCloudDeveloper/gaussdb-node.git",
"directory": "packages/gaussdb-connection-string"
},
"keywords": [
"pg",
"connection",
"string",
"parse"
"parse",
"gaussdb"
],
"author": "Blaine Bublitz <blaine@iceddev.com> (http://iceddev.com/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/brianc/node-postgres/issues"
"url": "https://github.com/HuaweiCloudDeveloper/gaussdb-node/issues"
},
"homepage": "https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string",
"homepage": "https://github.com/HuaweiCloudDeveloper/gaussdb-node/tree/master/packages/gaussdb-connection-string",
"devDependencies": {
"@types/pg": "^8.12.0",
"chai": "^4.1.1",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ESM wrapper for pg-cursor
// ESM wrapper for gaussdb-cursor
import Cursor from '../index.js'

// Export as default only to match CJS module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
// note: can remove these deep requires when we bump min version of pg to 9.x
const Result = require('pg/lib/result.js')
const prepare = require('pg/lib/utils.js').prepareValue
const Result = require('gaussdb/lib/result.js')
const prepare = require('gaussdb/lib/utils.js').prepareValue
const EventEmitter = require('events').EventEmitter
const util = require('util')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pg-cursor",
"name": "gaussdb-cursor",
"version": "2.15.0",
"description": "Query cursor extension for node-postgres",
"description": "Query cursor extension for GaussDB",
"main": "index.js",
"exports": {
".": {
Expand All @@ -18,17 +18,17 @@
},
"repository": {
"type": "git",
"url": "git://github.com/brianc/node-postgres.git",
"directory": "packages/pg-cursor"
"url": "git@github.com:HuaweiCloudDeveloper/gaussdb-node.git",
"directory": "packages/gaussdb-cursor"
},
"author": "Brian M. Carlson",
"license": "MIT",
"devDependencies": {
"mocha": "^10.5.2",
"pg": "^8.16.0"
"gaussdb": "^8.16.0"
},
"peerDependencies": {
"pg": "^8"
"gaussdb": "^8"
},
"files": [
"index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert')
const Cursor = require('../')
const pg = require('pg')
const pg = require('gaussdb')

const text = 'SELECT generate_series as num FROM generate_series(0, 50)'
describe('close', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
const assert = require('assert')
const Cursor = require('../')
const pg = require('pg')
const pg = require('gaussdb')

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert')
const Cursor = require('../')
const pg = require('pg')
const pg = require('gaussdb')

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert')
const pg = require('pg')
const pg = require('gaussdb')
const Cursor = require('../')

describe('queries with no data', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
const assert = require('assert')
const Cursor = require('../')
const pg = require('pg')
const pg = require('gaussdb')

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert')
const Cursor = require('../')
const pg = require('pg')
const pg = require('gaussdb')

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
const assert = require('assert')
const Cursor = require('../')
const pg = require('pg')
const pg = require('gaussdb')

describe('query config passed to result', () => {
it('passes rowMode to result', (done) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert')
const Cursor = require('../')
const pg = require('pg')
const pg = require('gaussdb')

// SKIP: 不支持 LISTEN/NOFITY statement
// https://github.com/HuaweiCloudDeveloper/gaussdb-drivers/blob/master-dev/diff-gaussdb-postgres.md#%E4%B8%8D%E6%94%AF%E6%8C%81-listennofity-statement
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const test = require('node:test')
const { describe, it } = test

const paths = [
'pg',
'pg/lib/index.js',
'pg/lib/connection-parameters.js',
'pg-protocol/dist/messages.js',
'gaussdb',
'gaussdb/lib/index.js',
'gaussdb/lib/connection-parameters.js',
'gaussdb-protocol/dist/messages.js',
'pg-native/lib/build-result.js',
]
for (const path of paths) {
Expand All @@ -20,7 +20,7 @@ for (const path of paths) {

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

const pool = new pg.native.Pool()
const result = await pool.query('SELECT 1')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import { CloudflareSocket } from 'pg-cloudflare'
import { CloudflareSocket } from 'gaussdb-cloudflare'

describe('pg-cloudflare', () => {
describe('gaussdb-cloudflare', () => {
it('should export CloudflareSocket constructor', () => {
assert.ok(new CloudflareSocket())
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import { parse, toClientConfig, parseIntoClientConfig } from 'pg-connection-string'
import { parse, toClientConfig, parseIntoClientConfig } from 'gaussdb-connection-string'

describe('pg-connection-string', () => {
describe('gaussdb-connection-string', () => {
it('should export parse function', () => {
assert.strictEqual(typeof parse, 'function')
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import Cursor from 'pg-cursor'
import Cursor from 'gaussdb-cursor'

describe('pg-cursor', () => {
describe('gaussdb-cursor', () => {
it('should export Cursor constructor as default', () => {
assert.ok(new Cursor())
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import Pool from 'pg-pool'
import Pool from 'gaussdb-pool'

describe('pg-pool', () => {
describe('gaussdb-pool', () => {
it('should export Pool constructor', () => {
assert.ok(new Pool())
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import protocol, { NoticeMessage, DatabaseError } from 'pg-protocol/dist/messages.js'
import protocol, { NoticeMessage, DatabaseError } from 'gaussdb-protocol/dist/messages.js'
import { describe, it } from 'node:test'
import { strict as assert } from 'node:assert'

describe('pg-protocol', () => {
describe('gaussdb-protocol', () => {
it('should export database error', () => {
assert.ok(DatabaseError)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import QueryStream from 'pg-query-stream'
import QueryStream from 'gaussdb-query-stream'

describe('pg-query-stream', () => {
describe('gaussdb-query-stream', () => {
it('should export QueryStream constructor as default', () => {
assert.ok(new QueryStream())
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import pg, {
escapeLiteral,
Result,
TypeOverrides,
} from 'pg'
} from 'gaussdb'

describe('pg', () => {
it('should export Client constructor', () => {
Expand Down
26 changes: 26 additions & 0 deletions packages/gaussdb-esm-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "gaussdb-esm-test",
"version": "1.2.0",
"description": "A test module for GaussDB with ESM support",
"main": "index.js",
"type": "module",
"scripts": {
"test": "node --test"
},
"keywords": [
"gaussdb",
"esm",
"test"
],
"devDependencies": {
"gaussdb": "^8.16.0",
"gaussdb-cloudflare": "^1.2.5",
"gaussdb-cursor": "^2.15.0",
"pg-native": "^3.5.0",
"gaussdb-pool": "^3.10.0",
"gaussdb-protocol": "^1.10.0",
"gaussdb-query-stream": "^4.10.0"
},
"author": "Brian M. Carlson <brian.m.carlson@gmail.com>",
"license": "MIT"
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ESM wrapper for pg-pool
// ESM wrapper for gaussdb-pool
import Pool from '../index.js'

// Export as default only to match CJS module
Expand Down
Loading