2121use SimPod \ClickHouseClient \Format \Format ;
2222use SimPod \ClickHouseClient \Logger \SqlLogger ;
2323use SimPod \ClickHouseClient \Output \Output ;
24- use SimPod \ClickHouseClient \Sql \ Escaper ;
24+ use SimPod \ClickHouseClient \Schema \ Table ;
2525use SimPod \ClickHouseClient \Sql \SqlFactory ;
2626use SimPod \ClickHouseClient \Sql \ValueFormatter ;
2727
@@ -100,13 +100,17 @@ public function selectWithParams(string $query, array $params, Format $outputFor
100100 return $ outputFormat ::output ($ response ->getBody ()->__toString ());
101101 }
102102
103- public function insert (string $ table , array $ values , array |null $ columns = null , array $ settings = []): void
103+ public function insert (Table | string $ table , array $ values , array |null $ columns = null , array $ settings = []): void
104104 {
105105 if ($ values === []) {
106106 throw CannotInsert::noValues ();
107107 }
108108
109- $ table = Escaper::quoteIdentifier ($ table );
109+ if (! $ table instanceof Table) {
110+ $ table = new Table ($ table );
111+ }
112+
113+ $ tableName = $ table ->fullName ();
110114
111115 if (is_array ($ columns ) && ! array_is_list ($ columns )) {
112116 $ columnsSql = sprintf ('(%s) ' , implode (', ' , array_keys ($ columns )));
@@ -139,7 +143,7 @@ static function (array $row) use (&$pN, $types): string {
139143
140144 $ this ->executeRequest (
141145 <<<CLICKHOUSE
142- INSERT INTO $ table
146+ INSERT INTO $ tableName
143147 $ columnsSql
144148 VALUES $ valuesSql
145149 CLICKHOUSE ,
@@ -174,7 +178,7 @@ static function (array $row) use (&$pN, $types): string {
174178 try {
175179 $ this ->executeRequest (
176180 <<<CLICKHOUSE
177- INSERT INTO $ table
181+ INSERT INTO $ tableName
178182 $ columnsSql
179183 VALUES $ valuesSql
180184 CLICKHOUSE ,
@@ -186,16 +190,24 @@ static function (array $row) use (&$pN, $types): string {
186190 }
187191 }
188192
189- public function insertWithFormat (string $ table , Format $ inputFormat , string $ data , array $ settings = []): void
190- {
193+ public function insertWithFormat (
194+ Table |string $ table ,
195+ Format $ inputFormat ,
196+ string $ data ,
197+ array $ settings = [],
198+ ): void {
191199 $ formatSql = $ inputFormat ::toSql ();
192200
193- $ table = Escaper::quoteIdentifier ($ table );
201+ if (! $ table instanceof Table) {
202+ $ table = new Table ($ table );
203+ }
204+
205+ $ tableName = $ table ->fullName ();
194206
195207 try {
196208 $ this ->executeRequest (
197209 <<<CLICKHOUSE
198- INSERT INTO $ table $ formatSql $ data
210+ INSERT INTO $ tableName $ formatSql $ data
199211 CLICKHOUSE ,
200212 params: [],
201213 settings: $ settings ,
@@ -206,7 +218,7 @@ public function insertWithFormat(string $table, Format $inputFormat, string $dat
206218 }
207219
208220 public function insertPayload (
209- string $ table ,
221+ Table | string $ table ,
210222 Format $ inputFormat ,
211223 StreamInterface $ payload ,
212224 array $ columns = [],
@@ -218,12 +230,16 @@ public function insertPayload(
218230
219231 $ formatSql = $ inputFormat ::toSql ();
220232
221- $ table = Escaper::quoteIdentifier ($ table );
233+ if (! $ table instanceof Table) {
234+ $ table = new Table ($ table );
235+ }
236+
237+ $ tableName = $ table ->fullName ();
222238
223239 $ columnsSql = $ columns === [] ? '' : sprintf ('(%s) ' , implode (', ' , $ columns ));
224240
225241 $ sql = <<<CLICKHOUSE
226- INSERT INTO $ table $ columnsSql $ formatSql
242+ INSERT INTO $ tableName $ columnsSql $ formatSql
227243 CLICKHOUSE ;
228244
229245 $ request = $ this ->requestFactory ->initRequest (
0 commit comments