From e6a46becd49399ba06490cebb8758db1bdc615ee Mon Sep 17 00:00:00 2001 From: Bobbie Soedirgo Date: Thu, 11 Mar 2021 14:49:59 +0800 Subject: [PATCH 1/5] style: fix formatting --- src/lib/PostgrestQueryBuilder.ts | 4 ++-- test/basic.ts | 2 +- test/resource-embedding.ts | 10 ++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/PostgrestQueryBuilder.ts b/src/lib/PostgrestQueryBuilder.ts index bde273dd..986c4732 100644 --- a/src/lib/PostgrestQueryBuilder.ts +++ b/src/lib/PostgrestQueryBuilder.ts @@ -87,9 +87,9 @@ export default class PostgrestQueryBuilder extends PostgrestBuilder { if (count) { prefersHeaders.push(`count=${count}`) } - + this.headers['Prefer'] = prefersHeaders.join(',') - + return new PostgrestFilterBuilder(this) } diff --git a/test/basic.ts b/test/basic.ts index 6579e26b..acf39395 100644 --- a/test/basic.ts +++ b/test/basic.ts @@ -176,7 +176,7 @@ test('select with count:exact', async () => { }) test("stored procedure with count: 'exact'", async () => { - const res = await postgrest.rpc('get_status', { name_param: 'supabot'}, {count: 'exact' }) + const res = await postgrest.rpc('get_status', { name_param: 'supabot' }, { count: 'exact' }) expect(res).toMatchSnapshot() }) diff --git a/test/resource-embedding.ts b/test/resource-embedding.ts index 7f6e5387..473f0738 100644 --- a/test/resource-embedding.ts +++ b/test/resource-embedding.ts @@ -24,7 +24,9 @@ describe('embedded filters', () => { const res = await postgrest .from('users') .select('messages(*)') - .or('channel_id.eq.2,and(message.eq.Hello World 👋,username.eq.supabot)', { foreignTable: 'messages' }) + .or('channel_id.eq.2,and(message.eq.Hello World 👋,username.eq.supabot)', { + foreignTable: 'messages', + }) expect(res).toMatchSnapshot() }) }) @@ -38,14 +40,14 @@ describe('embedded transforms', () => { expect(res).toMatchSnapshot() }) -test('embedded order on multiple columns', async () => { + test('embedded order on multiple columns', async () => { const res = await postgrest .from('users') .select('messages(*)') .order('channel_id', { foreignTable: 'messages', ascending: false }) .order('username', { foreignTable: 'messages', ascending: false }) - expect(res).toMatchSnapshot() -}) + expect(res).toMatchSnapshot() + }) test('embedded limit', async () => { const res = await postgrest From ccdb5dfc79d36677d9bfd82da31961b15de09152 Mon Sep 17 00:00:00 2001 From: Bobbie Soedirgo Date: Thu, 11 Mar 2021 14:50:17 +0800 Subject: [PATCH 2/5] feat: rename filters --- src/lib/PostgrestFilterBuilder.ts | 82 +++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 10 deletions(-) diff --git a/src/lib/PostgrestFilterBuilder.ts b/src/lib/PostgrestFilterBuilder.ts index 08e32954..3ba78047 100644 --- a/src/lib/PostgrestFilterBuilder.ts +++ b/src/lib/PostgrestFilterBuilder.ts @@ -182,7 +182,7 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param value The value to filter with. */ - cs(column: keyof T, value: string | T[keyof T][] | object): this { + contains(column: keyof T, value: string | T[keyof T][] | object): this { if (typeof value === 'string') { // range types can be inclusive '[', ']' or exclusive '(', ')' so just // keep it simple and accept a string @@ -197,6 +197,9 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder return this } + /** @deprecated Use `contains()` instead. */ + cs = this.contains + /** * Finds all rows whose json, array, or range value on the stated `column` is * contained by the specified `value`. @@ -204,7 +207,7 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param value The value to filter with. */ - cd(column: keyof T, value: string | T[keyof T][] | object): this { + containedBy(column: keyof T, value: string | T[keyof T][] | object): this { if (typeof value === 'string') { // range this.url.searchParams.append(`${column}`, `cd.${value}`) @@ -218,6 +221,9 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder return this } + /** @deprecated Use `containedBy()` instead. */ + cd = this.containedBy + /** * Finds all rows whose range value on the stated `column` is strictly to the * left of the specified `range`. @@ -225,11 +231,14 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param range The range to filter with. */ - sl(column: keyof T, range: string): this { + rangeLt(column: keyof T, range: string): this { this.url.searchParams.append(`${column}`, `sl.${range}`) return this } + /** @deprecated Use `rangeLt()` instead. */ + sl = this.rangeLt + /** * Finds all rows whose range value on the stated `column` is strictly to * the right of the specified `range`. @@ -237,11 +246,14 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param range The range to filter with. */ - sr(column: keyof T, range: string): this { + rangeGt(column: keyof T, range: string): this { this.url.searchParams.append(`${column}`, `sr.${range}`) return this } + /** @deprecated Use `rangeGt()` instead. */ + sr = this.rangeGt + /** * Finds all rows whose range value on the stated `column` does not extend * to the left of the specified `range`. @@ -249,11 +261,14 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param range The range to filter with. */ - nxl(column: keyof T, range: string): this { + rangeGte(column: keyof T, range: string): this { this.url.searchParams.append(`${column}`, `nxl.${range}`) return this } + /** @deprecated Use `rangeGte()` instead. */ + nxl = this.rangeGte + /** * Finds all rows whose range value on the stated `column` does not extend * to the right of the specified `range`. @@ -261,11 +276,14 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param range The range to filter with. */ - nxr(column: keyof T, range: string): this { + rangeLte(column: keyof T, range: string): this { this.url.searchParams.append(`${column}`, `nxr.${range}`) return this } + /** @deprecated Use `rangeLte()` instead. */ + nxr = this.rangeLte + /** * Finds all rows whose range value on the stated `column` is adjacent to * the specified `range`. @@ -273,19 +291,22 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param range The range to filter with. */ - adj(column: keyof T, range: string): this { + adjacent(column: keyof T, range: string): this { this.url.searchParams.append(`${column}`, `adj.${range}`) return this } + /** @deprecated Use `adjacent()` instead. */ + adj = this.adjacent + /** - * Finds all rows whose array or range value on the stated `column` is - * contained by the specified `value`. + * Finds all rows whose array or range value on the stated `column` overlaps + * (has a value in common) with the specified `value`. * * @param column The column to filter on. * @param value The value to filter with. */ - ov(column: keyof T, value: string | T[keyof T][]): this { + overlaps(column: keyof T, value: string | T[keyof T][]): this { if (typeof value === 'string') { // range this.url.searchParams.append(`${column}`, `ov.${value}`) @@ -296,6 +317,39 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder return this } + /** @deprecated Use `overlaps()` instead. */ + ov = this.overlaps + + /** + * Finds all rows whose text or tsvector value on the stated `column` matches + * the tsquery in `query`. + * + * @param column The column to filter on. + * @param query The Postgres tsquery string to filter with. + * @param config The text search configuration to use. + * @param type The type of tsquery conversion to use on `query`. + */ + textSearch( + column: keyof T, + query: string, + { + config, + type = null, + }: { config?: string; type?: 'plain' | 'phrase' | 'websearch' | null } = {} + ): this { + let typePart = '' + if (type === 'plain') { + typePart = 'pl' + } else if (type === 'phrase') { + typePart = 'ph' + } else if (type === 'websearch') { + typePart = 'w' + } + const configPart = config === undefined ? '' : `(${config})` + this.url.searchParams.append(`${column}`, `${typePart}fts${configPart}.${query}`) + return this + } + /** * Finds all rows whose tsvector value on the stated `column` matches * to_tsquery(`query`). @@ -303,6 +357,8 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param query The Postgres tsquery string to filter with. * @param config The text search configuration to use. + * + * @deprecated Use `textSearch()` instead. */ fts(column: keyof T, query: string, { config }: { config?: string } = {}): this { const configPart = typeof config === 'undefined' ? '' : `(${config})` @@ -317,6 +373,8 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param query The Postgres tsquery string to filter with. * @param config The text search configuration to use. + * + * @deprecated Use `textSearch()` with `type: 'plain'` instead. */ plfts(column: keyof T, query: string, { config }: { config?: string } = {}): this { const configPart = typeof config === 'undefined' ? '' : `(${config})` @@ -331,6 +389,8 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param query The Postgres tsquery string to filter with. * @param config The text search configuration to use. + * + * @deprecated Use `textSearch()` with `type: 'phrase'` instead. */ phfts(column: keyof T, query: string, { config }: { config?: string } = {}): this { const configPart = typeof config === 'undefined' ? '' : `(${config})` @@ -345,6 +405,8 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param query The Postgres tsquery string to filter with. * @param config The text search configuration to use. + * + * @deprecated Use `textSearch()` with `type: 'websearch'` instead. */ wfts(column: keyof T, query: string, { config }: { config?: string } = {}): this { const configPart = typeof config === 'undefined' ? '' : `(${config})` From 1762de2d6a35c6c9921a43852cafb3f8ce87b9f7 Mon Sep 17 00:00:00 2001 From: Bobbie Soedirgo Date: Thu, 11 Mar 2021 14:50:26 +0800 Subject: [PATCH 3/5] test: update filter names & snapshots --- test/__snapshots__/index.test.ts.snap | 408 +++++++++++++------------- test/filters.ts | 52 ++-- 2 files changed, 230 insertions(+), 230 deletions(-) diff --git a/test/__snapshots__/index.test.ts.snap b/test/__snapshots__/index.test.ts.snap index ec6fff79..e7ad23e3 100644 --- a/test/__snapshots__/index.test.ts.snap +++ b/test/__snapshots__/index.test.ts.snap @@ -2,7 +2,7 @@ exports[`Prefer: return=minimal 1`] = `null`; -exports[`adj 1`] = ` +exports[`adjacent 1`] = ` Object { "body": Array [ Object { @@ -681,7 +681,7 @@ Object { } `; -exports[`cd 1`] = ` +exports[`containedBy 1`] = ` Object { "body": Array [ Object { @@ -708,7 +708,7 @@ Object { } `; -exports[`cs 1`] = ` +exports[`contains 1`] = ` Object { "body": Array [ Object { @@ -1285,33 +1285,6 @@ Object { } `; -exports[`fts 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - exports[`gt 1`] = ` Object { "body": Array [ @@ -2439,88 +2412,6 @@ Object { } `; -exports[`nxl 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`nxr 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - exports[`on_conflict insert 1`] = ` Object { "body": Array [ @@ -2699,7 +2590,7 @@ Object { } `; -exports[`ov 1`] = ` +exports[`overlaps 1`] = ` Object { "body": Array [ Object { @@ -2726,16 +2617,9 @@ Object { } `; -exports[`phfts 1`] = ` +exports[`range 1`] = ` Object { "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, Object { "age_range": "[25,35)", "catchphrase": "'bat' 'cat'", @@ -2743,16 +2627,23 @@ Object { "status": "OFFLINE", "username": "kiwicopple", }, - ], - "count": null, - "data": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "age_range": "[25,35)", + "catchphrase": "'bat' 'rat'", "data": null, "status": "ONLINE", - "username": "supabot", + "username": "awailas", + }, + Object { + "age_range": "[20,30)", + "catchphrase": "'fat' 'rat'", + "data": null, + "status": "ONLINE", + "username": "dragarcia", }, + ], + "count": null, + "data": Array [ Object { "age_range": "[25,35)", "catchphrase": "'bat' 'cat'", @@ -2760,6 +2651,20 @@ Object { "status": "OFFLINE", "username": "kiwicopple", }, + Object { + "age_range": "[25,35)", + "catchphrase": "'bat' 'rat'", + "data": null, + "status": "ONLINE", + "username": "awailas", + }, + Object { + "age_range": "[20,30)", + "catchphrase": "'fat' 'rat'", + "data": null, + "status": "ONLINE", + "username": "dragarcia", + }, ], "error": null, "status": 200, @@ -2767,25 +2672,39 @@ Object { } `; -exports[`plfts 1`] = ` +exports[`rangeGt 1`] = ` Object { "body": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "age_range": "[25,35)", + "catchphrase": "'bat' 'cat'", + "data": null, + "status": "OFFLINE", + "username": "kiwicopple", + }, + Object { + "age_range": "[25,35)", + "catchphrase": "'bat' 'rat'", "data": null, "status": "ONLINE", - "username": "supabot", + "username": "awailas", }, ], "count": null, "data": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "age_range": "[25,35)", + "catchphrase": "'bat' 'cat'", + "data": null, + "status": "OFFLINE", + "username": "kiwicopple", + }, + Object { + "age_range": "[25,35)", + "catchphrase": "'bat' 'rat'", "data": null, "status": "ONLINE", - "username": "supabot", + "username": "awailas", }, ], "error": null, @@ -2794,7 +2713,7 @@ Object { } `; -exports[`range 1`] = ` +exports[`rangeGte 1`] = ` Object { "body": Array [ Object { @@ -2849,6 +2768,60 @@ Object { } `; +exports[`rangeLt 1`] = ` +Object { + "body": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", +} +`; + +exports[`rangeLte 1`] = ` +Object { + "body": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", +} +`; + exports[`select on insert 1`] = ` Object { "body": Array [ @@ -3046,74 +3019,6 @@ Object { } `; -exports[`sl 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`sr 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - exports[`stored procedure 1`] = ` Object { "body": "ONLINE", @@ -3220,7 +3125,102 @@ Object { } `; -exports[`wfts 1`] = ` +exports[`textSearch 1`] = ` +Object { + "body": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", +} +`; + +exports[`textSearch with phraseto_tsquery 1`] = ` +Object { + "body": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + Object { + "age_range": "[25,35)", + "catchphrase": "'bat' 'cat'", + "data": null, + "status": "OFFLINE", + "username": "kiwicopple", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + Object { + "age_range": "[25,35)", + "catchphrase": "'bat' 'cat'", + "data": null, + "status": "OFFLINE", + "username": "kiwicopple", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", +} +`; + +exports[`textSearch with plainto_tsquery 1`] = ` +Object { + "body": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", +} +`; + +exports[`textSearch with websearch_to_tsquery 1`] = ` Object { "body": Array [ Object { diff --git a/test/filters.ts b/test/filters.ts index 0817b50d..c89050dc 100644 --- a/test/filters.ts +++ b/test/filters.ts @@ -62,75 +62,75 @@ test('in', async () => { expect(res).toMatchSnapshot() }) -test('cs', async () => { - const res = await postgrest.from('users').select().cs('age_range', '[1,2)') +test('contains', async () => { + const res = await postgrest.from('users').select().contains('age_range', '[1,2)') expect(res).toMatchSnapshot() }) -test('cd', async () => { - const res = await postgrest.from('users').select().cd('age_range', '[1,2)') +test('containedBy', async () => { + const res = await postgrest.from('users').select().containedBy('age_range', '[1,2)') expect(res).toMatchSnapshot() }) -test('sl', async () => { - const res = await postgrest.from('users').select().sl('age_range', '[2,25)') +test('rangeLt', async () => { + const res = await postgrest.from('users').select().rangeLt('age_range', '[2,25)') expect(res).toMatchSnapshot() }) -test('sr', async () => { - const res = await postgrest.from('users').select().sr('age_range', '[2,25)') +test('rangeGt', async () => { + const res = await postgrest.from('users').select().rangeGt('age_range', '[2,25)') expect(res).toMatchSnapshot() }) -test('nxl', async () => { - const res = await postgrest.from('users').select().nxl('age_range', '[2,25)') +test('rangeGte', async () => { + const res = await postgrest.from('users').select().rangeGte('age_range', '[2,25)') expect(res).toMatchSnapshot() }) -test('nxr', async () => { - const res = await postgrest.from('users').select().nxr('age_range', '[2,25)') +test('rangeLte', async () => { + const res = await postgrest.from('users').select().rangeLte('age_range', '[2,25)') expect(res).toMatchSnapshot() }) -test('adj', async () => { - const res = await postgrest.from('users').select().adj('age_range', '[2,25)') +test('adjacent', async () => { + const res = await postgrest.from('users').select().adjacent('age_range', '[2,25)') expect(res).toMatchSnapshot() }) -test('ov', async () => { - const res = await postgrest.from('users').select().ov('age_range', '[2,25)') +test('overlaps', async () => { + const res = await postgrest.from('users').select().overlaps('age_range', '[2,25)') expect(res).toMatchSnapshot() }) -test('fts', async () => { +test('textSearch', async () => { const res = await postgrest .from('users') .select() - .fts('catchphrase', `'fat' & 'cat'`, { config: 'english' }) + .textSearch('catchphrase', `'fat' & 'cat'`, { config: 'english' }) expect(res).toMatchSnapshot() }) -test('plfts', async () => { +test('textSearch with plainto_tsquery', async () => { const res = await postgrest .from('users') .select() - .plfts('catchphrase', `'fat' & 'cat'`, { config: 'english' }) + .textSearch('catchphrase', `'fat' & 'cat'`, { config: 'english', type: 'plain' }) expect(res).toMatchSnapshot() }) -test('phfts', async () => { +test('textSearch with phraseto_tsquery', async () => { const res = await postgrest .from('users') .select() - .phfts('catchphrase', 'cat', { config: 'english' }) + .textSearch('catchphrase', 'cat', { config: 'english', type: 'phrase' }) expect(res).toMatchSnapshot() }) -test('wfts', async () => { +test('textSearch with websearch_to_tsquery', async () => { const res = await postgrest .from('users') .select() - .wfts('catchphrase', `'fat' & 'cat'`, { config: 'english' }) + .textSearch('catchphrase', `'fat' & 'cat'`, { config: 'english', type: 'websearch' }) expect(res).toMatchSnapshot() }) @@ -140,9 +140,9 @@ test('multiple filters', async () => { .select() .eq('username', 'supabot') .is('data', null) - .ov('age_range', '[1,2)') + .overlaps('age_range', '[1,2)') .eq('status', 'ONLINE') - .fts('catchphrase', 'cat') + .textSearch('catchphrase', 'cat') expect(res).toMatchSnapshot() }) From 1be1e307e6bfba79c1a1409415eaee2fbe9d4ba5 Mon Sep 17 00:00:00 2001 From: Paul Copplestone Date: Thu, 11 Mar 2021 15:55:45 +0800 Subject: [PATCH 4/5] Inlines the filter snapshots to make it easier to read --- package-lock.json | 17 +- test/__snapshots__/index.test.ts.snap | 1261 +++---------------------- test/filters.ts | 691 ++++++++++++-- 3 files changed, 784 insertions(+), 1185 deletions(-) diff --git a/package-lock.json b/package-lock.json index f5088bcd..aef5f729 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2213,7 +2213,8 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=", - "dev": true + "dev": true, + "optional": true }, "handlebars": { "version": "4.7.6", @@ -2602,6 +2603,7 @@ "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", "dev": true, + "optional": true, "requires": { "is-docker": "^2.0.0" } @@ -3840,6 +3842,7 @@ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", "dev": true, + "optional": true, "requires": { "yallist": "^4.0.0" } @@ -4053,6 +4056,7 @@ "resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-8.0.1.tgz", "integrity": "sha512-BvEXF+UmsnAfYfoapKM9nGxnP+Wn7P91YfXmrKnfcYCx6VBeoN5Ez5Ogck6I8Bi5k4RlpqRYaw75pAwzX9OphA==", "dev": true, + "optional": true, "requires": { "growly": "^1.3.0", "is-wsl": "^2.2.0", @@ -4067,6 +4071,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", "dev": true, + "optional": true, "requires": { "lru-cache": "^6.0.0" } @@ -4076,6 +4081,7 @@ "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, + "optional": true, "requires": { "isexe": "^2.0.0" } @@ -4997,7 +5003,8 @@ "version": "0.1.1", "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==", - "dev": true + "dev": true, + "optional": true }, "signal-exit": { "version": "3.0.3", @@ -5721,7 +5728,8 @@ "version": "8.3.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.1.tgz", "integrity": "sha512-FOmRr+FmWEIG8uhZv6C2bTgEVXsHk08kE7mPlrBbEe+c3r9pjceVPgupIfNIhc4yx55H69OXANrUaSuu9eInKg==", - "dev": true + "dev": true, + "optional": true }, "v8-to-istanbul": { "version": "6.0.1", @@ -5906,7 +5914,8 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "dev": true, + "optional": true }, "yargs": { "version": "15.4.1", diff --git a/test/__snapshots__/index.test.ts.snap b/test/__snapshots__/index.test.ts.snap index e7ad23e3..6a71bf56 100644 --- a/test/__snapshots__/index.test.ts.snap +++ b/test/__snapshots__/index.test.ts.snap @@ -2,61 +2,6 @@ exports[`Prefer: return=minimal 1`] = `null`; -exports[`adjacent 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - exports[`allow ordering on JSON column 1`] = ` Array [ Object { @@ -681,60 +626,6 @@ Object { } `; -exports[`containedBy 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`contains 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - exports[`don't mutate PostgrestClient.headers 1`] = `null`; exports[`embedded filters embedded eq 1`] = ` @@ -1231,78 +1122,66 @@ Object { } `; -exports[`eq 1`] = ` +exports[`insert, update, delete with count: 'exact' basic delete count: 'exact' 1`] = ` Object { "body": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "channel_id": 2, "data": null, - "status": "ONLINE", + "id": 6, + "message": "foo", "username": "supabot", }, - ], - "count": null, - "data": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "channel_id": 2, "data": null, - "status": "ONLINE", + "id": 3, + "message": "foo", "username": "supabot", }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`filter 1`] = ` -Object { - "body": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "channel_id": 2, "data": null, - "status": "ONLINE", + "id": 7, + "message": "foo", + "username": "supabot", + }, + Object { + "channel_id": 2, + "data": null, + "id": 8, + "message": "foo", "username": "supabot", }, ], - "count": null, + "count": 4, "data": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "channel_id": 2, "data": null, - "status": "ONLINE", + "id": 6, + "message": "foo", "username": "supabot", }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`gt 1`] = ` -Object { - "body": Array [ Object { "channel_id": 2, "data": null, - "id": 2, - "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", + "id": 3, + "message": "foo", "username": "supabot", }, - ], - "count": null, - "data": Array [ Object { "channel_id": 2, "data": null, - "id": 2, - "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", + "id": 7, + "message": "foo", + "username": "supabot", + }, + Object { + "channel_id": 2, + "data": null, + "id": 8, + "message": "foo", "username": "supabot", }, ], @@ -1312,7 +1191,7 @@ Object { } `; -exports[`gte 1`] = ` +exports[`insert, update, delete with count: 'exact' basic delete count: 'exact' 2`] = ` Object { "body": Array [ Object { @@ -1353,293 +1232,87 @@ Object { } `; -exports[`ilike 1`] = ` +exports[`insert, update, delete with count: 'exact' bulk insert with count: 'exact' 1`] = ` Object { "body": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "channel_id": 1, "data": null, - "status": "ONLINE", + "id": 7, + "message": "foo", + "username": "supabot", + }, + Object { + "channel_id": 1, + "data": null, + "id": 8, + "message": "foo", "username": "supabot", }, ], - "count": null, + "count": 2, "data": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "channel_id": 1, "data": null, - "status": "ONLINE", + "id": 7, + "message": "foo", + "username": "supabot", + }, + Object { + "channel_id": 1, + "data": null, + "id": 8, + "message": "foo", "username": "supabot", }, ], "error": null, - "status": 200, - "statusText": "OK", + "status": 201, + "statusText": "Created", } `; -exports[`in 1`] = ` +exports[`insert, update, delete with count: 'exact' bulk insert with count: 'exact' 2`] = ` Object { "body": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "channel_id": 1, "data": null, - "status": "ONLINE", + "id": 1, + "message": "Hello World 👋", "username": "supabot", }, Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", + "channel_id": 2, "data": null, - "status": "OFFLINE", - "username": "kiwicopple", + "id": 2, + "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", + "username": "supabot", }, Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", + "channel_id": 1, "data": null, - "status": "ONLINE", - "username": "awailas", + "id": 6, + "message": "foo", + "username": "supabot", }, Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", + "channel_id": 2, "data": null, - "status": "ONLINE", - "username": "dragarcia", + "id": 3, + "message": "foo", + "username": "supabot", }, - ], - "count": null, - "data": Array [ Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", + "channel_id": 1, "data": null, - "status": "ONLINE", + "id": 7, + "message": "foo", "username": "supabot", }, Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`insert, update, delete with count: 'exact' basic delete count: 'exact' 1`] = ` -Object { - "body": Array [ - Object { - "channel_id": 2, - "data": null, - "id": 6, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 3, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 7, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 8, - "message": "foo", - "username": "supabot", - }, - ], - "count": 4, - "data": Array [ - Object { - "channel_id": 2, - "data": null, - "id": 6, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 3, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 7, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 8, - "message": "foo", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`insert, update, delete with count: 'exact' basic delete count: 'exact' 2`] = ` -Object { - "body": Array [ - Object { - "channel_id": 1, - "data": null, - "id": 1, - "message": "Hello World 👋", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 2, - "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "channel_id": 1, - "data": null, - "id": 1, - "message": "Hello World 👋", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 2, - "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`insert, update, delete with count: 'exact' bulk insert with count: 'exact' 1`] = ` -Object { - "body": Array [ - Object { - "channel_id": 1, - "data": null, - "id": 7, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 1, - "data": null, - "id": 8, - "message": "foo", - "username": "supabot", - }, - ], - "count": 2, - "data": Array [ - Object { - "channel_id": 1, - "data": null, - "id": 7, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 1, - "data": null, - "id": 8, - "message": "foo", - "username": "supabot", - }, - ], - "error": null, - "status": 201, - "statusText": "Created", -} -`; - -exports[`insert, update, delete with count: 'exact' bulk insert with count: 'exact' 2`] = ` -Object { - "body": Array [ - Object { - "channel_id": 1, - "data": null, - "id": 1, - "message": "Hello World 👋", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 2, - "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", - "username": "supabot", - }, - Object { - "channel_id": 1, - "data": null, - "id": 6, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 3, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 1, - "data": null, - "id": 7, - "message": "foo", - "username": "supabot", - }, - Object { - "channel_id": 1, + "channel_id": 1, "data": null, "id": 8, "message": "foo", @@ -2041,198 +1714,7 @@ Object { } `; -exports[`is 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`like 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`limit 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`lt 1`] = ` -Object { - "body": Array [ - Object { - "channel_id": 1, - "data": null, - "id": 1, - "message": "Hello World 👋", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "channel_id": 1, - "data": null, - "id": 1, - "message": "Hello World 👋", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`lte 1`] = ` -Object { - "body": Array [ - Object { - "channel_id": 1, - "data": null, - "id": 1, - "message": "Hello World 👋", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 2, - "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "channel_id": 1, - "data": null, - "id": 1, - "message": "Hello World 👋", - "username": "supabot", - }, - Object { - "channel_id": 2, - "data": null, - "id": 2, - "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`match 1`] = ` +exports[`limit 1`] = ` Object { "body": Array [ Object { @@ -2265,332 +1747,17 @@ Object { "count": null, "data": null, "error": Object { - "code": "42P01", - "details": null, - "hint": null, - "message": "relation \\"public.missing_table\\" does not exist", - }, - "status": 404, - "statusText": "Not Found", -} -`; - -exports[`multiple filters 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`neq 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`not 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`on_conflict insert 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - ], - "error": null, - "status": 201, - "statusText": "Created", -} -`; - -exports[`or 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`order 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "dragarcia", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", - "data": null, - "status": "ONLINE", - "username": "awailas", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`order on multiple columns 1`] = ` -Object { - "body": Array [ - Object { - "channel_id": 2, - "data": null, - "id": 2, - "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", - "username": "supabot", - }, - Object { - "channel_id": 1, - "data": null, - "id": 1, - "message": "Hello World 👋", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "channel_id": 2, - "data": null, - "id": 2, - "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", - "username": "supabot", - }, - Object { - "channel_id": 1, - "data": null, - "id": 1, - "message": "Hello World 👋", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", + "code": "42P01", + "details": null, + "hint": null, + "message": "relation \\"public.missing_table\\" does not exist", + }, + "status": 404, + "statusText": "Not Found", } `; -exports[`overlaps 1`] = ` +exports[`on_conflict insert 1`] = ` Object { "body": Array [ Object { @@ -2612,14 +1779,21 @@ Object { }, ], "error": null, - "status": 200, - "statusText": "OK", + "status": 201, + "statusText": "Created", } `; -exports[`range 1`] = ` +exports[`order 1`] = ` Object { "body": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, Object { "age_range": "[25,35)", "catchphrase": "'bat' 'cat'", @@ -2628,22 +1802,29 @@ Object { "username": "kiwicopple", }, Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", + "age_range": "[20,30)", + "catchphrase": "'fat' 'rat'", "data": null, "status": "ONLINE", - "username": "awailas", + "username": "dragarcia", }, Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", + "age_range": "[25,35)", + "catchphrase": "'bat' 'rat'", "data": null, "status": "ONLINE", - "username": "dragarcia", + "username": "awailas", }, ], "count": null, "data": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, Object { "age_range": "[25,35)", "catchphrase": "'bat' 'cat'", @@ -2652,18 +1833,18 @@ Object { "username": "kiwicopple", }, Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", + "age_range": "[20,30)", + "catchphrase": "'fat' 'rat'", "data": null, "status": "ONLINE", - "username": "awailas", + "username": "dragarcia", }, Object { - "age_range": "[20,30)", - "catchphrase": "'fat' 'rat'", + "age_range": "[25,35)", + "catchphrase": "'bat' 'rat'", "data": null, "status": "ONLINE", - "username": "dragarcia", + "username": "awailas", }, ], "error": null, @@ -2672,39 +1853,39 @@ Object { } `; -exports[`rangeGt 1`] = ` +exports[`order on multiple columns 1`] = ` Object { "body": Array [ Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", + "channel_id": 2, "data": null, - "status": "OFFLINE", - "username": "kiwicopple", + "id": 2, + "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", + "username": "supabot", }, Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", + "channel_id": 1, "data": null, - "status": "ONLINE", - "username": "awailas", + "id": 1, + "message": "Hello World 👋", + "username": "supabot", }, ], "count": null, "data": Array [ Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", + "channel_id": 2, "data": null, - "status": "OFFLINE", - "username": "kiwicopple", + "id": 2, + "message": "Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.", + "username": "supabot", }, Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'rat'", + "channel_id": 1, "data": null, - "status": "ONLINE", - "username": "awailas", + "id": 1, + "message": "Hello World 👋", + "username": "supabot", }, ], "error": null, @@ -2713,7 +1894,7 @@ Object { } `; -exports[`rangeGte 1`] = ` +exports[`range 1`] = ` Object { "body": Array [ Object { @@ -2768,60 +1949,6 @@ Object { } `; -exports[`rangeLt 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`rangeLte 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - exports[`select on insert 1`] = ` Object { "body": Array [ @@ -3124,125 +2251,3 @@ Object { "statusText": "OK", } `; - -exports[`textSearch 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`textSearch with phraseto_tsquery 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - Object { - "age_range": "[25,35)", - "catchphrase": "'bat' 'cat'", - "data": null, - "status": "OFFLINE", - "username": "kiwicopple", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`textSearch with plainto_tsquery 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; - -exports[`textSearch with websearch_to_tsquery 1`] = ` -Object { - "body": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "count": null, - "data": Array [ - Object { - "age_range": "[1,2)", - "catchphrase": "'cat' 'fat'", - "data": null, - "status": "ONLINE", - "username": "supabot", - }, - ], - "error": null, - "status": 200, - "statusText": "OK", -} -`; diff --git a/test/filters.ts b/test/filters.ts index c89050dc..b69e0f08 100644 --- a/test/filters.ts +++ b/test/filters.ts @@ -3,135 +3,659 @@ import { PostgrestClient } from '../src/index' const postgrest = new PostgrestClient('http://localhost:3000') test('not', async () => { - const res = await postgrest.from('users').select().not('status', 'eq', 'OFFLINE') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('status').not('status', 'eq', 'OFFLINE') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "status": "ONLINE", + }, + Object { + "status": "ONLINE", + }, + Object { + "status": "ONLINE", + }, + ], + "count": null, + "data": Array [ + Object { + "status": "ONLINE", + }, + Object { + "status": "ONLINE", + }, + Object { + "status": "ONLINE", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('or', async () => { - const res = await postgrest.from('users').select().or('status.eq.OFFLINE,username.eq.supabot') - expect(res).toMatchSnapshot() + const res = await postgrest + .from('users') + .select('status, username') + .or('status.eq.OFFLINE,username.eq.supabot') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "status": "ONLINE", + "username": "supabot", + }, + Object { + "status": "OFFLINE", + "username": "kiwicopple", + }, + ], + "count": null, + "data": Array [ + Object { + "status": "ONLINE", + "username": "supabot", + }, + Object { + "status": "OFFLINE", + "username": "kiwicopple", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('eq', async () => { - const res = await postgrest.from('users').select().eq('username', 'supabot') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('username').eq('username', 'supabot') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "username": "supabot", + }, + ], + "count": null, + "data": Array [ + Object { + "username": "supabot", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('neq', async () => { - const res = await postgrest.from('users').select().neq('username', 'supabot') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('username').neq('username', 'supabot') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "username": "kiwicopple", + }, + Object { + "username": "awailas", + }, + Object { + "username": "dragarcia", + }, + ], + "count": null, + "data": Array [ + Object { + "username": "kiwicopple", + }, + Object { + "username": "awailas", + }, + Object { + "username": "dragarcia", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('gt', async () => { - const res = await postgrest.from('messages').select().gt('id', 1) - expect(res).toMatchSnapshot() + const res = await postgrest.from('messages').select('').gt('id', 1) + expect(res).toMatchInlineSnapshot(` + Object { + "body": null, + "count": null, + "data": null, + "error": Object { + "details": "unexpected end of input expecting field name (* or [a..z0..9_]) or \\"*\\"", + "message": "\\"failed to parse select parameter ()\\" (line 1, column 1)", + }, + "status": 400, + "statusText": "Bad Request", + } + `) }) test('gte', async () => { - const res = await postgrest.from('messages').select().gte('id', 1) - expect(res).toMatchSnapshot() + const res = await postgrest.from('messages').select('id').gte('id', 1) + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "id": 1, + }, + Object { + "id": 2, + }, + ], + "count": null, + "data": Array [ + Object { + "id": 1, + }, + Object { + "id": 2, + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('lt', async () => { - const res = await postgrest.from('messages').select().lt('id', 2) - expect(res).toMatchSnapshot() + const res = await postgrest.from('messages').select('id').lt('id', 2) + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "id": 1, + }, + ], + "count": null, + "data": Array [ + Object { + "id": 1, + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('lte', async () => { - const res = await postgrest.from('messages').select().lte('id', 2) - expect(res).toMatchSnapshot() + const res = await postgrest.from('messages').select('id').lte('id', 2) + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "id": 1, + }, + Object { + "id": 2, + }, + ], + "count": null, + "data": Array [ + Object { + "id": 1, + }, + Object { + "id": 2, + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('like', async () => { - const res = await postgrest.from('users').select().like('username', '%supa%') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('username').like('username', '%supa%') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "username": "supabot", + }, + ], + "count": null, + "data": Array [ + Object { + "username": "supabot", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('ilike', async () => { - const res = await postgrest.from('users').select().ilike('username', '%SUPA%') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('username').ilike('username', '%SUPA%') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "username": "supabot", + }, + ], + "count": null, + "data": Array [ + Object { + "username": "supabot", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('is', async () => { - const res = await postgrest.from('users').select().is('data', null) - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('data').is('data', null) + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "data": null, + }, + Object { + "data": null, + }, + Object { + "data": null, + }, + Object { + "data": null, + }, + ], + "count": null, + "data": Array [ + Object { + "data": null, + }, + Object { + "data": null, + }, + Object { + "data": null, + }, + Object { + "data": null, + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('in', async () => { - const res = await postgrest.from('users').select().in('status', ['ONLINE', 'OFFLINE']) - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('status').in('status', ['ONLINE', 'OFFLINE']) + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "status": "ONLINE", + }, + Object { + "status": "OFFLINE", + }, + Object { + "status": "ONLINE", + }, + Object { + "status": "ONLINE", + }, + ], + "count": null, + "data": Array [ + Object { + "status": "ONLINE", + }, + Object { + "status": "OFFLINE", + }, + Object { + "status": "ONLINE", + }, + Object { + "status": "ONLINE", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('contains', async () => { - const res = await postgrest.from('users').select().contains('age_range', '[1,2)') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('age_range').contains('age_range', '[1,2)') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "age_range": "[1,2)", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('containedBy', async () => { - const res = await postgrest.from('users').select().containedBy('age_range', '[1,2)') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('age_range').containedBy('age_range', '[1,2)') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "age_range": "[1,2)", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('rangeLt', async () => { - const res = await postgrest.from('users').select().rangeLt('age_range', '[2,25)') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('age_range').rangeLt('age_range', '[2,25)') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "age_range": "[1,2)", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('rangeGt', async () => { - const res = await postgrest.from('users').select().rangeGt('age_range', '[2,25)') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('age_range').rangeGt('age_range', '[2,25)') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "age_range": "[25,35)", + }, + Object { + "age_range": "[25,35)", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[25,35)", + }, + Object { + "age_range": "[25,35)", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('rangeGte', async () => { - const res = await postgrest.from('users').select().rangeGte('age_range', '[2,25)') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('age_range').rangeGte('age_range', '[2,25)') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "age_range": "[25,35)", + }, + Object { + "age_range": "[25,35)", + }, + Object { + "age_range": "[20,30)", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[25,35)", + }, + Object { + "age_range": "[25,35)", + }, + Object { + "age_range": "[20,30)", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('rangeLte', async () => { - const res = await postgrest.from('users').select().rangeLte('age_range', '[2,25)') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('age_range').rangeLte('age_range', '[2,25)') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "age_range": "[1,2)", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('adjacent', async () => { - const res = await postgrest.from('users').select().adjacent('age_range', '[2,25)') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('age_range').adjacent('age_range', '[2,25)') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "age_range": "[1,2)", + }, + Object { + "age_range": "[25,35)", + }, + Object { + "age_range": "[25,35)", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + }, + Object { + "age_range": "[25,35)", + }, + Object { + "age_range": "[25,35)", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('overlaps', async () => { - const res = await postgrest.from('users').select().overlaps('age_range', '[2,25)') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('age_range').overlaps('age_range', '[2,25)') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "age_range": "[20,30)", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[20,30)", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('textSearch', async () => { const res = await postgrest .from('users') - .select() + .select('catchphrase') .textSearch('catchphrase', `'fat' & 'cat'`, { config: 'english' }) - expect(res).toMatchSnapshot() + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "catchphrase": "'cat' 'fat'", + }, + ], + "count": null, + "data": Array [ + Object { + "catchphrase": "'cat' 'fat'", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('textSearch with plainto_tsquery', async () => { const res = await postgrest .from('users') - .select() + .select('catchphrase') .textSearch('catchphrase', `'fat' & 'cat'`, { config: 'english', type: 'plain' }) - expect(res).toMatchSnapshot() + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "catchphrase": "'cat' 'fat'", + }, + ], + "count": null, + "data": Array [ + Object { + "catchphrase": "'cat' 'fat'", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('textSearch with phraseto_tsquery', async () => { const res = await postgrest .from('users') - .select() + .select('catchphrase') .textSearch('catchphrase', 'cat', { config: 'english', type: 'phrase' }) - expect(res).toMatchSnapshot() + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "catchphrase": "'cat' 'fat'", + }, + Object { + "catchphrase": "'bat' 'cat'", + }, + ], + "count": null, + "data": Array [ + Object { + "catchphrase": "'cat' 'fat'", + }, + Object { + "catchphrase": "'bat' 'cat'", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('textSearch with websearch_to_tsquery', async () => { const res = await postgrest .from('users') - .select() + .select('catchphrase') .textSearch('catchphrase', `'fat' & 'cat'`, { config: 'english', type: 'websearch' }) - expect(res).toMatchSnapshot() + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "catchphrase": "'cat' 'fat'", + }, + ], + "count": null, + "data": Array [ + Object { + "catchphrase": "'cat' 'fat'", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('multiple filters', async () => { @@ -143,18 +667,79 @@ test('multiple filters', async () => { .overlaps('age_range', '[1,2)') .eq('status', 'ONLINE') .textSearch('catchphrase', 'cat') - expect(res).toMatchSnapshot() + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + ], + "count": null, + "data": Array [ + Object { + "age_range": "[1,2)", + "catchphrase": "'cat' 'fat'", + "data": null, + "status": "ONLINE", + "username": "supabot", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('filter', async () => { - const res = await postgrest.from('users').select().filter('username', 'eq', 'supabot') - expect(res).toMatchSnapshot() + const res = await postgrest.from('users').select('username').filter('username', 'eq', 'supabot') + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "username": "supabot", + }, + ], + "count": null, + "data": Array [ + Object { + "username": "supabot", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) test('match', async () => { const res = await postgrest .from('users') - .select() + .select('username, status') .match({ username: 'supabot', status: 'ONLINE' }) - expect(res).toMatchSnapshot() + expect(res).toMatchInlineSnapshot(` + Object { + "body": Array [ + Object { + "status": "ONLINE", + "username": "supabot", + }, + ], + "count": null, + "data": Array [ + Object { + "status": "ONLINE", + "username": "supabot", + }, + ], + "error": null, + "status": 200, + "statusText": "OK", + } + `) }) From 9ca784e0b7652bae8fda60c202bc0613f80a704e Mon Sep 17 00:00:00 2001 From: Bobbie Soedirgo Date: Sat, 13 Mar 2021 17:53:14 +0800 Subject: [PATCH 5/5] rename adjacent -> rangeAdjacent --- src/lib/PostgrestFilterBuilder.ts | 6 +++--- test/filters.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/PostgrestFilterBuilder.ts b/src/lib/PostgrestFilterBuilder.ts index 3ba78047..dc1595dc 100644 --- a/src/lib/PostgrestFilterBuilder.ts +++ b/src/lib/PostgrestFilterBuilder.ts @@ -291,13 +291,13 @@ export default class PostgrestFilterBuilder extends PostgrestTransformBuilder * @param column The column to filter on. * @param range The range to filter with. */ - adjacent(column: keyof T, range: string): this { + rangeAdjacent(column: keyof T, range: string): this { this.url.searchParams.append(`${column}`, `adj.${range}`) return this } - /** @deprecated Use `adjacent()` instead. */ - adj = this.adjacent + /** @deprecated Use `rangeAdjacent()` instead. */ + adj = this.rangeAdjacent /** * Finds all rows whose array or range value on the stated `column` overlaps diff --git a/test/filters.ts b/test/filters.ts index b69e0f08..6452deba 100644 --- a/test/filters.ts +++ b/test/filters.ts @@ -496,8 +496,8 @@ test('rangeLte', async () => { `) }) -test('adjacent', async () => { - const res = await postgrest.from('users').select('age_range').adjacent('age_range', '[2,25)') +test('rangeAdjacent', async () => { + const res = await postgrest.from('users').select('age_range').rangeAdjacent('age_range', '[2,25)') expect(res).toMatchInlineSnapshot(` Object { "body": Array [