private function buildJoins(array $joins)
    {
        foreach ($joins as &$join) {
            // table(s)
            foreach ($join[1] as &$table) {
                $table = $this->escapeIdentifier($table);
            }
            $join[1] = implode(', ', array_filter($join[1]));

            // on clause
            if ($join[2]) {
                $join[2] = 'ON '.$join[2];
            } else {
                unset($join[2]);
            }

            // using clause
            foreach ($join[3] as &$column) {
                $column = $this->escapeIdentifier($column);
            }
            $join[3] = implode(', ', array_filter($join[3]));

            if ($join[3]) {
                $join[3] = 'USING ('.$join[3].')';
            } else {
                unset($join[3]);
            }
            $join = implode(' ', $join);
        }

        return implode(' ', array_filter($joins));
    }