@@ -576,3 +576,53 @@ def range(
576
576
end - start + 1 ,
577
577
)
578
578
return self
579
+
580
+
581
+ class BaseRPCRequestBuilder (BaseSelectRequestBuilder [_ReturnT ]):
582
+ def __init__ (
583
+ self ,
584
+ session : Union [AsyncClient , SyncClient ],
585
+ headers : Headers ,
586
+ params : QueryParams ,
587
+ ) -> None :
588
+ # Generic[T] is an instance of typing._GenericAlias, so doing Generic[T].__init__
589
+ # tries to call _GenericAlias.__init__ - which is the wrong method
590
+ # The __origin__ attribute of the _GenericAlias is the actual class
591
+ get_origin_and_cast (BaseSelectRequestBuilder [_ReturnT ]).__init__ (
592
+ self , session , headers , params
593
+ )
594
+
595
+ def select (
596
+ self ,
597
+ * columns : str ,
598
+ ) -> Self :
599
+ """Run a SELECT query.
600
+
601
+ Args:
602
+ *columns: The names of the columns to fetch.
603
+ Returns:
604
+ :class:`BaseSelectRequestBuilder`
605
+ """
606
+ method , params , headers , json = pre_select (* columns , count = None )
607
+ self .params = self .params .add ("select" , params .get ("select" ))
608
+ self .headers ["Prefer" ] = "return=representation"
609
+ return self
610
+
611
+ def single (self ) -> Self :
612
+ """Specify that the query will only return a single row in response.
613
+
614
+ .. caution::
615
+ The API will raise an error if the query returned more than one row.
616
+ """
617
+ self .headers ["Accept" ] = "application/vnd.pgrst.object+json"
618
+ return self
619
+
620
+ def maybe_single (self ) -> Self :
621
+ """Retrieves at most one row from the result. Result must be at most one row (e.g. using `eq` on a UNIQUE column), otherwise this will result in an error."""
622
+ self .headers ["Accept" ] = "application/vnd.pgrst.object+json"
623
+ return self
624
+
625
+ def csv (self ) -> Self :
626
+ """Specify that the query must retrieve data as a single CSV string."""
627
+ self .headers ["Accept" ] = "text/csv"
628
+ return self
0 commit comments