Repository navigation
Better structure with namespaces. New like condition and select method. Updated orWhere and getStoreId method. - #40
Conversation
ext-json to composer as required, because of json_encode and json_decode methods; own file for every exception class, for better structure; like functionality; [UPDATED] name spaces of Traits and Exceptions; file names of traits; [FIXED] missing @throws tags; wrong behavior of verifyWhereConditions method if condition is not matched by any if statements;
|
Added new select method to specify which fields should be in result. The field names to select or exclude are separated with a space between. By default the field _id is always selected. Example without select (nothing changed with this pr): $newsStore->where("_id", "=", 2)->fetch();Output: [
[
"title" => "New Select Method",
"content" => "Lorem Ipsum",
"author" => "Max",
"_id" => 2
]
]Example 1 - Select one field:$newsStore->select("title")->where("_id", "=", 2)->fetch();Output: [[ "_id" => 2, "title" => "New Select Method" ]]Example 2 - Select two fields:$newsStore->select("title author")->where("_id", "=", 2)->fetch();Output: [[ "_id" => 2, "title" => "New Select Method", "author" => "Max" ]]Example 3 - Don't select field:$newsStore->select("-author")->where("_id", "=", 2)->fetch();Output: [[ "_id" => 2, "title" => "New Select Method", "content" => "Lorem Ipsum" ]]Example 4 - Don't select two fields:$newsStore->select("-author -title")->where("_id", "=", 2)->fetch();Output: [[ "_id" => 2, "content" => "Lorem Ipsum" ]]Example 5 - Just select author, without _id field:$newsStore->select("author -_id")->where("_id", "=", 2)->fetch();Output: [[ "author" => "Lorem Ipsum" ]]Example 6 - Exclude not existing field:$newsStore->select("-rating")->where("_id", "=", 2)->fetch();Output: [
[
"title" => "New Select Method",
"content" => "Lorem Ipsum",
"author" => "Max",
"_id" => 2
]
]Example 7 - Select not existing field:$newsStore->select("rating")->where("_id", "=", 2)->fetch();Output: [[ "_id" => 2 ]]#38 I think this is a good solution for this enhancement request. |
…"and" between each condition
|
Updated the orWhere method to allow infinite conditions that have an "and" between each condition. Now the orWhere method can be used in four ways: "Old way"$newsStore->where("_id", "=", 2)->orWhere("author", "=", "Max")->fetch();With arrays$condition1 = ["author", "=", "Max"];
$condition2 = ["author", "=", "Isabelle"];
$newsStore->where("_id", "=", 2)->orWhere($condition1, $condition2)->fetch();With maps$condition1 = ["fieldName" => "author", "condition" => "=", "value" => "Max"];
$condition2 = ["fieldName" => "author", "condition" => "=", "value" => "Isabelle"];
$newsStore->where("_id", "=", 2)->orWhere($condition1, $condition2)->fetch();Mix of array and map$condition1 = ["author", "=", "Max"];
$condition2 = ["fieldName" => "author","condition" => "=", "value" => "Isabelle"];
$newsStore->where("_id", "=", 2)->orWhere($condition1, $condition2)->fetch(); |
|
#30 |
|
@Timu57 Many thanks for your contributions, it's inspiring and much needed. Here are some quick thoughts: $newsStore->select("author -_id");After a while the first thing I have noticed that it might create confusions, for example some one might have a key called Now if he want to select only name he would write the query like this: (If I understood it correctly) $newsStore->select("-name");It will work now in opposite direction! Some times it could be also readability issue for other team members. So, I was thinking of two different methods,
Making sure,
Please let me know what you think about this update. |
|
@rakibtg Thank you for your response. |
[ADDED] except method to exclude specified fields
|
Now the implementation is like this: // select few fields
$newsStore->select(["title","content"])->where("_id", "=", 2)->fetch();
// exclude fields
$newsStore->except(["_id"])->where("_id", "=", 2)->fetch();
// select and exclude fields
$newsStore->select(["title"])->except(["_id","author"])->where("_id", "=", 2)->fetch(); |
|
Hi, is something wrong with the pr? |
|
Hi @Timu57 Extremely sorry for the delay, hopefully I can merge it within tomorrow :) |
|
@Timu57 Merged 🎉 Thanks for the PR ❤️. Going to create a new release soon. |
Hi,
thank you for this nice project.
I made some improvements.
Should not interfere with any code using this SleekDB.
Hope this can be merged or further improved before merging.
A little summary:
[ADDED]
like condition with regex;
ext-json to composer as required, because of json_encode and json_decode methods;
own file for every exception class, for better structure and easier usage outside of SleekDB;
namespaces to Traits and Exceptions;
[UPDATED]
file names of traits;
folder structure;
[FIXED]
missing @throws tags;
wrong behavior of verifyWhereConditions method if condition is not matched by any if statements;