Arrch Released by Michael Giuliana on 11/14/12
On a fairly recent project, I found that I was limited in my access to a traditional database - I ended up using flat-files to store JSON representations of my data. The cache process is run asynchronously with PHP, but that's another monster... Once the data was stored, accessing it was all or nothing. I needed an efficient and simple way to query the array of cached items like a database - so Arrch came into being. Here's an example data structure:
// LARGE array of objects or assoc. arrays $data = array( ..., array( 'id' => 1403, 'first_name' => 'John', 'last_name' => 'Searchable', 'deceased' => false, 'data' => array( 'children' => 3, 'dogs' => 10, 'rabbits' => 14 ), ), ..., );
Of course, the array doesn't have to be large, but they make for good test sets. Here's an example query:
// Arrch::find($data, $where, $limit, $sort_key, $sort_order) $results = Arrch::find($data, array( // Where 'first_name' is like, or contains 'h' (that second param is a tilde) array('first_name', '~', 'h'), // Where 'data.children' === 3 array('data.children', 3) ), 1, 'last_name', 'ASC');
The find() method operates on the $data array as a reference, but also returns the result array so you can set it to a variable or return it from within a function.