1212use SimPod \ClickHouseClient \Client \Http \RequestOptions ;
1313use SimPod \ClickHouseClient \Exception \CannotInsert ;
1414use SimPod \ClickHouseClient \Exception \ServerError ;
15+ use SimPod \ClickHouseClient \Exception \UnsupportedValue ;
1516use SimPod \ClickHouseClient \Format \Format ;
1617use SimPod \ClickHouseClient \Output \Output ;
1718use SimPod \ClickHouseClient \Sql \Escaper ;
2324use function array_map ;
2425use function implode ;
2526use function is_int ;
27+ use function SimPod \ClickHouseClient \absurd ;
2628use function sprintf ;
2729
2830class PsrClickHouseClient implements ClickHouseClient
@@ -44,38 +46,43 @@ public function __construct(
4446
4547 public function executeQuery (string $ query , array $ settings = []): void
4648 {
47- $ this ->executeRequest ($ query , $ settings );
49+ $ this ->executeRequest ($ query , settings: $ settings );
4850 }
4951
5052 public function executeQueryWithParams (string $ query , array $ params , array $ settings = []): void
5153 {
52- $ this ->executeQuery ($ this ->sqlFactory ->createWithParameters ($ query , $ params ), $ settings );
54+ $ this ->executeRequest (
55+ $ this ->sqlFactory ->createWithParameters ($ query , $ params ),
56+ settings: $ settings ,
57+ );
5358 }
5459
5560 public function select (string $ query , Format $ outputFormat , array $ settings = []): Output
61+ {
62+ try {
63+ return $ this ->selectWithParams ($ query , params: [], outputFormat: $ outputFormat , settings: $ settings );
64+ } catch (UnsupportedValue ) {
65+ absurd ();
66+ }
67+ }
68+
69+ public function selectWithParams (string $ query , array $ params , Format $ outputFormat , array $ settings = []): Output
5670 {
5771 $ formatClause = $ outputFormat ::toSql ();
5872
73+ $ sql = $ this ->sqlFactory ->createWithParameters ($ query , $ params );
74+
5975 $ response = $ this ->executeRequest (
6076 <<<CLICKHOUSE
61- $ query
77+ $ sql
6278 $ formatClause
6379 CLICKHOUSE ,
64- $ settings ,
80+ settings: $ settings ,
6581 );
6682
6783 return $ outputFormat ::output ($ response ->getBody ()->__toString ());
6884 }
6985
70- public function selectWithParams (string $ query , array $ params , Format $ outputFormat , array $ settings = []): Output
71- {
72- return $ this ->select (
73- $ this ->sqlFactory ->createWithParameters ($ query , $ params ),
74- $ outputFormat ,
75- $ settings ,
76- );
77- }
78-
7986 public function insert (string $ table , array $ values , array |null $ columns = null , array $ settings = []): void
8087 {
8188 if ($ values === []) {
@@ -111,7 +118,7 @@ public function insert(string $table, array $values, array|null $columns = null,
111118 $ columnsSql
112119 VALUES $ valuesSql
113120 CLICKHOUSE ,
114- $ settings ,
121+ settings: $ settings ,
115122 );
116123 }
117124
@@ -125,7 +132,7 @@ public function insertWithFormat(string $table, Format $inputFormat, string $dat
125132 <<<CLICKHOUSE
126133 INSERT INTO $ table $ formatSql $ data
127134 CLICKHOUSE ,
128- $ settings ,
135+ settings: $ settings ,
129136 );
130137 }
131138
@@ -135,7 +142,7 @@ public function insertWithFormat(string $table, Format $inputFormat, string $dat
135142 * @throws ServerError
136143 * @throws ClientExceptionInterface
137144 */
138- private function executeRequest (string $ sql , array $ settings = [] ): ResponseInterface
145+ private function executeRequest (string $ sql , array $ settings ): ResponseInterface
139146 {
140147 $ request = $ this ->requestFactory ->prepareRequest (
141148 new RequestOptions (
0 commit comments