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

Add support for stream parameter for PostgreSQL and MySQL #303

Open
edosrecki opened this issue Sep 6, 2023 · 1 comment
Open

Add support for stream parameter for PostgreSQL and MySQL #303

edosrecki opened this issue Sep 6, 2023 · 1 comment

Comments

@edosrecki
Copy link

edosrecki commented Sep 6, 2023

Issue

Both mysql2 and pg clients support an optional stream config parameter (see references), which is either an existing stream, or a factory which creates a stream lazily. However, @databases library does not accept stream parameter, and does not pass it to underlying drivers.

Justification

stream parameter allows a more flexible control of the socket connection creation. It supports a variety of setups such as secure socket connections that are used by cloud providers such as Google Cloud Platform. In references you can see how Google Cloud SQL Connector creates a stream factory which is used to connect to Google Cloud SQL instances (with password, or IAM authentication), secured by an ephemeral certificate.

It would be beneficial for GCP users, who want to use @databases, if the library accepted the stream parameter and passed it down to drivers.

References

mysql2: https://github.com/sidorares/node-mysql2/blob/a0e0e2fe2c115dc0246c52783fd29945ae01bf77/lib/connection.js#L67C2-L67C2
pg: https://github.com/brianc/node-postgres/blob/a84ebb3fe85edafb1b358965bdb5e3de58b12c5d/packages/pg/lib/connection.js#L19
cloud-sql-nodejs-connector: https://github.com/GoogleCloudPlatform/cloud-sql-nodejs-connector/blob/00e726f4f60f9c83fb816211d447013f6c0163e0/src/connector.ts#L185

@ruyadorno
Copy link

ruyadorno commented Sep 11, 2023

Thanks for opening this issue @edosrecki! I don't have the bandwith right now to contribute to atdatabases but if anyone is willing to take a try at adding the support to the stream parameter, these are the references to the places I believe have to be tweaked:

  • PostgreSQL:
    export interface PgOptions {
    user: string | undefined;
    password: string | undefined;
    database: string | undefined;
    connectionTimeoutMillis: number;
    statement_timeout?: number;
    query_timeout?: number;
    idle_in_transaction_session_timeout?: number;
    application_name?: string;
    keepAlive: boolean;
    keepAliveInitialDelayMillis: number;
    types: TypeOverrides;
    hosts: {host: string; port?: number | undefined}[];
    ssl: SSLConfig;
    }
  • MySQL:
    interface MySqlConnectionOptions {
    uri: string;
    multipleStatements?: boolean;
    timezone: 'Z' | 'local';
    typeCast?: (
    field: {
    type: string;
    length: number;
    db: string;
    table: string;
    name: string;
    string(): string;
    buffer(): Buffer;
    geometry(): unknown;
    },
    next: () => any,
    ) => any;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants