@@ -10,6 +10,7 @@ import { TypeEqual } from 'ts-expect'
10
10
import {
11
11
FindMatchingTableRelationships ,
12
12
IsRelationNullable ,
13
+ FindJoinTableRelationship ,
13
14
} from '../../src/select-query-parser/utils'
14
15
import { Json } from '../../src/select-query-parser/types'
15
16
import { ParseQuery } from '../../src/select-query-parser/parser'
@@ -124,11 +125,8 @@ import { ParseQuery } from '../../src/select-query-parser/parser'
124
125
type Row = Schema [ 'Tables' ] [ RelationName ] [ 'Row' ]
125
126
type Relationships = Schema [ 'Tables' ] [ RelationName ] [ 'Relationships' ]
126
127
type ParsedQuery = ParseQuery < typeof select >
127
- // First field of the query is username and is properly parsed
128
- type f1 = ParsedQuery [ 0 ]
129
128
type r1 = ProcessNode < Schema , Row , RelationName , Relationships , ParsedQuery [ 0 ] >
130
129
expectType < TypeEqual < r1 , { username : string } > > ( true )
131
- type f2 = ParsedQuery [ 1 ]
132
130
type r2 = ProcessNodes < Schema , Row , RelationName , Relationships , ParsedQuery >
133
131
// fail because result for messages is ({id: string} | {message: string | null })[]
134
132
expectType <
@@ -160,3 +158,42 @@ import { ParseQuery } from '../../src/select-query-parser/parser'
160
158
type r2 = ProcessNodes < Schema , Row , RelationName , Relationships , ParsedQuery >
161
159
expectType < r2 > ( expected ! )
162
160
}
161
+
162
+ {
163
+ type Schema = Database [ 'public' ]
164
+ type CurrentTableOrView = 'products'
165
+ type FieldName = 'categories'
166
+ type R = FindJoinTableRelationship < Schema , CurrentTableOrView , FieldName >
167
+ let expected : {
168
+ foreignKeyName : 'product_categories_category_id_fkey'
169
+ columns : [ 'category_id' ]
170
+ isOneToOne : false
171
+ referencedRelation : 'categories'
172
+ referencedColumns : [ 'id' ]
173
+ }
174
+ expectType < R > ( expected ! )
175
+ }
176
+
177
+ {
178
+ type Schema = Database [ 'public' ]
179
+ type CurrentTableOrView = 'categories'
180
+ type FieldName = 'products'
181
+ type R = FindJoinTableRelationship < Schema , CurrentTableOrView , FieldName >
182
+ let expected : {
183
+ foreignKeyName : 'product_categories_product_id_fkey'
184
+ columns : [ 'product_id' ]
185
+ isOneToOne : false
186
+ referencedRelation : 'products'
187
+ referencedColumns : [ 'id' ]
188
+ }
189
+ expectType < R > ( expected ! )
190
+ }
191
+
192
+ {
193
+ type Schema = Database [ 'public' ]
194
+ type CurrentTableOrView = 'categories'
195
+ type FieldName = 'missing'
196
+ type R = FindJoinTableRelationship < Schema , CurrentTableOrView , FieldName >
197
+ let expected : never
198
+ expectType < R > ( expected ! )
199
+ }
0 commit comments