Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from filebase/1.0
Browse files Browse the repository at this point in the history
sync 01
  • Loading branch information
faryar76 committed Feb 22, 2019
2 parents 5cd3f44 + 9fccaab commit 6bc9a4a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Change Log
==========

### 02/21/2019 - 1.0.22
* Merged [Pull Request](https://github.com/filebase/Filebase/pull/47) for deleting items with a custom filter. (this adds the `delete()` method on queries.)

### 12/26/2018 - 1.0.21
* Merged [Pull Request](https://github.com/filebase/Filebase/pull/30) for YAML format.

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ if ($database->has('kingslayer'))
// do some action
}


// Need to find all the users that have a tag for "php" ?
$users = $db->query()->where('tags','IN','php')->results();

Expand Down Expand Up @@ -379,13 +378,16 @@ echo $user['name'];
// What about regex search? Finds emails within a field
$users = $db->query()->where('email','REGEX','/[a-z\d._%+-]+@[a-z\d.-]+\.[a-z]{2,4}\b/i')->results();


// Find all users that have gmail addresses and only returning their name and age fields (excluding the rest)
$users = $db->query()->select('name,age')->where('email','LIKE','@gmail.com')->results();

// Instead of returning users, how about just count how many users are found.
$totalUsers = $db->query()->where('email','LIKE','@gmail.com')->count();

// Delete using custom filters (this will act like a bulk delete)
$db->query()->where('name','LIKE','john')->delete(function($item){
return ($item->name == 'John' && $item->email == '[email protected]');
});

```

Expand All @@ -403,6 +405,7 @@ To run the query use `results()` or if you only want to return the first item us
|`orWhere()` | `mixed` | see `where()`, this uses the logical `OR` |
|`limit()` | `int` limit, `int` offset | How many documents to return, and offset |
|`orderBy()` | `field` , `sort order` | Order documents by a specific field and order by `ASC` or `DESC` |
|`delete()` | `Closure` | Ability to Bulk-delete all items that match |


The below **methods execute the query** and return results *(do not try to use them together)*
Expand Down
4 changes: 2 additions & 2 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Database
* Stores the version of Filebase
* use $db->getVersion()
*/
const VERSION = '1.0.20';
const VERSION = '1.0.22';


//--------------------------------------------------------------------
Expand Down Expand Up @@ -322,7 +322,7 @@ protected function read($name)

$file = Filesystem::read(
$this->config->dir . '/'
. Filesystem::validateName($name, $this->config->safe_filename)
. Filesystem::validateName($name, $this->config->safe_filename)
. '.' . $format::getFileExtension()
);

Expand Down
4 changes: 2 additions & 2 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1045,9 +1045,9 @@ public function testQueryFromCacheAfterSave()
$db->flush(true);
}
public function testDeleteWhereMatchItemsWithCustomFilter()
{
{
$db = new \Filebase\Database([
'dir' => 'path/to/users/users/test',
'dir' => __DIR__.'/databases/deletefilter',
]);
$db->flush(true);

Expand Down

0 comments on commit 6bc9a4a

Please sign in to comment.