Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sqlserver support #125

Merged
merged 1 commit into from
May 26, 2023
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
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ driver. Currently supported drivers are:

- [`pg`](https://www.npmjs.com/package/pg) (PostgreSQL)
- [`mysql2`](https://www.npmjs.com/package/mysql2) (MySQL)
- [`tedious`](https://www.npmjs.com/package/tedious) (SQL Server)

## Installation

Expand Down Expand Up @@ -169,6 +170,64 @@ const clientOpts = await connector.getOptions({
});
```

### Using with SQL Server

Here is how to start a new
[`tedious`](https://www.npmjs.com/package/tedious) connection.

```js
const {Connection, Request} = require('tedious');
const {Connector} = require('@google-cloud/cloud-sql-connector');

const connector = new Connector();
const clientOpts = await connector.getTediousOptions({
instanceConnectionName: process.env.SQLSERVER_CONNECTION_NAME,
ipType: 'PUBLIC'
});
const connection = new Connection({
// Please note that the `server` property here is not used and is only defined
// due to a bug in the tedious driver (ref: https://github.com/tediousjs/tedious/issues/1541)
// With that in mind, do not try to change this value since it will have no
// impact in how the connector works, this README will be updated to remove
// this property declaration as soon as the tedious driver bug is fixed
server: '0.0.0.0',
ruyadorno marked this conversation as resolved.
Show resolved Hide resolved
authentication: {
type: 'default',
options: {
userName: process.env.SQLSERVER_USER,
password: process.env.SQLSERVER_PASS,
},
},
options: {
...clientOpts,
// Please note that the `port` property here is not used and is only defined
// due to a bug in the tedious driver (ref: https://github.com/tediousjs/tedious/issues/1541)
// With that in mind, do not try to change this value since it will have no
// impact in how the connector works, this README will be updated to remove
// this property declaration as soon as the tedious driver bug is fixed
port: 9999,
database: process.env.SQLSERVER_DB,
},
})

connection.connect(err => {
if (err) { throw err; }
let result;
const req = new Request('SELECT GETUTCDATE()', (err) => {
if (err) { throw err; }
})
req.on('error', (err) => { throw err; });
req.on('row', (columns) => { result = columns; });
req.on('requestCompleted', () => {
console.table(result);
});
connection.execSql(req);
})

connection.close();
connector.close();
```

## Supported Node.js Versions

Our client libraries follow the
Expand Down
Loading