@@ -5,6 +5,30 @@ import { PostgrestBuilder, PostgrestSingleResponse } from './types'
55 */
66
77export 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+
832 /**
933 * Orders the result with the specified `column`.
1034 *
@@ -20,7 +44,7 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
2044 nullsFirst = false ,
2145 foreignTable,
2246 } : { ascending ?: boolean ; nullsFirst ?: boolean ; foreignTable ?: string } = { }
23- ) : PostgrestTransformBuilder < T > {
47+ ) : this {
2448 const key = typeof foreignTable === 'undefined' ? 'order' : `"${ foreignTable } ".order`
2549 this . url . searchParams . set (
2650 key ,
@@ -38,7 +62,7 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
3862 limit (
3963 count : number ,
4064 { foreignTable } : { foreignTable ?: string } = { }
41- ) : PostgrestTransformBuilder < T > {
65+ ) : this {
4266 const key = typeof foreignTable === 'undefined' ? 'limit' : `"${ foreignTable } ".limit`
4367 this . url . searchParams . set ( key , `${ count } ` )
4468 return this
@@ -55,7 +79,7 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
5579 from : number ,
5680 to : number ,
5781 { foreignTable } : { foreignTable ?: string } = { }
58- ) : PostgrestTransformBuilder < T > {
82+ ) : this {
5983 const keyOffset = typeof foreignTable === 'undefined' ? 'offset' : `"${ foreignTable } ".offset`
6084 const keyLimit = typeof foreignTable === 'undefined' ? 'limit' : `"${ foreignTable } ".limit`
6185 this . url . searchParams . set ( keyOffset , `${ from } ` )
0 commit comments