Skip to content

Commit fe081a7

Browse files
krishna-ybddhodge
andauthored
docs: Add YugabyteDB smart driver features to Sequelize documentation (#29496)
docs: Add YugabyteDB smart driver features to Sequelize documentation - Added subsection: Using the YugabyteDB Smart Driver - Explains how to use smart driver with sequelize-yugabytedb - Links to smart-drivers documentation - Shows package.json configuration - Simplified load balance properties section - Environment variables examples - Connection parameters examples - Removed detailed property table for brevity * docs: Apply review feedback - improve smart driver documentation * docs: Add environment variables documentation to Node.js smart driver - Add comprehensive environment variables table to yugabyte-node-driver.md - Include all standard PG env vars (PGHOST, PGPORT, PGDATABASE, PGUSER, PGPASSWORD) - Include YugabyteDB-specific env vars (PGLOADBALANCE, PGTOPOLOGYKEYS, PGYBSERVERSREFRESHINTERVAL) - Add mapping table showing environment variable to connection parameter correspondence - Add code examples showing how to set env vars in Node.js and shell - Update sequelize.md to clarify it shows 'some' not 'all' environment variables - Add cross-reference from Sequelize docs to complete env vars documentation - Remove redundant detailed env vars table from yugabyte-node-driver.md - Keep only the mapping table showing env var to parameter correspondence - Add all standard PostgreSQL env vars (PGHOST, PGPORT, PGDATABASE, PGUSER, PGPASSWORD) - Include YugabyteDB-specific env vars (PGLOADBALANCE, PGTOPOLOGYKEYS, PGYBSERVERSREFRESHINTERVAL) - Remove note from yugabyte-node-driver.md (cleaner without it) - Update sequelize.md to link to complete env vars list - Clarify that load balancing env vars are only for @yugabytedb/pg package Co-authored-by: Dwight Hodge <ghodge@yugabyte.com>
1 parent c40b09b commit fe081a7

File tree

2 files changed

+135
-2
lines changed

2 files changed

+135
-2
lines changed

docs/content/stable/develop/drivers-orms/nodejs/sequelize.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,27 @@ The following code creates an Employees model to store and retrieve employee inf
8888
- The actual table is created by calling the `Employee.sync()` API in the `createTableAndInsert()` function. This also inserts the data for three employees into the table using the `Employee.create()` API.
8989
- Finally, you can retrieve the information of all employees using `Employee.findAll()`.
9090
91+
#### Using the YugabyteDB node-postgres smart driver
92+
93+
You can also use the [YugabyteDB node-postgres smart driver](/stable/develop/drivers-orms/nodejs/yugabyte-node-driver/) (`@yugabytedb/pg`), which includes connection load balancing features, to distribute connections uniformly across the nodes in the entire cluster or in specific placements (zones or regions).
94+
95+
For more information on the smart driver features, refer to [Using YugabyteDB smart drivers](../../smart-drivers/#using-yugabytedb-smart-drivers).
96+
97+
To use the YugabyteDB node-postgres smart driver instead of the vanilla pg driver, add the following dependencies to your application's `package.json` file, to override the default PostgreSQL driver with the YugabyteDB smart driver:
98+
99+
```json
100+
{
101+
"dependencies": {
102+
"sequelize-yugabytedb": "^1.0.5",
103+
"pg": "npm:@yugabytedb/pg@8.7.3-yb-10"
104+
}
105+
}
106+
```
107+
108+
To configure load balancing properties, use either environment variables or connection parameters. See [Specify load balance properties](#specify-load-balance-properties) for examples and more details.
109+
110+
For a complete working example, refer to the [Sequelize ORM example application](https://github.com/YugabyteDB-Samples/orm-examples/tree/master/node/sequelize).
111+
91112
Add the code in the `example.js` file.
92113
93114
```js
@@ -189,9 +210,74 @@ Employees Details:
189210
]
190211
```
191212
192-
## Specifying SSL configuration
213+
#### Specify load balance properties
214+
215+
You can specify load balance properties using environment variables or connection parameters.
216+
217+
For information on all load balance modes, see [Node type-aware load balancing](../../smart-drivers/#node-type-aware-load-balancing).
218+
219+
##### Environment variables
220+
221+
The following table summarizes some environment variables available for configuring the YugabyteDB node-postgres smart driver:
222+
223+
| Environment variable | Description | Default |
224+
| :--- | :--- | :--- |
225+
| PGLOADBALANCE | Enables cluster-aware or node type-aware load balancing.<br>Valid values are `any`, `prefer-primary`, `prefer-rr`, `only-primary`, `only-rr`, `true` (alias for `any`), and `false` (disabled). | `false` |
226+
| PGTOPOLOGYKEYS | Enables topology-aware load balancing by specifying comma-separated geo-locations. Provide locations in the form `cloud.region.zone` (for example, `aws.us-east-1.us-east-1a`). Specify multiple zones by separating values using commas. You can use a wildcard to specify all zones in a region (`cloud.region.*`). Indicate fallback priority using `cloud.region.zone:n`, where `n` is priority number. | Empty (disabled) |
227+
| PGYBSERVERSREFRESHINTERVAL | The interval (in seconds) to refresh the servers list | `300` (5 minutes) |
228+
229+
These environment variables are only effective when using the YugabyteDB smart driver (`@yugabytedb/pg`). For a complete list of all available environment variables, refer to [Environment variables](../yugabyte-node-driver/#environment-variables).
230+
231+
```js
232+
const { Sequelize, DataTypes } = require('sequelize-yugabytedb')
233+
234+
// Enable load balancing across nodes in the cluster
235+
process.env.PGLOADBALANCE = 'any'; // Valid values: any, prefer-primary, prefer-rr, only-primary, only-rr
236+
// Specify the region(s)/zone(s) to target nodes from (Optional)
237+
process.env.PGTOPOLOGYKEYS = 'aws.us-east-2.us-east-2a';
238+
// Set the minimum time interval for refreshing the cluster topology information (Optional)
239+
process.env.PGYBSERVERSREFRESHINTERVAL = '5';
240+
241+
const sequelize = new Sequelize('yugabyte', 'yugabyte', 'yugabyte', {
242+
host: 'localhost',
243+
port: '5433',
244+
dialect: 'postgres'
245+
})
246+
```
247+
248+
You can also set these in your shell or in a `.env` file:
249+
250+
```sh
251+
export PGLOADBALANCE=any
252+
export PGTOPOLOGYKEYS=aws.us-east-2.us-east-2a
253+
export PGYBSERVERSREFRESHINTERVAL=5
254+
```
255+
256+
##### Connection parameters
257+
258+
Alternatively, you can specify load balancing properties directly in the connection string:
259+
260+
```js
261+
const connectionString =
262+
'postgres://yugabyte:yugabyte@localhost:5433/yugabyte' +
263+
'?loadBalance=any' +
264+
'&topologyKeys=aws.us-east-2.us-east-2a' +
265+
'&ybServersRefreshInterval=5';
266+
267+
const sequelize = new Sequelize(connectionString, {
268+
dialect: 'postgres',
269+
pool: {
270+
max: 10,
271+
min: 2,
272+
idle: 10000,
273+
acquire: 30000
274+
}
275+
});
276+
```
277+
278+
## Specify SSL configuration
193279
194-
This configuration can be used while connecting to a YugabyteDB Aeon cluster or a local YB cluster with SSL enabled.
280+
This configuration can be used while connecting to a YugabyteDB Aeon cluster or a local YugabyteDB cluster with SSL enabled.
195281
196282
1. Install the `fs` package to read the SSL certificate:
197283
@@ -224,3 +310,4 @@ This configuration can be used while connecting to a YugabyteDB Aeon cluster or
224310
## Learn more
225311
226312
- [YugabyteDB smart drivers for YSQL](../../smart-drivers/)
313+
- [Sequelize ORM example application](https://github.com/YugabyteDB-Samples/orm-examples/tree/master/node/sequelize)

docs/content/stable/develop/drivers-orms/nodejs/yugabyte-node-driver.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,52 @@ postgresql://yugabyte:yugabyte@128.0.0.1:5433/yugabyte?loadBalance=true? \
9191

9292
After the driver establishes the initial connection, it fetches the list of available servers from the cluster, and load-balances subsequent connection requests across these servers.
9393

94+
#### Environment variables
95+
96+
You can also specify load balance properties using environment variables. The following table shows the mapping between environment variables and their corresponding connection parameters.
97+
98+
| Environment variable | Connection parameter |
99+
| :--- | :--- |
100+
| PGHOST | host |
101+
| PGPORT | port |
102+
| PGDATABASE | database |
103+
| PGUSER | user |
104+
| PGPASSWORD | password |
105+
| PGLOADBALANCE | loadBalance |
106+
| PGTOPOLOGYKEYS | topologyKeys |
107+
| PGYBSERVERSREFRESHINTERVAL | ybServersRefreshInterval |
108+
109+
The following is an example of how you can set up the connection using environment variables.
110+
111+
```js
112+
const pg = require('@yugabytedb/pg');
113+
114+
// Enable load balancing across nodes in the cluster
115+
process.env.PGLOADBALANCE = 'any'; // Valid values: any, prefer-primary, prefer-rr, only-primary, only-rr
116+
// Specify the region(s)/zone(s) to target nodes from (Optional)
117+
process.env.PGTOPOLOGYKEYS = 'aws.us-east-2.us-east-2a';
118+
// Set the minimum time interval for refreshing the cluster topology information (Optional)
119+
process.env.PGYBSERVERSREFRESHINTERVAL = '5';
120+
121+
const client = new pg.Client({
122+
host: 'localhost',
123+
port: 5433,
124+
database: 'yugabyte',
125+
user: 'yugabyte',
126+
password: 'yugabyte'
127+
});
128+
```
129+
130+
You can also set these variables in your shell or in a `.env` file:
131+
132+
```sh
133+
export PGLOADBALANCE=any
134+
export PGTOPOLOGYKEYS=aws.us-east-2.us-east-2a
135+
export PGYBSERVERSREFRESHINTERVAL=5
136+
```
137+
138+
For information on all load balance modes, see [Node type-aware load balancing](../../smart-drivers/#node-type-aware-load-balancing).
139+
94140
#### Use SSL
95141

96142
The following table describes the connection parameters required to connect using TLS/SSL.

0 commit comments

Comments
 (0)