$params Bound to {name:Type} placeholders in $sql. * @return array> */ public function query(string $sql, array $params = []): array { $query = array_merge( ['database' => $this->database, 'default_format' => 'JSONEachRow'], collect($params)->mapWithKeys(fn ($value, $key) => ["param_{$key}" => $value])->all(), ); $response = Http::withBasicAuth($this->username, $this->password) ->withBody($sql, 'text/plain') ->post("{$this->baseUrl}/?".http_build_query($query)); if ($response->failed()) { throw new RuntimeException("ClickHouse query failed ({$response->status()}): {$response->body()}"); } // JSONEachRow: one JSON object per line, not a JSON array. return collect(explode("\n", trim($response->body()))) ->filter(fn (string $line) => $line !== '') ->map(fn (string $line) => json_decode($line, true)) ->all(); } }