Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 4188925

Browse files
authored
Merge pull request #165 from supabase/feat/rename-filters
Rename filters
2 parents b1369cd + 9ca784e commit 4188925

File tree

4 files changed

+833
-1172
lines changed

4 files changed

+833
-1172
lines changed

package-lock.json

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/PostgrestFilterBuilder.ts

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
188188
* @param column The column to filter on.
189189
* @param value The value to filter with.
190190
*/
191-
cs(column: keyof T, value: string | T[keyof T][] | object): this {
191+
contains(column: keyof T, value: string | T[keyof T][] | object): this {
192192
if (typeof value === 'string') {
193193
// range types can be inclusive '[', ']' or exclusive '(', ')' so just
194194
// keep it simple and accept a string
@@ -203,14 +203,17 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
203203
return this
204204
}
205205

206+
/** @deprecated Use `contains()` instead. */
207+
cs = this.contains
208+
206209
/**
207210
* Finds all rows whose json, array, or range value on the stated `column` is
208211
* contained by the specified `value`.
209212
*
210213
* @param column The column to filter on.
211214
* @param value The value to filter with.
212215
*/
213-
cd(column: keyof T, value: string | T[keyof T][] | object): this {
216+
containedBy(column: keyof T, value: string | T[keyof T][] | object): this {
214217
if (typeof value === 'string') {
215218
// range
216219
this.url.searchParams.append(`${column}`, `cd.${value}`)
@@ -224,74 +227,92 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
224227
return this
225228
}
226229

230+
/** @deprecated Use `containedBy()` instead. */
231+
cd = this.containedBy
232+
227233
/**
228234
* Finds all rows whose range value on the stated `column` is strictly to the
229235
* left of the specified `range`.
230236
*
231237
* @param column The column to filter on.
232238
* @param range The range to filter with.
233239
*/
234-
sl(column: keyof T, range: string): this {
240+
rangeLt(column: keyof T, range: string): this {
235241
this.url.searchParams.append(`${column}`, `sl.${range}`)
236242
return this
237243
}
238244

245+
/** @deprecated Use `rangeLt()` instead. */
246+
sl = this.rangeLt
247+
239248
/**
240249
* Finds all rows whose range value on the stated `column` is strictly to
241250
* the right of the specified `range`.
242251
*
243252
* @param column The column to filter on.
244253
* @param range The range to filter with.
245254
*/
246-
sr(column: keyof T, range: string): this {
255+
rangeGt(column: keyof T, range: string): this {
247256
this.url.searchParams.append(`${column}`, `sr.${range}`)
248257
return this
249258
}
250259

260+
/** @deprecated Use `rangeGt()` instead. */
261+
sr = this.rangeGt
262+
251263
/**
252264
* Finds all rows whose range value on the stated `column` does not extend
253265
* to the left of the specified `range`.
254266
*
255267
* @param column The column to filter on.
256268
* @param range The range to filter with.
257269
*/
258-
nxl(column: keyof T, range: string): this {
270+
rangeGte(column: keyof T, range: string): this {
259271
this.url.searchParams.append(`${column}`, `nxl.${range}`)
260272
return this
261273
}
262274

275+
/** @deprecated Use `rangeGte()` instead. */
276+
nxl = this.rangeGte
277+
263278
/**
264279
* Finds all rows whose range value on the stated `column` does not extend
265280
* to the right of the specified `range`.
266281
*
267282
* @param column The column to filter on.
268283
* @param range The range to filter with.
269284
*/
270-
nxr(column: keyof T, range: string): this {
285+
rangeLte(column: keyof T, range: string): this {
271286
this.url.searchParams.append(`${column}`, `nxr.${range}`)
272287
return this
273288
}
274289

290+
/** @deprecated Use `rangeLte()` instead. */
291+
nxr = this.rangeLte
292+
275293
/**
276294
* Finds all rows whose range value on the stated `column` is adjacent to
277295
* the specified `range`.
278296
*
279297
* @param column The column to filter on.
280298
* @param range The range to filter with.
281299
*/
282-
adj(column: keyof T, range: string): this {
300+
rangeAdjacent(column: keyof T, range: string): this {
283301
this.url.searchParams.append(`${column}`, `adj.${range}`)
284302
return this
285303
}
286304

305+
/** @deprecated Use `rangeAdjacent()` instead. */
306+
adj = this.rangeAdjacent
307+
287308
/**
288-
* Finds all rows whose array or range value on the stated `column` is
289-
* contained by the specified `value`.
309+
* Finds all rows whose array or range value on the stated `column` overlaps
310+
* (has a value in common) with the specified `value`.
290311
*
291312
* @param column The column to filter on.
292313
* @param value The value to filter with.
293314
*/
294-
ov(column: keyof T, value: string | T[keyof T][]): this {
315+
overlaps(column: keyof T, value: string | T[keyof T][]): this {
295316
if (typeof value === 'string') {
296317
// range
297318
this.url.searchParams.append(`${column}`, `ov.${value}`)
@@ -302,13 +323,48 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
302323
return this
303324
}
304325

326+
/** @deprecated Use `overlaps()` instead. */
327+
ov = this.overlaps
328+
329+
/**
330+
* Finds all rows whose text or tsvector value on the stated `column` matches
331+
* the tsquery in `query`.
332+
*
333+
* @param column The column to filter on.
334+
* @param query The Postgres tsquery string to filter with.
335+
* @param config The text search configuration to use.
336+
* @param type The type of tsquery conversion to use on `query`.
337+
*/
338+
textSearch(
339+
column: keyof T,
340+
query: string,
341+
{
342+
config,
343+
type = null,
344+
}: { config?: string; type?: 'plain' | 'phrase' | 'websearch' | null } = {}
345+
): this {
346+
let typePart = ''
347+
if (type === 'plain') {
348+
typePart = 'pl'
349+
} else if (type === 'phrase') {
350+
typePart = 'ph'
351+
} else if (type === 'websearch') {
352+
typePart = 'w'
353+
}
354+
const configPart = config === undefined ? '' : `(${config})`
355+
this.url.searchParams.append(`${column}`, `${typePart}fts${configPart}.${query}`)
356+
return this
357+
}
358+
305359
/**
306360
* Finds all rows whose tsvector value on the stated `column` matches
307361
* to_tsquery(`query`).
308362
*
309363
* @param column The column to filter on.
310364
* @param query The Postgres tsquery string to filter with.
311365
* @param config The text search configuration to use.
366+
*
367+
* @deprecated Use `textSearch()` instead.
312368
*/
313369
fts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
314370
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -323,6 +379,8 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
323379
* @param column The column to filter on.
324380
* @param query The Postgres tsquery string to filter with.
325381
* @param config The text search configuration to use.
382+
*
383+
* @deprecated Use `textSearch()` with `type: 'plain'` instead.
326384
*/
327385
plfts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
328386
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -337,6 +395,8 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
337395
* @param column The column to filter on.
338396
* @param query The Postgres tsquery string to filter with.
339397
* @param config The text search configuration to use.
398+
*
399+
* @deprecated Use `textSearch()` with `type: 'phrase'` instead.
340400
*/
341401
phfts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
342402
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -351,6 +411,8 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
351411
* @param column The column to filter on.
352412
* @param query The Postgres tsquery string to filter with.
353413
* @param config The text search configuration to use.
414+
*
415+
* @deprecated Use `textSearch()` with `type: 'websearch'` instead.
354416
*/
355417
wfts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
356418
const configPart = typeof config === 'undefined' ? '' : `(${config})`

0 commit comments

Comments
 (0)