Skip to content

Commit

Permalink
using 'in' as type guard
Browse files Browse the repository at this point in the history
  • Loading branch information
borsemayur2 committed May 1, 2021
1 parent 0f076ed commit 84ad078
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/connectors/postgres-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@ import type { SupportedSQLDatabaseDialect } from "../translators/sql-translator.
import type { QueryDescription } from "../query-builder.ts";
import type { Values } from "../data-types.ts";

interface PostgresOptionsBase extends ConnectorOptions {
interface PostgresOptionsWithConfig extends ConnectorOptions {
database: string;
host: string;
username: string;
password: string;
port?: number;
// unused types
uri?: never;
}

interface PostgresOptionsWithURI extends ConnectorOptions {
uri: string;
// unused types
database?: never;
host?: never;
username?: never;
password?: never;
port?: never;
}

export type PostgresOptions = PostgresOptionsWithURI | PostgresOptionsBase;
export type PostgresOptions =
| PostgresOptionsWithConfig
| PostgresOptionsWithURI;

export class PostgresConnector implements Connector {
_dialect: SupportedSQLDatabaseDialect = "postgres";
Expand All @@ -38,7 +32,7 @@ export class PostgresConnector implements Connector {
/** Create a PostgreSQL connection. */
constructor(options: PostgresOptions) {
this._options = options;
if (options.hasOwnProperty("uri")) {
if ("uri" in options) {
this._client = new PostgresClient(options.uri);
} else {
this._client = new PostgresClient({
Expand Down

0 comments on commit 84ad078

Please sign in to comment.