Skip to content

Commit 7eabd65

Browse files
committed
chore: foreignTable -> referencedTable
1 parent 18f580c commit 7eabd65

File tree

3 files changed

+67
-29
lines changed

3 files changed

+67
-29
lines changed

src/PostgrestFilterBuilder.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,19 @@ export default class PostgrestFilterBuilder<
487487
* It's currently not possible to do an `.or()` filter across multiple tables.
488488
*
489489
* @param filters - The filters to use, following PostgREST syntax
490-
* @param foreignTable - Set this to filter on foreign tables instead of the
491-
* current table
490+
* @param options - Named parameters
491+
* @param options.referencedTable - Set this to filter on referenced tables
492+
* instead of the parent table
493+
* @param options.foreignTable - Deprecated, use `referencedTable` instead
492494
*/
493-
or(filters: string, { foreignTable }: { foreignTable?: string } = {}): this {
494-
const key = foreignTable ? `${foreignTable}.or` : 'or'
495+
or(
496+
filters: string,
497+
{
498+
foreignTable,
499+
referencedTable = foreignTable,
500+
}: { foreignTable?: string; referencedTable?: string } = {}
501+
): this {
502+
const key = referencedTable ? `${referencedTable}.or` : 'or'
495503
this.url.searchParams.append(key, `(${filters})`)
496504
return this
497505
}

src/PostgrestTransformBuilder.ts

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,24 @@ export default class PostgrestTransformBuilder<
4242
return this as unknown as PostgrestTransformBuilder<Schema, Row, NewResultOne[], Relationships>
4343
}
4444

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+
*/
4556
order<ColumnName extends string & keyof Row>(
4657
column: ColumnName,
4758
options?: { ascending?: boolean; nullsFirst?: boolean; foreignTable?: undefined }
4859
): this
60+
/**
61+
* @deprecated Use `options.referencedTable` instead of `options.foreignTable`
62+
*/
4963
order(
5064
column: string,
5165
options?: { ascending?: boolean; nullsFirst?: boolean; foreignTable?: string }
@@ -55,26 +69,34 @@ export default class PostgrestTransformBuilder<
5569
*
5670
* You can call this method multiple times to order by multiple columns.
5771
*
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.
6074
*
6175
* @param column - The column to order by
6276
* @param options - Named parameters
6377
* @param options.ascending - If `true`, the result will be in ascending order
6478
* @param options.nullsFirst - If `true`, `null`s appear first. If `false`,
6579
* `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
6884
*/
6985
order(
7086
column: string,
7187
{
7288
ascending = true,
7389
nullsFirst,
7490
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+
} = {}
7698
): this {
77-
const key = foreignTable ? `${foreignTable}.order` : 'order'
99+
const key = referencedTable ? `${referencedTable}.order` : 'order'
78100
const existingOrder = this.url.searchParams.get(key)
79101

80102
this.url.searchParams.set(
@@ -91,11 +113,19 @@ export default class PostgrestTransformBuilder<
91113
*
92114
* @param count - The maximum number of rows to return
93115
* @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
96120
*/
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`
99129
this.url.searchParams.set(key, `${count}`)
100130
return this
101131
}
@@ -110,12 +140,22 @@ export default class PostgrestTransformBuilder<
110140
* @param from - The starting index from which to limit the result
111141
* @param to - The last index to which to limit the result
112142
* @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
115147
*/
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`
119159
this.url.searchParams.set(keyOffset, `${from}`)
120160
// Range is inclusive, so add 1
121161
this.url.searchParams.set(keyLimit, `${to - from + 1}`)

src/select-query-parser.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ type Letter = Alphabet | Digit | '_'
4040

4141
type Json = string | number | boolean | null | { [key: string]: Json } | Json[]
4242

43-
// /**
44-
// * Parsed node types.
45-
// * Currently only `*` and all other fields.
46-
// */
47-
// type ParsedNode =
48-
// | { star: true }
49-
// | { name: string; original: string }
50-
// | { name: string; foreignTable: true }
51-
// | { name: string; type: T };
52-
5343
/**
5444
* Parser errors.
5545
*/

0 commit comments

Comments
 (0)