@@ -5,6 +5,30 @@ import { PostgrestBuilder, PostgrestSingleResponse } from './types'
5
5
*/
6
6
7
7
export default class PostgrestTransformBuilder < T > extends PostgrestBuilder < T > {
8
+ /**
9
+ * Performs vertical filtering with SELECT.
10
+ *
11
+ * @param columns The columns to retrieve, separated by commas.
12
+ */
13
+ select ( columns = '*' ) : this {
14
+ // Remove whitespaces except when quoted
15
+ let quoted = false
16
+ const cleanedColumns = columns
17
+ . split ( '' )
18
+ . map ( ( c ) => {
19
+ if ( / \s / . test ( c ) && ! quoted ) {
20
+ return ''
21
+ }
22
+ if ( c === '"' ) {
23
+ quoted = ! quoted
24
+ }
25
+ return c
26
+ } )
27
+ . join ( '' )
28
+ this . url . searchParams . set ( 'select' , cleanedColumns )
29
+ return this
30
+ }
31
+
8
32
/**
9
33
* Orders the result with the specified `column`.
10
34
*
@@ -20,7 +44,7 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
20
44
nullsFirst = false ,
21
45
foreignTable,
22
46
} : { ascending ?: boolean ; nullsFirst ?: boolean ; foreignTable ?: string } = { }
23
- ) : PostgrestTransformBuilder < T > {
47
+ ) : this {
24
48
const key = typeof foreignTable === 'undefined' ? 'order' : `"${ foreignTable } ".order`
25
49
this . url . searchParams . set (
26
50
key ,
@@ -38,7 +62,7 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
38
62
limit (
39
63
count : number ,
40
64
{ foreignTable } : { foreignTable ?: string } = { }
41
- ) : PostgrestTransformBuilder < T > {
65
+ ) : this {
42
66
const key = typeof foreignTable === 'undefined' ? 'limit' : `"${ foreignTable } ".limit`
43
67
this . url . searchParams . set ( key , `${ count } ` )
44
68
return this
@@ -55,7 +79,7 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
55
79
from : number ,
56
80
to : number ,
57
81
{ foreignTable } : { foreignTable ?: string } = { }
58
- ) : PostgrestTransformBuilder < T > {
82
+ ) : this {
59
83
const keyOffset = typeof foreignTable === 'undefined' ? 'offset' : `"${ foreignTable } ".offset`
60
84
const keyLimit = typeof foreignTable === 'undefined' ? 'limit' : `"${ foreignTable } ".limit`
61
85
this . url . searchParams . set ( keyOffset , `${ from } ` )
0 commit comments