/opt/canhelp/node_modules/drizzle-orm
Edit: /opt/canhelp/node_modules/drizzle-orm/relations.d.cts (12304B)
import { type AnyTable, type InferModelFromColumns, Table } from "./table.cjs";
import { type AnyColumn, Column } from "./column.cjs";
import { entityKind } from "./entity.cjs";
import { and, asc, between, desc, exists, ilike, inArray, isNotNull, isNull, like, not, notBetween, notExists, notIlike, notInArray, notLike, or } from "./sql/expressions/index.cjs";
import { type Placeholder, SQL, sql } from "./sql/sql.cjs";
import type { Assume, ColumnsWithTable, Equal, Simplify, ValueOrArray } from "./utils.cjs";
export declare abstract class Relation
{
readonly sourceTable: Table;
readonly referencedTable: AnyTable<{
name: TTableName;
}>;
readonly relationName: string | undefined;
static readonly [entityKind]: string;
readonly $brand: 'Relation';
readonly referencedTableName: TTableName;
fieldName: string;
constructor(sourceTable: Table, referencedTable: AnyTable<{
name: TTableName;
}>, relationName: string | undefined);
abstract withFieldName(fieldName: string): Relation;
}
export declare class Relations = Record> {
readonly table: AnyTable<{
name: TTableName;
}>;
readonly config: (helpers: TableRelationsHelpers) => TConfig;
static readonly [entityKind]: string;
readonly $brand: 'Relations';
constructor(table: AnyTable<{
name: TTableName;
}>, config: (helpers: TableRelationsHelpers) => TConfig);
}
export declare class One extends Relation {
readonly config: RelationConfig[]> | undefined;
readonly isNullable: TIsNullable;
static readonly [entityKind]: string;
protected $relationBrand: 'One';
constructor(sourceTable: Table, referencedTable: AnyTable<{
name: TTableName;
}>, config: RelationConfig[]> | undefined, isNullable: TIsNullable);
withFieldName(fieldName: string): One;
}
export declare class Many extends Relation {
readonly config: {
relationName: string;
} | undefined;
static readonly [entityKind]: string;
protected $relationBrand: 'Many';
constructor(sourceTable: Table, referencedTable: AnyTable<{
name: TTableName;
}>, config: {
relationName: string;
} | undefined);
withFieldName(fieldName: string): Many;
}
export type TableRelationsKeysOnly, TTableName extends string, K extends keyof TSchema> = TSchema[K] extends Relations ? K : never;
export type ExtractTableRelationsFromSchema, TTableName extends string> = ExtractObjectValues<{
[K in keyof TSchema as TableRelationsKeysOnly]: TSchema[K] extends Relations ? TConfig : never;
}>;
export type ExtractObjectValues = T[keyof T];
export type ExtractRelationsFromTableExtraConfigSchema = ExtractObjectValues<{
[K in keyof TConfig as TConfig[K] extends Relations ? K : never]: TConfig[K] extends Relations ? TRelationConfig : never;
}>;
export declare function getOperators(): {
and: typeof and;
between: typeof between;
eq: import("./expressions.ts").BinaryOperator;
exists: typeof exists;
gt: import("./expressions.ts").BinaryOperator;
gte: import("./expressions.ts").BinaryOperator;
ilike: typeof ilike;
inArray: typeof inArray;
isNull: typeof isNull;
isNotNull: typeof isNotNull;
like: typeof like;
lt: import("./expressions.ts").BinaryOperator;
lte: import("./expressions.ts").BinaryOperator;
ne: import("./expressions.ts").BinaryOperator;
not: typeof not;
notBetween: typeof notBetween;
notExists: typeof notExists;
notLike: typeof notLike;
notIlike: typeof notIlike;
notInArray: typeof notInArray;
or: typeof or;
sql: typeof sql;
};
export type Operators = ReturnType;
export declare function getOrderByOperators(): {
sql: typeof sql;
asc: typeof asc;
desc: typeof desc;
};
export type OrderByOperators = ReturnType;
export type FindTableByDBName = ExtractObjectValues<{
[K in keyof TSchema as TSchema[K]['dbName'] extends TTableName ? K : never]: TSchema[K];
}>;
export type DBQueryConfig = {
columns?: {
[K in keyof TTableConfig['columns']]?: boolean;
} | undefined;
with?: {
[K in keyof TTableConfig['relations']]?: true | DBQueryConfig> | undefined;
} | undefined;
extras?: Record | ((fields: Simplify<[
TTableConfig['columns']
] extends [never] ? {} : TTableConfig['columns']>, operators: {
sql: Operators['sql'];
}) => Record) | undefined;
} & (TRelationType extends 'many' ? {
where?: SQL | undefined | ((fields: Simplify<[
TTableConfig['columns']
] extends [never] ? {} : TTableConfig['columns']>, operators: Operators) => SQL | undefined);
orderBy?: ValueOrArray | ((fields: Simplify<[
TTableConfig['columns']
] extends [never] ? {} : TTableConfig['columns']>, operators: OrderByOperators) => ValueOrArray) | undefined;
limit?: number | Placeholder | undefined;
} & (TIsRoot extends true ? {
offset?: number | Placeholder | undefined;
} : {}) : {});
export interface TableRelationalConfig {
tsName: string;
dbName: string;
columns: Record;
relations: Record;
primaryKey: AnyColumn[];
schema?: string;
}
export type TablesRelationalConfig = Record;
export interface RelationalSchemaConfig {
fullSchema: Record;
schema: TSchema;
tableNamesMap: Record;
}
export type ExtractTablesWithRelations> = {
[K in keyof TSchema as TSchema[K] extends Table ? K : never]: TSchema[K] extends Table ? {
tsName: K & string;
dbName: TSchema[K]['_']['name'];
columns: TSchema[K]['_']['columns'];
relations: ExtractTableRelationsFromSchema;
primaryKey: AnyColumn[];
} : never;
};
export type ReturnTypeOrValue = T extends (...args: any[]) => infer R ? R : T;
export type BuildRelationResult> = {
[K in NonUndefinedKeysOnly & keyof TRelations]: TRelations[K] extends infer TRel extends Relation ? BuildQueryResult, Assume>> extends infer TResult ? TRel extends One ? TResult | (Equal extends true ? null : never) : TResult[] : never : never;
};
export type NonUndefinedKeysOnly = ExtractObjectValues<{
[K in keyof T as T[K] extends undefined ? never : K]: K;
}> & keyof T;
export type BuildQueryResult> = Equal extends true ? InferModelFromColumns : TFullSelection extends Record ? Simplify<(TFullSelection['columns'] extends Record ? InferModelFromColumns<{
[K in Equal, false> extends true ? Exclude> : {
[K in keyof TFullSelection['columns']]: Equal extends true ? K : never;
}[keyof TFullSelection['columns']] & keyof TTableConfig['columns']]: TTableConfig['columns'][K];
}> : InferModelFromColumns) & (TFullSelection['extras'] extends Record | ((...args: any[]) => Record) ? {
[K in NonUndefinedKeysOnly>]: Assume[K], SQL.Aliased>['_']['type'];
} : {}) & (TFullSelection['with'] extends Record ? BuildRelationResult : {})> : never;
export interface RelationConfig[]> {
relationName?: string;
fields: TColumns;
references: ColumnsWithTable;
}
export declare function extractTablesRelationalConfig(schema: Record, configHelpers: (table: Table) => any): {
tables: TTables;
tableNamesMap: Record;
};
export declare function relations>>(table: AnyTable<{
name: TTableName;
}>, relations: (helpers: TableRelationsHelpers) => TRelations): Relations;
export declare function createOne(sourceTable: Table): , ...AnyColumn<{
tableName: TTableName;
}>[]]>(table: TForeignTable, config?: RelationConfig) => One>;
export declare function createMany(sourceTable: Table): (referencedTable: TForeignTable, config?: {
relationName: string;
}) => Many;
export interface NormalizedRelation {
fields: AnyColumn[];
references: AnyColumn[];
}
export declare function normalizeRelation(schema: TablesRelationalConfig, tableNamesMap: Record, relation: Relation): NormalizedRelation;
export declare function createTableRelationsHelpers(sourceTable: AnyTable<{
name: TTableName;
}>): {
one: , ...AnyColumn<{
tableName: TTableName;
}>[]]>(table: TForeignTable, config?: RelationConfig | undefined) => One>;
many: (referencedTable: TForeignTable, config?: {
relationName: string;
}) => Many;
};
export type TableRelationsHelpers = ReturnType>;
export interface BuildRelationalQueryResult {
tableTsKey: string;
selection: {
dbKey: string;
tsKey: string;
field: TColumn | SQL | SQL.Aliased;
relationTableTsKey: string | undefined;
isJson: boolean;
isExtra?: boolean;
selection: BuildRelationalQueryResult['selection'];
}[];
sql: TTable | SQL;
}
export declare function mapRelationalRow(tablesConfig: TablesRelationalConfig, tableConfig: TableRelationalConfig, row: unknown[], buildQueryResultSelection: BuildRelationalQueryResult['selection'], mapColumnValue?: (value: unknown) => unknown): Record;