Skip to content

Instantly share code, notes, and snippets.

@jasonvarga
Created June 30, 2021 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonvarga/e040614e631b57295e10f34703e15246 to your computer and use it in GitHub Desktop.
Save jasonvarga/e040614e631b57295e10f34703e15246 to your computer and use it in GitHub Desktop.
Fake Statamic SQL entries query for debugging
<?php
// A very crude way to see the "query" when using the stache.
// I used this to test https://github.com/statamic/cms/pull/3540
public function get($columns = ['*'])
{
$results = parent::get($columns);
$sql = 'select ';
$sql .= join(', ', $columns). ' from `entries` ';
$sql .= collect($this->wheres)->map(function ($where) {
$str = ($where['type'] === 'In')
? 'in (' . join(', ', $where['values']) . ')'
: $where['operator'] . ' ' . ($where['value'] ?? 'null');
return 'where `' . $where['column'] . '` ' . $str;
})->join(' and ');
ray($sql);
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment