11import { type AnyTable , getTableUniqueName , type InferModelFromColumns , Table } from '~/table.ts' ;
22import { type AnyColumn , Column } from './column.ts' ;
3- import { entityKind , is } from './entity.ts' ;
3+ import { is } from './entity.ts' ;
44import { PrimaryKeyBuilder } from './pg-core/primary-keys.ts' ;
55import {
66 and ,
@@ -31,7 +31,7 @@ import { type Placeholder, SQL, sql } from './sql/sql.ts';
3131import type { Assume , ColumnsWithTable , Equal , Simplify , ValueOrArray } from './utils.ts' ;
3232
3333export abstract class Relation < TTableName extends string = string > {
34- static readonly [ entityKind ] : string = 'Relation' ;
34+ static readonly [ 'drizzle: entityKind' ] : string = 'Relation' ;
3535
3636 declare readonly $brand : 'Relation' ;
3737 readonly referencedTableName : TTableName ;
@@ -52,7 +52,7 @@ export class Relations<
5252 TTableName extends string = string ,
5353 TConfig extends Record < string , Relation > = Record < string , Relation > ,
5454> {
55- static readonly [ entityKind ] : string = 'Relations' ;
55+ static readonly [ 'drizzle: entityKind' ] : string = 'Relations' ;
5656
5757 declare readonly $brand : 'Relations' ;
5858
@@ -66,7 +66,7 @@ export class One<
6666 TTableName extends string = string ,
6767 TIsNullable extends boolean = boolean ,
6868> extends Relation < TTableName > {
69- static override readonly [ entityKind ] : string = 'One' ;
69+ static override readonly [ 'drizzle: entityKind' ] : string = 'One' ;
7070
7171 declare protected $relationBrand : 'One' ;
7272
@@ -98,7 +98,7 @@ export class One<
9898}
9999
100100export class Many < TTableName extends string > extends Relation < TTableName > {
101- static override readonly [ entityKind ] : string = 'Many' ;
101+ static override readonly [ 'drizzle: entityKind' ] : string = 'Many' ;
102102
103103 declare protected $relationBrand : 'Many' ;
104104
@@ -156,7 +156,30 @@ export type ExtractRelationsFromTableExtraConfigSchema<
156156 }
157157> ;
158158
159- export function getOperators ( ) {
159+ export function getOperators ( ) : {
160+ and : typeof and ;
161+ between : typeof between ;
162+ eq : typeof eq ;
163+ exists : typeof exists ;
164+ gt : typeof gt ;
165+ gte : typeof gte ;
166+ ilike : typeof ilike ;
167+ inArray : typeof inArray ;
168+ isNull : typeof isNull ;
169+ isNotNull : typeof isNotNull ;
170+ like : typeof like ;
171+ lt : typeof lt ;
172+ lte : typeof lte ;
173+ ne : typeof ne ;
174+ not : typeof not ;
175+ notBetween : typeof notBetween ;
176+ notExists : typeof notExists ;
177+ notLike : typeof notLike ;
178+ notIlike : typeof notIlike ;
179+ notInArray : typeof notInArray ;
180+ or : typeof or ;
181+ sql : typeof sql ;
182+ } {
160183 return {
161184 and,
162185 between,
@@ -185,7 +208,11 @@ export function getOperators() {
185208
186209export type Operators = ReturnType < typeof getOperators > ;
187210
188- export function getOrderByOperators ( ) {
211+ export function getOrderByOperators ( ) : {
212+ sql : typeof sql ;
213+ asc : typeof asc ;
214+ desc : typeof desc ;
215+ } {
189216 return {
190217 sql,
191218 asc,
@@ -518,7 +545,19 @@ export function relations<
518545 ) ;
519546}
520547
521- export function createOne < TTableName extends string > ( sourceTable : Table ) {
548+ export function createOne < TTableName extends string > ( sourceTable : Table ) : <
549+ TForeignTable extends Table ,
550+ TColumns extends [
551+ AnyColumn < { tableName : TTableName } > ,
552+ ...AnyColumn < { tableName : TTableName } > [ ] ,
553+ ] ,
554+ > (
555+ table : TForeignTable ,
556+ config ?: RelationConfig < TTableName , TForeignTable [ '_' ] [ 'name' ] , TColumns > ,
557+ ) => One <
558+ TForeignTable [ '_' ] [ 'name' ] ,
559+ Equal < TColumns [ number ] [ '_' ] [ 'notNull' ] , true >
560+ > {
522561 return function one <
523562 TForeignTable extends Table ,
524563 TColumns extends [
@@ -542,7 +581,10 @@ export function createOne<TTableName extends string>(sourceTable: Table) {
542581 } ;
543582}
544583
545- export function createMany ( sourceTable : Table ) {
584+ export function createMany ( sourceTable : Table ) : < TForeignTable extends Table > (
585+ referencedTable : TForeignTable ,
586+ config ?: { relationName : string } ,
587+ ) => Many < TForeignTable [ '_' ] [ 'name' ] > {
546588 return function many < TForeignTable extends Table > (
547589 referencedTable : TForeignTable ,
548590 config ?: { relationName : string } ,
@@ -635,7 +677,10 @@ export function normalizeRelation(
635677
636678export function createTableRelationsHelpers < TTableName extends string > (
637679 sourceTable : AnyTable < { name : TTableName } > ,
638- ) {
680+ ) : {
681+ one : ReturnType < typeof createOne < TTableName > > ;
682+ many : ReturnType < typeof createMany > ;
683+ } {
639684 return {
640685 one : createOne < TTableName > ( sourceTable ) ,
641686 many : createMany ( sourceTable ) ,
0 commit comments