PostgresProcessor.php 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Illuminate\Database\Query\Processors;
  3. use Illuminate\Database\Query\Builder;
  4. class PostgresProcessor extends Processor
  5. {
  6. /**
  7. * Process an "insert get ID" query.
  8. *
  9. * @param \Illuminate\Database\Query\Builder $query
  10. * @param string $sql
  11. * @param array $values
  12. * @param string $sequence
  13. * @return int
  14. */
  15. public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
  16. {
  17. $result = $query->getConnection()->selectFromWriteConnection($sql, $values)[0];
  18. $sequence = $sequence ?: 'id';
  19. $id = is_object($result) ? $result->{$sequence} : $result[$sequence];
  20. return is_numeric($id) ? (int) $id : $id;
  21. }
  22. /**
  23. * Process the results of a column listing query.
  24. *
  25. * @param array $results
  26. * @return array
  27. */
  28. public function processColumnListing($results)
  29. {
  30. return array_map(function ($result) {
  31. return ((object) $result)->column_name;
  32. }, $results);
  33. }
  34. }