import { PgCodecs, PostgresType } from "./codecs.cjs";
import { PgMaterializedView, PgView } from "./view.cjs";
import { entityKind } from "../entity.cjs";
import { Query, SQL } from "../sql/sql.cjs";
import { RowsMapperGenerator, UpdateSet } from "../utils.cjs";
import { BuildRelationalQueryResult, DBQueryConfigWithComment, RelationalRowsMapperGenerator, TableRelationalConfig, TablesRelationalConfig } from "../relations.cjs";
import { CodecsCollection } from "../codecs.cjs";
import { PgTable } from "./table.cjs";
import { PgDeleteConfig, PgInsertConfig, PgUpdateConfig } from "./query-builders/index.cjs";
import { PgSelectConfig, SelectedFieldsOrdered } from "./query-builders/select.types.cjs";

//#region src/pg-core/dialect.d.ts
/** Used to build mappers directly in driver in minipg */
type PreparedQuerySelection = {
  type: 'plain';
  fields: SelectedFieldsOrdered;
} | {
  type: 'relational';
  fields: BuildRelationalQueryResult['selection'];
};
/** Selection shape converter for driver-side mapping, provided per driver where supported */
type ShapeGenerator = (selection: PreparedQuerySelection, nullableObjectPaths: string[] | undefined) => any;
interface PgDialectConfig {
  codecs?: PgCodecs;
  useJitMappers?: boolean;
  shapeGenerator?: ShapeGenerator;
}
declare class PgDialect {
  static readonly [entityKind]: string;
  readonly codecs: CodecsCollection<PostgresType>;
  readonly mapperGenerators: {
    rows: RowsMapperGenerator;
    relationalRows: RelationalRowsMapperGenerator;
  };
  readonly shapeGenerator?: ShapeGenerator;
  constructor(config?: PgDialectConfig);
  escapeName(name: string): string;
  escapeParam(num: number): string;
  escapeString(str: string): string;
  private buildWithCTE;
  buildDeleteQuery({
    table,
    where,
    returning,
    withList,
    comment,
    ignoreSelectionCastCodecs
  }: PgDeleteConfig): SQL;
  buildUpdateSet(table: PgTable, set: UpdateSet): SQL;
  buildUpdateQuery({
    table,
    set,
    where,
    returning,
    withList,
    from,
    joins,
    comment,
    ignoreSelectionCastCodecs
  }: PgUpdateConfig): SQL;
  /**
   * Builds selection SQL with provided fields/expressions
   *
   * Examples:
   *
   * `select <selection> from`
   *
   * `insert ... returning <selection>`
   *
   * If `isSingleTable` is true, then columns won't be prefixed with table name
   */
  private buildSelection;
  private buildJoins;
  private buildFromTable;
  buildSelectQuery({
    withList,
    fieldsFlat,
    where,
    having,
    table,
    joins,
    orderBy,
    groupBy,
    limit,
    offset,
    lockingClause,
    distinct,
    setOperators,
    setFieldsFlat: setSelection,
    comment,
    ignoreSelectionCastCodecs
  }: PgSelectConfig): SQL;
  buildSetOperations(leftSelect: SQL, outputSelection: SelectedFieldsOrdered, ignoreSelectionCastCodecs: boolean | undefined, setOperators: PgSelectConfig['setOperators']): SQL;
  buildSetOperationQuery({
    leftSelect,
    setOperator: {
      type,
      isAll,
      rightSelect,
      limit,
      orderBy,
      offset
    }
  }: {
    leftSelect: SQL;
    setOperator: PgSelectConfig['setOperators'][number];
  }): SQL;
  buildInsertQuery({
    table,
    values: valuesOrSelect,
    onConflict,
    returning,
    withList,
    select,
    overridingSystemValue_,
    comment,
    columnList,
    ignoreSelectionCastCodecs
  }: PgInsertConfig): SQL;
  buildRefreshMaterializedViewQuery({
    view,
    concurrently,
    withNoData
  }: {
    view: PgMaterializedView;
    concurrently?: boolean;
    withNoData?: boolean;
  }): SQL;
  sqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): Query;
  _sqlToQuery(sql: SQL): Query;
  private buildRqbColumn;
  private buildColumns;
  buildRelationalQuery({
    schema,
    table,
    tableConfig,
    queryConfig: config,
    relationWhere,
    mode,
    errorPath,
    depth,
    throughJoin,
    nested
  }: {
    schema: TablesRelationalConfig;
    table: PgTable | PgView;
    tableConfig: TableRelationalConfig;
    queryConfig?: DBQueryConfigWithComment<'many'> | true;
    relationWhere?: SQL;
    mode: 'first' | 'many';
    errorPath?: string;
    depth?: number;
    throughJoin?: SQL;
    nested?: boolean;
  }): BuildRelationalQueryResult;
}
//#endregion
export { PgDialect, PgDialectConfig, PreparedQuerySelection, ShapeGenerator };
//# sourceMappingURL=dialect.d.cts.map