Created
June 30, 2021 20:18
-
-
Save jasonvarga/e040614e631b57295e10f34703e15246 to your computer and use it in GitHub Desktop.
Fake Statamic SQL entries query for debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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