@@ -42,10 +42,24 @@ export default class PostgrestTransformBuilder<
42
42
return this as unknown as PostgrestTransformBuilder < Schema , Row , NewResultOne [ ] , Relationships >
43
43
}
44
44
45
+ order < ColumnName extends string & keyof Row > (
46
+ column : ColumnName ,
47
+ options ?: { ascending ?: boolean ; nullsFirst ?: boolean ; referencedTable ?: undefined }
48
+ ) : this
49
+ order (
50
+ column : string ,
51
+ options ?: { ascending ?: boolean ; nullsFirst ?: boolean ; referencedTable ?: string }
52
+ ) : this
53
+ /**
54
+ * @deprecated Use `options.referencedTable` instead of `options.foreignTable`
55
+ */
45
56
order < ColumnName extends string & keyof Row > (
46
57
column : ColumnName ,
47
58
options ?: { ascending ?: boolean ; nullsFirst ?: boolean ; foreignTable ?: undefined }
48
59
) : this
60
+ /**
61
+ * @deprecated Use `options.referencedTable` instead of `options.foreignTable`
62
+ */
49
63
order (
50
64
column : string ,
51
65
options ?: { ascending ?: boolean ; nullsFirst ?: boolean ; foreignTable ?: string }
@@ -55,26 +69,34 @@ export default class PostgrestTransformBuilder<
55
69
*
56
70
* You can call this method multiple times to order by multiple columns.
57
71
*
58
- * You can order foreign tables, but it doesn't affect the ordering of the
59
- * current table.
72
+ * You can order referenced tables, but it only affects the ordering of the
73
+ * parent table if you use `!inner` in the query .
60
74
*
61
75
* @param column - The column to order by
62
76
* @param options - Named parameters
63
77
* @param options.ascending - If `true`, the result will be in ascending order
64
78
* @param options.nullsFirst - If `true`, `null`s appear first. If `false`,
65
79
* `null`s appear last.
66
- * @param options.foreignTable - Set this to order a foreign table by foreign
67
- * columns
80
+ * @param options.referencedTable - Set this to order a referenced table by
81
+ * its columns
82
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
83
+ * instead
68
84
*/
69
85
order (
70
86
column : string ,
71
87
{
72
88
ascending = true ,
73
89
nullsFirst,
74
90
foreignTable,
75
- } : { ascending ?: boolean ; nullsFirst ?: boolean ; foreignTable ?: string } = { }
91
+ referencedTable = foreignTable ,
92
+ } : {
93
+ ascending ?: boolean
94
+ nullsFirst ?: boolean
95
+ foreignTable ?: string
96
+ referencedTable ?: string
97
+ } = { }
76
98
) : this {
77
- const key = foreignTable ? `${ foreignTable } .order` : 'order'
99
+ const key = referencedTable ? `${ referencedTable } .order` : 'order'
78
100
const existingOrder = this . url . searchParams . get ( key )
79
101
80
102
this . url . searchParams . set (
@@ -91,11 +113,19 @@ export default class PostgrestTransformBuilder<
91
113
*
92
114
* @param count - The maximum number of rows to return
93
115
* @param options - Named parameters
94
- * @param options.foreignTable - Set this to limit rows of foreign tables
95
- * instead of the current table
116
+ * @param options.referencedTable - Set this to limit rows of referenced
117
+ * tables instead of the parent table
118
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
119
+ * instead
96
120
*/
97
- limit ( count : number , { foreignTable } : { foreignTable ?: string } = { } ) : this {
98
- const key = typeof foreignTable === 'undefined' ? 'limit' : `${ foreignTable } .limit`
121
+ limit (
122
+ count : number ,
123
+ {
124
+ foreignTable,
125
+ referencedTable = foreignTable ,
126
+ } : { foreignTable ?: string ; referencedTable ?: string } = { }
127
+ ) : this {
128
+ const key = typeof referencedTable === 'undefined' ? 'limit' : `${ referencedTable } .limit`
99
129
this . url . searchParams . set ( key , `${ count } ` )
100
130
return this
101
131
}
@@ -110,12 +140,22 @@ export default class PostgrestTransformBuilder<
110
140
* @param from - The starting index from which to limit the result
111
141
* @param to - The last index to which to limit the result
112
142
* @param options - Named parameters
113
- * @param options.foreignTable - Set this to limit rows of foreign tables
114
- * instead of the current table
143
+ * @param options.referencedTable - Set this to limit rows of referenced
144
+ * tables instead of the parent table
145
+ * @param options.foreignTable - Deprecated, use `options.referencedTable`
146
+ * instead
115
147
*/
116
- range ( from : number , to : number , { foreignTable } : { foreignTable ?: string } = { } ) : this {
117
- const keyOffset = typeof foreignTable === 'undefined' ? 'offset' : `${ foreignTable } .offset`
118
- const keyLimit = typeof foreignTable === 'undefined' ? 'limit' : `${ foreignTable } .limit`
148
+ range (
149
+ from : number ,
150
+ to : number ,
151
+ {
152
+ foreignTable,
153
+ referencedTable = foreignTable ,
154
+ } : { foreignTable ?: string ; referencedTable ?: string } = { }
155
+ ) : this {
156
+ const keyOffset =
157
+ typeof referencedTable === 'undefined' ? 'offset' : `${ referencedTable } .offset`
158
+ const keyLimit = typeof referencedTable === 'undefined' ? 'limit' : `${ referencedTable } .limit`
119
159
this . url . searchParams . set ( keyOffset , `${ from } ` )
120
160
// Range is inclusive, so add 1
121
161
this . url . searchParams . set ( keyLimit , `${ to - from + 1 } ` )
0 commit comments