Skip to content

Commit ccdb5df

Browse files
committed
feat: rename filters
1 parent e6a46be commit ccdb5df

File tree

1 file changed

+72
-10
lines changed

1 file changed

+72
-10
lines changed

Diff for: src/lib/PostgrestFilterBuilder.ts

+72-10
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
182182
* @param column The column to filter on.
183183
* @param value The value to filter with.
184184
*/
185-
cs(column: keyof T, value: string | T[keyof T][] | object): this {
185+
contains(column: keyof T, value: string | T[keyof T][] | object): this {
186186
if (typeof value === 'string') {
187187
// range types can be inclusive '[', ']' or exclusive '(', ')' so just
188188
// keep it simple and accept a string
@@ -197,14 +197,17 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
197197
return this
198198
}
199199

200+
/** @deprecated Use `contains()` instead. */
201+
cs = this.contains
202+
200203
/**
201204
* Finds all rows whose json, array, or range value on the stated `column` is
202205
* contained by the specified `value`.
203206
*
204207
* @param column The column to filter on.
205208
* @param value The value to filter with.
206209
*/
207-
cd(column: keyof T, value: string | T[keyof T][] | object): this {
210+
containedBy(column: keyof T, value: string | T[keyof T][] | object): this {
208211
if (typeof value === 'string') {
209212
// range
210213
this.url.searchParams.append(`${column}`, `cd.${value}`)
@@ -218,74 +221,92 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
218221
return this
219222
}
220223

224+
/** @deprecated Use `containedBy()` instead. */
225+
cd = this.containedBy
226+
221227
/**
222228
* Finds all rows whose range value on the stated `column` is strictly to the
223229
* left of the specified `range`.
224230
*
225231
* @param column The column to filter on.
226232
* @param range The range to filter with.
227233
*/
228-
sl(column: keyof T, range: string): this {
234+
rangeLt(column: keyof T, range: string): this {
229235
this.url.searchParams.append(`${column}`, `sl.${range}`)
230236
return this
231237
}
232238

239+
/** @deprecated Use `rangeLt()` instead. */
240+
sl = this.rangeLt
241+
233242
/**
234243
* Finds all rows whose range value on the stated `column` is strictly to
235244
* the right of the specified `range`.
236245
*
237246
* @param column The column to filter on.
238247
* @param range The range to filter with.
239248
*/
240-
sr(column: keyof T, range: string): this {
249+
rangeGt(column: keyof T, range: string): this {
241250
this.url.searchParams.append(`${column}`, `sr.${range}`)
242251
return this
243252
}
244253

254+
/** @deprecated Use `rangeGt()` instead. */
255+
sr = this.rangeGt
256+
245257
/**
246258
* Finds all rows whose range value on the stated `column` does not extend
247259
* to the left of the specified `range`.
248260
*
249261
* @param column The column to filter on.
250262
* @param range The range to filter with.
251263
*/
252-
nxl(column: keyof T, range: string): this {
264+
rangeGte(column: keyof T, range: string): this {
253265
this.url.searchParams.append(`${column}`, `nxl.${range}`)
254266
return this
255267
}
256268

269+
/** @deprecated Use `rangeGte()` instead. */
270+
nxl = this.rangeGte
271+
257272
/**
258273
* Finds all rows whose range value on the stated `column` does not extend
259274
* to the right of the specified `range`.
260275
*
261276
* @param column The column to filter on.
262277
* @param range The range to filter with.
263278
*/
264-
nxr(column: keyof T, range: string): this {
279+
rangeLte(column: keyof T, range: string): this {
265280
this.url.searchParams.append(`${column}`, `nxr.${range}`)
266281
return this
267282
}
268283

284+
/** @deprecated Use `rangeLte()` instead. */
285+
nxr = this.rangeLte
286+
269287
/**
270288
* Finds all rows whose range value on the stated `column` is adjacent to
271289
* the specified `range`.
272290
*
273291
* @param column The column to filter on.
274292
* @param range The range to filter with.
275293
*/
276-
adj(column: keyof T, range: string): this {
294+
adjacent(column: keyof T, range: string): this {
277295
this.url.searchParams.append(`${column}`, `adj.${range}`)
278296
return this
279297
}
280298

299+
/** @deprecated Use `adjacent()` instead. */
300+
adj = this.adjacent
301+
281302
/**
282-
* Finds all rows whose array or range value on the stated `column` is
283-
* contained by the specified `value`.
303+
* Finds all rows whose array or range value on the stated `column` overlaps
304+
* (has a value in common) with the specified `value`.
284305
*
285306
* @param column The column to filter on.
286307
* @param value The value to filter with.
287308
*/
288-
ov(column: keyof T, value: string | T[keyof T][]): this {
309+
overlaps(column: keyof T, value: string | T[keyof T][]): this {
289310
if (typeof value === 'string') {
290311
// range
291312
this.url.searchParams.append(`${column}`, `ov.${value}`)
@@ -296,13 +317,48 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
296317
return this
297318
}
298319

320+
/** @deprecated Use `overlaps()` instead. */
321+
ov = this.overlaps
322+
323+
/**
324+
* Finds all rows whose text or tsvector value on the stated `column` matches
325+
* the tsquery in `query`.
326+
*
327+
* @param column The column to filter on.
328+
* @param query The Postgres tsquery string to filter with.
329+
* @param config The text search configuration to use.
330+
* @param type The type of tsquery conversion to use on `query`.
331+
*/
332+
textSearch(
333+
column: keyof T,
334+
query: string,
335+
{
336+
config,
337+
type = null,
338+
}: { config?: string; type?: 'plain' | 'phrase' | 'websearch' | null } = {}
339+
): this {
340+
let typePart = ''
341+
if (type === 'plain') {
342+
typePart = 'pl'
343+
} else if (type === 'phrase') {
344+
typePart = 'ph'
345+
} else if (type === 'websearch') {
346+
typePart = 'w'
347+
}
348+
const configPart = config === undefined ? '' : `(${config})`
349+
this.url.searchParams.append(`${column}`, `${typePart}fts${configPart}.${query}`)
350+
return this
351+
}
352+
299353
/**
300354
* Finds all rows whose tsvector value on the stated `column` matches
301355
* to_tsquery(`query`).
302356
*
303357
* @param column The column to filter on.
304358
* @param query The Postgres tsquery string to filter with.
305359
* @param config The text search configuration to use.
360+
*
361+
* @deprecated Use `textSearch()` instead.
306362
*/
307363
fts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
308364
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -317,6 +373,8 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
317373
* @param column The column to filter on.
318374
* @param query The Postgres tsquery string to filter with.
319375
* @param config The text search configuration to use.
376+
*
377+
* @deprecated Use `textSearch()` with `type: 'plain'` instead.
320378
*/
321379
plfts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
322380
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -331,6 +389,8 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
331389
* @param column The column to filter on.
332390
* @param query The Postgres tsquery string to filter with.
333391
* @param config The text search configuration to use.
392+
*
393+
* @deprecated Use `textSearch()` with `type: 'phrase'` instead.
334394
*/
335395
phfts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
336396
const configPart = typeof config === 'undefined' ? '' : `(${config})`
@@ -345,6 +405,8 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
345405
* @param column The column to filter on.
346406
* @param query The Postgres tsquery string to filter with.
347407
* @param config The text search configuration to use.
408+
*
409+
* @deprecated Use `textSearch()` with `type: 'websearch'` instead.
348410
*/
349411
wfts(column: keyof T, query: string, { config }: { config?: string } = {}): this {
350412
const configPart = typeof config === 'undefined' ? '' : `(${config})`

0 commit comments

Comments
 (0)