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
10 changes: 5 additions & 5 deletions docs/pages/apis/client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Config = {
example to create a client with specific connection information:

```js
import { Client } from 'gaussdb'
import { Client } from 'gaussdb-node'

const client = new Client({
user: 'database-user',
Expand All @@ -48,7 +48,7 @@ const client = new Client({
## client.connect

```js
import { Client } from 'gaussdb'
import { Client } from 'gaussdb-node'
const client = new Client()

await client.connect()
Expand Down Expand Up @@ -90,7 +90,7 @@ client.query(text: string, values?: any[]) => Promise<Result>
**Plain text query**

```js
import { Client } from 'gaussdb'
import { Client } from 'gaussdb-node'
const client = new Client()

await client.connect()
Expand All @@ -104,7 +104,7 @@ await client.end()
**Parameterized query**

```js
import { Client } from 'gaussdb'
import { Client } from 'gaussdb-node'
const client = new Client()

await client.connect()
Expand Down Expand Up @@ -142,7 +142,7 @@ await client.end()
If you pass an object to `client.query` and the object has a `.submit` function on it, the client will pass it's GaussDB server connection to the object and delegate query dispatching to the supplied object. This is an advanced feature mostly intended for library authors. It is incidentally also currently how the callback and promise based queries above are handled internally, but this is subject to change. It is also how [gaussdb-cursor](https://github.com/HuaweiCloudDeveloper/gaussdb-node/tree/master/packages/gaussdb-cursor) and [gaussdb-query-stream](https://github.com/HuaweiCloudDeveloper/gaussdb-node/tree/master/packages/gaussdb-query-stream) work.

```js
import { Query } from 'gaussdb'
import { Query } from 'gaussdb-node'
const query = new Query('select $1::text as name', ['brianc'])

const result = client.query(query)
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/apis/cursor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install gaussdb gaussdb-cursor
Instantiates a new Cursor. A cursor is an instance of `Submittable` and should be passed directly to the `client.query` method.

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'
import Cursor from 'gaussdb-cursor'

const pool = new Pool()
Expand Down Expand Up @@ -55,7 +55,7 @@ If the cursor has read to the end of the result sets all subsequent calls to cur
Here is an example of reading to the end of a cursor:

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'
import Cursor from 'gaussdb-cursor'

const pool = new Pool()
Expand Down
12 changes: 6 additions & 6 deletions docs/pages/apis/pool.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Config = {
example to create a new pool with configuration:

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'

const pool = new Pool({
host: 'localhost',
Expand All @@ -76,7 +76,7 @@ pool.query(text: string, values?: any[]) => Promise<gaussdb.Result>
```

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'

const pool = new Pool()

Expand Down Expand Up @@ -108,7 +108,7 @@ Acquires a client from the pool.
- If the pool is 'full' and all clients are currently checked out will wait in a FIFO queue until a client becomes available by it being released back to the pool.

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'

const pool = new Pool()

Expand All @@ -126,7 +126,7 @@ Client instances returned from `pool.connect` will have a `release` method which
The `release` method on an acquired client returns it back to the pool. If you pass a truthy value in the `destroy` parameter, instead of releasing the client to the pool, the pool will be instructed to disconnect and destroy this client, leaving a space within itself for a new client.

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'

const pool = new Pool()

Expand All @@ -138,7 +138,7 @@ client.release()
```

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'

const pool = new Pool()
assert(pool.totalCount === 0)
Expand Down Expand Up @@ -171,7 +171,7 @@ Calling `pool.end` will drain the pool of all active clients, disconnect them, a

```js
// again both promises and callbacks are supported:
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'

const pool = new Pool()

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/apis/result.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Every result will have a rows array. If no rows are returned the array will be e
Every result will have a fields array. This array contains the `name` and `dataTypeID` of each field in the result. These fields are ordered in the same order as the columns if you are using `arrayMode` for the query:

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { Pool } = gaussdb

const pool = new Pool()
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/apis/utilities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Alert } from '/components/alert.tsx'
Escapes a string as a [SQL identifier](https://www.gaussdb.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS).

```js
import { escapeIdentifier } from 'gaussdb';
import { escapeIdentifier } from 'gaussdb-node';
const escapedIdentifier = escapeIdentifier('FooIdentifier')
console.log(escapedIdentifier) // '"FooIdentifier"'
```
Expand All @@ -27,7 +27,7 @@ console.log(escapedIdentifier) // '"FooIdentifier"'
Escapes a string as a [SQL literal](https://www.gaussdb.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS).

```js
import { escapeLiteral } from 'gaussdb';
import { escapeLiteral } from 'gaussdb-node';
const escapedLiteral = escapeLiteral("hello 'world'")
console.log(escapedLiteral) // "'hello ''world'''"
```
2 changes: 1 addition & 1 deletion docs/pages/features/callbacks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ title: Callbacks


```js
const { Pool, Client } = require('gaussdb')
const { Pool, Client } = require('gaussdb-node')

// pool
const pool = new Pool()
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/features/connecting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Both individual clients & pools will use these environment variables. Here's a t
Both individual clients & pools will use these environment variables. Here's a tiny program connecting node.js to the GaussDB server:

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { Pool, Client } = gaussdb

// pools will use environment variables
Expand Down Expand Up @@ -57,7 +57,7 @@ GAUSSDB_DATABASE=process.env.USER (fallback to GAUSSDATABASE)
gaussdb-node also supports configuring a pool or client programmatically with connection information. Here's our same script from above modified to use programmatic (hard-coded in this case) values. This can be useful if your application already has a way to manage config values or you don't want to use environment variables.

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { Pool, Client } = gaussdb

const pool = new Pool({
Expand Down Expand Up @@ -88,7 +88,7 @@ await client.end()
Many cloud providers include alternative methods for connecting to database instances using short-lived authentication tokens. gaussdb-node supports dynamic passwords via a callback function, either synchronous or asynchronous. The callback function must resolve to a string.

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { Pool } = gaussdb
import { RDS } from 'aws-sdk'

Expand Down Expand Up @@ -121,7 +121,7 @@ const pool = new Pool({
Connections to unix sockets can also be made. This can be useful on distros like Ubuntu, where authentication is managed via the socket connection instead of a password.

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { Client } = gaussdb
client = new Client({
user: 'username',
Expand All @@ -136,7 +136,7 @@ client = new Client({
You can initialize both a pool and a client with a connection string URI as well. This is common in environments like Heroku where the database connection string is supplied to your application dyno through an environment variable. Connection string parsing brought to you by [gaussdb-connection-string](https://github.com/HuaweiCloudDeveloper/gaussdb-node/tree/master/packages/gaussdb-connection-string).

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { Pool, Client } = gaussdb
const connectionString = 'gaussdb://dbuser:secretpassword@database.server.com:3211/mydb'

Expand Down
8 changes: 4 additions & 4 deletions docs/pages/features/esm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: ESM

## ESM Support

As of v8.15.x gaussdb-node supporters the __ECMAScript Module__ (ESM) format. This means you can use `import` statements instead of `require` or `import gaussdb from 'gaussdb'`.
As of v8.15.x gaussdb-node supporters the __ECMAScript Module__ (ESM) format. This means you can use `import` statements instead of `require` or `import gaussdb from 'gaussdb-node'`.

CommonJS modules are still supported. The ESM format is an opt-in feature and will not affect existing codebases that use CommonJS.

Expand All @@ -13,7 +13,7 @@ The docs have been changed to show ESM usage, but in a CommonJS context you can
If you're using CommonJS, you can use the following code to import the `gaussdb` module:

```js
const gaussdb = require('gaussdb')
const gaussdb = require('gaussdb-node')
const { Client } = gaussdb
// etc...
```
Expand All @@ -23,15 +23,15 @@ If you're using CommonJS, you can use the following code to import the `gaussdb`
If you're using ESM, you can use the following code to import the `gaussdb` module:

```js
import { Client } from 'gaussdb'
import { Client } from 'gaussdb-node'
// etc...
```


Previously if you were using ESM you would have to use the following code:

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { Client } = gaussdb
// etc...
```
4 changes: 2 additions & 2 deletions docs/pages/features/native.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ $ npm install gaussdb pg-native
Once `pg-native` is installed instead of requiring a `Client` or `Pool` constructor from `gaussdb` you do the following:

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { native } = gaussdb
const { Client, Pool } = native
```

When you access the `.native` property on `'gaussdb'` it will automatically require the `pg-native` package and wrap it in the same API.
When you access the `.native` property on `'gaussdb-node'` it will automatically require the `pg-native` package and wrap it in the same API.

<div class='alert alert-warning'>
Care has been taken to normalize between the two, but there might still be edge cases where things behave subtly differently due to the nature of using libpq over handling the binary protocol directly in JavaScript, so it's recommended you chose to either use the JavaScript driver or the native bindings both in development and production. For what its worth: I use the pure JavaScript driver because the JavaScript driver is more portable (doesn't need a compiler), and the pure JavaScript driver is <em>plenty</em> fast.
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/features/pooling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The client pool allows you to have a reusable pool of clients you can check out,
### Checkout, use, and return

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { Pool } = gaussdb

const pool = new Pool()
Expand Down Expand Up @@ -61,7 +61,7 @@ client.release()
If you don't need a transaction or you just need to run a single query, the pool has a convenience method to run a query on any available client in the pool. This is the preferred way to query with gaussdb-node if you can as it removes the risk of leaking a client.

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { Pool } = gaussdb

const pool = new Pool()
Expand All @@ -75,7 +75,7 @@ console.log('user:', res.rows[0])
To shut down a pool call `pool.end()` on the pool. This will wait for all checked-out clients to be returned and then shut down all the clients and the pool timers.

```js
import gaussdb from 'gaussdb'
import gaussdb from 'gaussdb-node'
const { Pool } = gaussdb
const pool = new Pool()

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/features/ssl.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const config = {
},
}

import { Client, Pool } from 'gaussdb'
import { Client, Pool } from 'gaussdb-node'

const client = new Client(config)
await client.connect()
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/features/transactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To execute a transaction with gaussdb-node you simply execute `BEGIN / COMMIT /
## Examples

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'
const pool = new Pool()

const client = await pool.connect()
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/guides/async-express.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ That's the same structure I used in the [project structure](/guides/project-stru
My `db/index.js` file usually starts out like this:

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'

const pool = new Pool()

Expand Down
6 changes: 3 additions & 3 deletions docs/pages/guides/project-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The location doesn't really matter - I've found it usually ends up being somewha
Typically I'll start out my `db/index.js` file like so:

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'

const pool = new Pool()

Expand All @@ -54,7 +54,7 @@ app.get('/:id', async (req, res, next) => {
Imagine we have lots of routes scattered throughout many files under our `routes/` directory. We now want to go back and log every single query that's executed, how long it took, and the number of rows it returned. If we had required gaussdb-node directly in every route file we'd have to go edit every single route - that would take forever & be really error prone! But thankfully we put our data access into `db/index.js`. Let's go add some logging:

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'

const pool = new Pool()

Expand All @@ -74,7 +74,7 @@ _note: I didn't log the query parameters. Depending on your application you migh
Now what if we need to check out a client from the pool to run several queries in a row in a transaction? We can add another method to our `db/index.js` file when we need to do this:

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'

const pool = new Pool()

Expand Down
6 changes: 3 additions & 3 deletions docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gaussdb-node strives to be compatible with all recent LTS versions of node & the
The simplest possible way to connect, query, and disconnect is with async/await:

```js
import { Client } from 'gaussdb'
import { Client } from 'gaussdb-node'
const client = new Client()
await client.connect()

Expand All @@ -36,7 +36,7 @@ await client.end()
For the sake of simplicity, these docs will assume that the methods are successful. In real life use, make sure to properly handle errors thrown in the methods. A `try/catch` block is a great way to do so:

```ts
import { Client } from 'gaussdb'
import { Client } from 'gaussdb-node'
const client = new Client()
await client.connect()

Expand All @@ -55,7 +55,7 @@ try {
In most applications you'll wannt to use a [connection pool](/features/pooling) to manage your connections. This is a more advanced topic, but here's a simple example of how to use it:

```js
import { Pool } from 'gaussdb'
import { Pool } from 'gaussdb-node'
const pool = new Pool()
const res = await pool.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].message) // Hello world!
Expand Down
2 changes: 1 addition & 1 deletion packages/gaussdb-cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gaussdb-cloudflare",
"version": "0.1.0",
"version": "0.2.0",
"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",
Expand Down
4 changes: 2 additions & 2 deletions packages/gaussdb-connection-string/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The resulting config contains a subset of the following properties:
The gaussdb-connection-string `ConnectionOptions` interface is not compatible with the `ClientConfig` interface that [gaussdb.Client](https://node-gaussdb.com/apis/client) expects. To remedy this, use the `parseIntoClientConfig` function instead of `parse`:

```ts
import { ClientConfig } from 'gaussdb';
import { ClientConfig } from 'gaussdb-node';
import { parseIntoClientConfig } from 'gaussdb-connection-string';

const config: ClientConfig = parseIntoClientConfig('gaussdb://someuser:somepassword@somehost:381/somedatabase')
Expand All @@ -48,7 +48,7 @@ const config: ClientConfig = parseIntoClientConfig('gaussdb://someuser:somepassw
You can also use `toClientConfig` to convert an existing `ConnectionOptions` interface into a `ClientConfig` interface:

```ts
import { ClientConfig } from 'gaussdb';
import { ClientConfig } from 'gaussdb-node';
import { parse, toClientConfig } from 'gaussdb-connection-string';

const config = parse('gaussdb://someuser:somepassword@somehost:381/somedatabase')
Expand Down
2 changes: 1 addition & 1 deletion packages/gaussdb-connection-string/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientConfig } from 'gaussdb'
import { ClientConfig } from 'gaussdb-node'

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

Expand Down
2 changes: 1 addition & 1 deletion packages/gaussdb-connection-string/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gaussdb-connection-string",
"version": "0.1.0",
"version": "0.2.0",
"description": "Functions for dealing with a GaussDB connection string",
"main": "./index.js",
"types": "./index.d.ts",
Expand Down
Loading