2121use SimPod \ClickHouseClient \Logger \SqlLogger ;
2222use SimPod \ClickHouseClient \Output \Output ;
2323use SimPod \ClickHouseClient \Schema \Table ;
24+ use SimPod \ClickHouseClient \Settings \EmptySettingsProvider ;
25+ use SimPod \ClickHouseClient \Settings \SettingsProvider ;
2426use SimPod \ClickHouseClient \Sql \SqlFactory ;
2527use SimPod \ClickHouseClient \Sql \ValueFormatter ;
2628
@@ -42,18 +44,17 @@ class PsrClickHouseClient implements ClickHouseClient
4244
4345 private SqlFactory $ sqlFactory ;
4446
45- /** @param array<string, float|int|string> $defaultSettings */
4647 public function __construct (
4748 private ClientInterface $ client ,
4849 private RequestFactory $ requestFactory ,
4950 private SqlLogger |null $ sqlLogger = null ,
50- private array $ defaultSettings = [] ,
51+ private SettingsProvider $ defaultSettings = new EmptySettingsProvider () ,
5152 ) {
5253 $ this ->valueFormatter = new ValueFormatter ();
5354 $ this ->sqlFactory = new SqlFactory ($ this ->valueFormatter );
5455 }
5556
56- public function executeQuery (string $ query , array $ settings = [] ): void
57+ public function executeQuery (string $ query , SettingsProvider $ settings = new EmptySettingsProvider () ): void
5758 {
5859 try {
5960 $ this ->executeRequest ($ query , params: [], settings: $ settings );
@@ -62,26 +63,36 @@ public function executeQuery(string $query, array $settings = []): void
6263 }
6364 }
6465
65- public function executeQueryWithParams (string $ query , array $ params , array $ settings = []): void
66- {
66+ public function executeQueryWithParams (
67+ string $ query ,
68+ array $ params ,
69+ SettingsProvider $ settings = new EmptySettingsProvider (),
70+ ): void {
6771 $ this ->executeRequest (
6872 $ this ->sqlFactory ->createWithParameters ($ query , $ params ),
6973 params: $ params ,
7074 settings: $ settings ,
7175 );
7276 }
7377
74- public function select (string $ query , Format $ outputFormat , array $ settings = []): Output
75- {
78+ public function select (
79+ string $ query ,
80+ Format $ outputFormat ,
81+ SettingsProvider $ settings = new EmptySettingsProvider (),
82+ ): Output {
7683 try {
7784 return $ this ->selectWithParams ($ query , params: [], outputFormat: $ outputFormat , settings: $ settings );
7885 } catch (UnsupportedParamValue | UnsupportedParamType ) {
7986 absurd ();
8087 }
8188 }
8289
83- public function selectWithParams (string $ query , array $ params , Format $ outputFormat , array $ settings = []): Output
84- {
90+ public function selectWithParams (
91+ string $ query ,
92+ array $ params ,
93+ Format $ outputFormat ,
94+ SettingsProvider $ settings = new EmptySettingsProvider (),
95+ ): Output {
8596 $ formatClause = $ outputFormat ::toSql ();
8697
8798 $ sql = $ this ->sqlFactory ->createWithParameters ($ query , $ params );
@@ -98,8 +109,12 @@ public function selectWithParams(string $query, array $params, Format $outputFor
98109 return $ outputFormat ::output ($ response ->getBody ()->__toString ());
99110 }
100111
101- public function insert (Table |string $ table , array $ values , array |null $ columns = null , array $ settings = []): void
102- {
112+ public function insert (
113+ Table |string $ table ,
114+ array $ values ,
115+ array |null $ columns = null ,
116+ SettingsProvider $ settings = new EmptySettingsProvider (),
117+ ): void {
103118 if ($ values === []) {
104119 throw CannotInsert::noValues ();
105120 }
@@ -192,7 +207,7 @@ public function insertWithFormat(
192207 Table |string $ table ,
193208 Format $ inputFormat ,
194209 string $ data ,
195- array $ settings = [] ,
210+ SettingsProvider $ settings = new EmptySettingsProvider () ,
196211 ): void {
197212 $ formatSql = $ inputFormat ::toSql ();
198213
@@ -220,7 +235,7 @@ public function insertPayload(
220235 Format $ inputFormat ,
221236 StreamInterface $ payload ,
222237 array $ columns = [],
223- array $ settings = [] ,
238+ SettingsProvider $ settings = new EmptySettingsProvider () ,
224239 ): void {
225240 if ($ payload ->getSize () === 0 ) {
226241 throw CannotInsert::noValues ();
@@ -259,13 +274,12 @@ public function insertPayload(
259274
260275 /**
261276 * @param array<string, mixed> $params
262- * @param array<string, float|int|string> $settings
263277 *
264278 * @throws ServerError
265279 * @throws ClientExceptionInterface
266280 * @throws UnsupportedParamType
267281 */
268- private function executeRequest (string $ sql , array $ params , array $ settings ): ResponseInterface
282+ private function executeRequest (string $ sql , array $ params , SettingsProvider $ settings ): ResponseInterface
269283 {
270284 $ request = $ this ->requestFactory ->prepareSqlRequest (
271285 $ sql ,
0 commit comments