<commit_before>import { Credentials } from "@dataform/api/commands/credentials";
import { IDbAdapter } from "@dataform/api/dbadapters/index";
import { dataform } from "@dataform/protos";
import * as pg from "pg";
import * as Cursor from "pg-cursor";
import * as PromisePool from "promise-pool-executor";

interface ICursor {
  read: (rowCount: number, callback: (err: Error, rows: any[]) => void) => void;
  close: (callback: (err: Error) => void) => void;
}

export class RedshiftDbAdapter implements IDbAdapter {
  private queryExecutor: IPgQueryExecutor;

  constructor(
    credentials: Credentials,
    // Intended for temporary testing, not included in a permanent API.
    usePgPool: boolean
  ) {
    this.queryExecutor = new PgClientExecutor(credentials as dataform.IJDBC);
  }

  public async execute(
    statement: string,
    options: {
      maxResults?: number;
    } = { maxResults: 1000 }
  ) {
    return this.queryExecutor.execute(statement, options);
  }

  public async evaluate(statement: string) {
    await this.execute(`explain ${statement}`);
  }

  public async tables(): Promise<dataform.ITarget[]> {
    const rows = await this.execute(
      `select table_name, table_schema
     from information_schema.tables
     where table_schema != 'information_schema'
       and table_schema != 'pg_catalog'
       and table_schema != 'pg_internal'
       union select tablename as table_name, schemaname as table_schema from svv_external_tables`,
      { maxResults: 10000 }<commit_msg>Actually use the pg.Pool executor for redshift when requested to do so. (#496)<commit_after>import { Credentials } from "@dataform/api/commands/credentials";
import { IDbAdapter } from "@dataform/api/dbadapters/index";
import { dataform } from "@dataform/protos";
import * as pg from "pg";
import * as Cursor from "pg-cursor";
import * as PromisePool from "promise-pool-executor";

interface ICursor {
  read: (rowCount: number, callback: (err: Error, rows: any[]) => void) => void;
  close: (callback: (err: Error) => void) => void;
}

export class RedshiftDbAdapter implements IDbAdapter {
  private queryExecutor: IPgQueryExecutor;

  constructor(
    credentials: Credentials,
    // Intended for temporary testing, not included in a permanent API.
    usePgPool: boolean
  ) {
    this.queryExecutor = usePgPool
      ? new PgClientExecutor(credentials as dataform.IJDBC)
      : new PgPoolExecutor(credentials as dataform.IJDBC);
  }

  public async execute(
    statement: string,
    options: {
      maxResults?: number;
    } = { maxResults: 1000 }
  ) {
    return this.queryExecutor.execute(statement, options);
  }

  public async evaluate(statement: string) {
    await this.execute(`explain ${statement}`);
  }

  public async tables(): Promise<dataform.ITarget[]> {
    const rows = await this.execute(
      `select table_name, table_schema
     from information_schema.tables
     where table_schema != 'information_schema'
       and table_schema != 'pg_catalog'
       and table_schema != 'pg_internal'
       union select tablename as table_name, schemaname as table_schema from svv_external_tables`,
      { maxResults: 10000 }
{'fraction_non_alphanumeric': 0.10706366803927779, 'fraction_numerical': 0.0066518847006651885, 'mean_word_length': 3.911353032659409, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '89276', 'n_tokens_mistral': 957, 'n_tokens_neox': 921, 'n_words': 271}