Skip to content

Deprecate SleekDB Class #84

Closed
Closed

Description

@Timu57

Introduction

The SleekDB class is at the moment a wrapper class for the Store, QueryBuilder, Query and Cache classes.

We keep and need that wrapper class to provide downwards compatibility but deprecating it now and removing the wrapper class in future releases.
That will make the SleekDB project much cleaner and more consistent.
It will also reduce the learning curve for new users and remove confusion.

The SleekDB class provides an easier way of usage than with the new classes.

Example with SleekDB class to retrieve all documents:

$result = $store->fetch()

Same example with Store class:

$result = $store->createQueryBuilder()->getQuery()->fetch();

The Store class has more structure and a distinct way of how to use it that also guides the user and provide better method suggestions with IDEs but unfortunately it's too complex for such simple queries.

Brand new methods

Retrieve all documents.

  public function findAll(): array

Retrieve one document with _id. (Very fast - Looks directly for file)

  public function findById(int $id): array|null

Retrieve one or multiple documents.

  public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array

Retrieve one document document.

  public function findOneBy(array $criteria): array|null

Update one or multiple documents.

  public function update(array $updatable): bool

Delete one or multiple documents.

  public function deleteBy($criteria, $returnOption = Query::DELETE_RETURN_BOOL): array|bool|int

Delete one document with _id. (Very fast - Looks directly for file)

  public function deleteById($id): bool

Comparing SleekDB and Store again

These new methods are enough for most use cases, so they render the QueryBuilder class most of the time optional and eliminate the advantage the SleekDB wrapper class had.


Example with SleekDB class to retrieve all documents:

$result = $store->fetch();

Same example with Store class:

$result = $store->findAll();

Example with SleekDB class to retrieve some documents:

$result = $store->where(["name", "=", "Luke"])->orderBy("asc", "date")->limit(10)->skip(2)->fetch();

Same example with Store class:

$result = $store->findBy(["name", "=", "Luke"], ["date" => "asc"], 10, 2);

Conclusion

For more complex methods there is still the QueryBuilder class that can be used.

We also added the new methods to the SleekDB wrapper class and had one problem.

The Query class has a update(array $updatable): bool method to execute the previously defined query and update all found documents with the given $updatable document.

The newly added update(array $updatable): bool does something completely different. It uses the _id property of the given document/s and looks directly for the file.

With the Store class it can be used like this:

$store->update($updatable);

The SleekDB wrapper class already contains a wrapper method for the update(array $updatable): bool method of the Query class, so we could not name the method update and used updateBy(array $updatable): bool instead.

Now we have a little problem regarding consistency, learning curve, complexity and confusion potential. If the SleekDB project also gets more complex and feature rich the wrapper class will become a big problem.

Thats why we have to deprecate the entire SleekDB class and remove it in the future.

Activity

  1. self-assigned this
    on Jan 13, 2021
  2. added this to the Version 2.0 milestone on Jan 13, 2021
  3. rakibtg commented on Jan 14, 2021

    @rakibtg
    Member

    @Timu57 Let's be it then :) We will deprecate the SleekDB class, the documentation will focus on Store, QueryBuilder, Query and Cache classes. In another page we may clarify the issue with the SleekDB class.

  4. rakibtg commented on Jan 24, 2021

    @rakibtg
    Member

    Added in SleekDB 2.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions