Giter Site home page Giter Site logo

sleekdb / sleekdb Goto Github PK

View Code? Open in Web Editor NEW
876.0 38.0 79.0 535 KB

Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.

Home Page: https://sleekdb.github.io

License: MIT License

PHP 100.00%
nosql-databases nosql php php7 database flat-file filestorage storage storage-engine api

sleekdb's Introduction

Please give it a Star if you like the project ๐ŸŽ‰ โค๏ธ

SleekDB - A NoSQL Database made using PHP

Full documentation: https://sleekdb.github.io/

SleekDB is a simple flat file NoSQL like database implemented in PHP without any third-party dependencies that store data in plain JSON files.

It is not designed to handle heavy-load IO operations, it is designed to have a simple solution where all we need a database for managing a few gigabytes of data. You can think of it as a database for low to medium operation loads.

Features

  • โšก Lightweight, faster

    Stores data in plain-text utilizing JSON format, no binary conversion needed to store or fetch the data. Default query cache layer.

  • ๐Ÿ”† Schema free data storage

    SleekDB does not require any schema, so you can insert any types of data you want.

  • ๐Ÿ” Query on nested properties

    It supports schema free data, so you can filter and use conditions on nested properties of the JSON documents!

    where( 'post.author.role', '=', 'admin' )

    SleekDB will look for data at:

    {
      "post": {
        "author": {
          "role": "admin"
        }
      }
    }
  • โœจ Dependency free, only needs PHP to run

    Supports PHP 7+. Requires no third-party plugins or software.

  • ๐Ÿš€ Default caching layer

    SleekDB will serve data from cache by default and regenerate cache automatically! Query results will be cached and later reused from a single file instead of traversing all the available files.

  • ๐ŸŒˆ Rich Conditions and Filters

    Use multiple conditional comparisons, text search, sorting on multiple properties and nested properties. Some useful methods are:

    • where
    • orWhere
    • select
    • except
    • in
    • not in
    • join
    • like
    • sort
    • skip
    • orderBy
    • update
    • limit
    • search
    • distinct
    • exists
    • first
    • delete
    • like
    • not lik
    • between
    • not between
    • group by
    • having
  • ๐Ÿ‘ Process data on demand

    SleekDB does not require any background process or network protocol in order to process data when you use it in a PHP project. All data for a query will be fetched at runtime within the same PHP process.

  • ๐Ÿ˜ Runs everywhere

    Runs perfectly on shared-servers or VPS too.

  • ๐Ÿฐ Easy to learn and implement

    SleekDB provides a very simple elegant API to handle all of your data.

  • ๐Ÿฐ Easily import/export or backup data

    SleekDB use files to store information. That makes tasks like backup, import and export very easy.

  • ๐Ÿ’ช Actively maintained

    SleekDB is created by @rakibtg who is using it in various types of applications which are in production right now. Our other contributor and active maintainer is Timucin who is making SleekDB much better in terms of code quality and new features.

  • ๐Ÿ“” Well documented

    The official documentation of SleekDB does not just provide a good api documentation. It is filled with examples!

Visit our website https://sleekdb.github.io/ for documentation and getting started guide.

sleekdb's People

Contributors

daussho avatar jakiboy avatar rakibtg avatar timu57 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sleekdb's Issues

Wrong namespace

    public function deleteStore() {
      $it = new RecursiveDirectoryIterator( $this->storePath, RecursiveDirectoryIterator::SKIP_DOTS );
      $files = new RecursiveIteratorIterator( $it, RecursiveIteratorIterator::CHILD_FIRST );
500 Internal Server Error
Class 'SleekDB\RecursiveDirectoryIterator' not found (0)

Can not use deleteStore() function at all. How do you even commit code without checking? Starting to get disappointed, if it has this level of errors on the surface, it's getting obvious this code is not used at all, who knows what other bad things happen inside.

Check if data exists

Adding an object that can be used to determine if data exists or not!

Example:

  SleekDB::store($store, $directory)
      ->where("email", "=", "[email protected]")
      ->exists()
      ->fetch();

This will return a true or false based on the existence of the data that you are looking for.

One of the benefit of using exists() method will be that it can skip extra document checks when all you need to know if a document with some conditions exists or not.
It will also ignore the join operations(if any) of the query.

๐Ÿ“ข Join our Telegram channel here: https://t.me/joinchat/LDAP_B1pyu3iZazrBl37Ow

Improving document discovering performance.

Huge improvement lacks while discovering documents with each conditions. Add progressive document discovery of documents.
Example:

<?php

  $destination = 'H:\xx\data_dumps\x';

  if ($handle = opendir($destination)) {
    while (false !== ($entry = readdir($handle))) {
      if ($entry != "." && $entry != "..") {
        $file = $destination . '/' . $entry;
        // ... code here
      }
    }
    closedir($handle);
  }

Make where and orWhere just accept one array

We deprecate the following usage of where and orWhere:

$store->where($fieldName, $condition, $value);

$store->orWhere($fieldName, $condition, $value);

Instead it should be used like this:

$store->where([$fieldName, $condition, $value]);

$store->orWhere([$fieldName, $condition, $value]);

Multiple clauses

For multiple where the user had to repeatedly use where:

$store->where($fieldName, $condition, $value)->where($fieldName2, $condition2, $value2)

Now it can be used like this:

$store->where([$fieldName, $condition, $value])->where([$fieldName2, $condition2, $value2]);
// or
$store->where([[$fieldName, $condition, $value], [$fieldName2, $condition2, $value2]]);

Possibility of duplicate IDโ€™s

If 2 data arrays were inserted into a store/table from separate requests at exactly the same time, for example 2 comments from 2 different users. What would stop these inserts from using the same ID?

I know the probability is unlikely but is there a system in place to prevent this?

I did look to see if flock was used but couldnโ€™t find anything.

A method to directly read the document by it's _id

Right now to find a document by it's _id the system will go through all the checks it has to fetch data from documents.
As the file name of a document is identical to its _id and as this id will be auto generated by the system so I think it's safe and efficient to have a method findById which will directly read a json file of that store and return the data instead of going through all the steps.

Multiple where() condition doesn't work

Hello there,

I have a problem with multiple where() conditions for my DB, I have start and end dates for my news article, I'm trying to do following to select 'active' news item:

$news = $newsStore
        ->orderBy( 'asc', 'order' )
        ->where( 'startDate', '<', time() )
        ->where( 'endDate', '>', time() )
        ->fetch();

Looks like first condition is completely ignored and only second one is applied.

Any help please?

reuse clause?

Below is a working clause, which I check existence and update data:

$result = $db->where(...)->...where(...)->fetch();
if(count($result)){
    $db->where(...)->...where(...)->update(...);//working
}

Since the where clause are so long and duplicated, my first mind is to rewriting it:

$query = $db->where(...)->...where(...);
$result = $query->fetch();
if(count($result)){
    $query->update(...);//not working, this updates all data
}

It is not working as expected. A similar example would be

$query = $db->where(...);
$query->fetch(); //show filtered result by where
$query->fetch(); //run it again, showing all data

So, the fetch() is actually affecting the $query itself, rather than a copy of $query.
I would personally prefer the reuse way would be designed and implemented. Or please telling users do not use it in this way in the tutorial (maybe can save their time).

BTW, below is a SQL PDO example, which would allow reuse:

$stmt = $db->prepare("select * from data where name=?");

$stmt->execute(["A"]);
$stmt->fetch(PDO::FETCH_ASSOC);//show result where name=="A"

$stmt->execute(["B"]);
$stmt->fetch(PDO::FETCH_ASSOC);//run it again, show result where name=="B"

Implement `in` clause.

Implement whereIn clause
Example:

   $db->whereIn( 'country', ['BD', 'SE', 'NO', 'CA'] )
      ->fetch();

Saving format is wrong

When trying to insert data using insert command

It saves data like this :
image

instead of this:
image

so, when I am trying to fetch data with conditions like (where, in) it returns an empty array.

thanks

Add update & delete to Store class

For simple queries conveniently update and delete documents without the need of QueryBuilder.

Update one or multiple documents.

function update($documents): bool

Delete one document.

function deleteDocument($id, $returnOption = Query::DELETE_RETURN_RESULTS): array|bool|int

For more return options look into #77

Date Rang

Hi,

Is Date Range filter supported or not?

Thanks,

Like Condition

I added these lines into the
HelpersTrait->verifyWhereConditions

else if ( $condition === "like" ) {
if ( strpos($fieldValue,$value) === false ) return false;
}
it looks fine.

Return the first item only

The fetch() method would return an array of documents. By using the first() method in the query we can get only the first item found, skipping additional document checks. Instead of returning an array of document it will return only a single document object.

Example:

SleekDB::store($store, $dataDirectory)->first()->fetch();

This would return only the data object instead of a single item within an array!

// Output
[
  "name" => "Foo",
  "email" => "[email protected]"
]

->where()->where() works like a OR condition

Love this library. I think the ->where()->where() conditions works like an OR condition.
I've added this line to make it work as I expected (as a AND condition) in helpers.php.

[edit] not exactly a OR condition, it's the last where clause that decides if the conditiosn are OK.

if( $validData === true ) {
        $storePassed = $this->verifyWhereConditions( $condition[ 'condition' ], $fieldValue, $condition[ 'value' ] );
        if (!$storePassed) break; //added by JP,  bug ?
}

Supress Key on fetch

Not show some keys on fetch.

1- have a store:

[
{
"name":"Bruno",
"country":"Brazil",
"age":"35",
"_id":1
},
{
"name":"Hasan",
"country":"Bangladesh",
"age":"30",
"_id":2
},
{
"name":"XYZ",
"country":"Z",
"age":"20",
"_id":3
},
{
"name":"ABC",
"country":"C",
"age":"10",
"_id":4
}
]

2- Fetch supressing keys "age" and "id":

$store= \SleekDB\SleekDB::store("example", dirname(FILE)."/dataBase");
$result = $store->where("_id",<",3)->SUPRESS("age","_id")->fetch();

3- Expected fetch result:
$result =
[
{
"name":"Bruno",
"country":"Brazil"
},
{
"name":"Hasan",
"country":"Bangladesh"
}
]

Change delete method of Query class to accept return options

// Query class

public function delete($returnOption = self::DELETE_RETURN_BOOL): bool|array|int

3 Constants

DELETE_RETURN_BOOL

Value: 1
Returns true on success and false if nothing found to delete.

DELETE_RETURN_RESULTS

Value: 2
Returns the deleted documents as a two dimensional array on success and an empty array if nothing found to delete.

DELETE_RETURN_COUNT

Value: 3
Returns 0 if nothing found to delete and the count of deleted documents on success.

Encryption and authentication

Please consider adding some form of full file encryption (e.g.: Mcrypt?) for the stored JSON files.
Also, please consider adding some form of user authentication (a nice to have).
Keep up the good work!

Cache based on key

Its possible to create automatic cache based on key?

Define AUTOMATIC CACHE for Key "country" on store $members.

The idea is all distinct values on key "country" (Brazil, Bangladesh, Z, C) would have automatic cache for fast fetch.
(each data update, would update automatically the cached data)

Example:
1- have a store $members=

[
{
"name":"Bruno",
"country":"Brazil",
"age":"35",
"_id":1
},
{
"name":"Hasan",
"country":"Bangladesh",
"age":"30",
"_id":2
},
{
"name":"XYZ",
"country":"Z",
"age":"20",
"_id":3
},
{
"name":"ABC",
"country":"C",
"age":"10",
"_id":4
},
{
"name":"User 5",
"country":"Brazil",
"age":"36",
"_id":5
},
{
"name":"User 6",
"country":"Bangladesh",
"age":"37",
"_id":6
}
]

Better code base

First of all, nice work.
But it would be much easier to help you with the expansion and development, then the structure would be different.
As an example it is not easy to build memcached / APCu or Redis as cache here.
Also the choice of the storage format (JSON / Serialze) can't be easily extended here, because absolutely no changes to the code are planned. Whereby this would be very easy to do.
To be able to manage tables / instances better, a class would be very good.
https://gist.github.com/Steinweber/6b8340e0dd6091f7dcffdbce235d6c2d

Make dataDir required

The data directory parameter when creating a store was made optional to make joins easier.
Now joins are made different, so data directory does not have to be optional anymore.

Then we do not need the _checkBootUp method anymore.

Option for _id

Sleek is generate id as "_id"
But Can it have an option for name it just "id" without underscore

update return value

The update function returns true even when the underlying file_put_contents return false due to security permissions.
So, nothing where updated in the register but update returns true, see PHP log Warning:

[Sat Nov 21 01:24:51.072446 2020] [php7:warn] [pid 1870] [client 111.111.111.111:1234] PHP Warning: file_put_contents(/home/user/data//278.json): failed to open stream: Permission denied in /php/utils/SleekDB/SleekDB.php on line 100

Maybe, update should return FALSE in such case.

Thanks.

Conditions are not reset

Hi. I'm trying to use SleekDB like shown in manual.

$db_codes = \SleekDB\SleekDB::store('bonus_codes', PATH_DB, [
    'auto_cache' => false,
    ]);

$code1 = $db_codes->where('code', '=', $raw_code1)->fetch();
$code2 = $db_codes->where('code', '=', $raw_code2)->fetch();
$codes_all = $db_codes->fetch();

$code1 have one item, like it should. $code2 have 0 items, while it should have 1, $codes_all have 0 items, totally unlike it should.

I have looked through the code and I can see it's because on every -> where() call, local variable conditions[] are appended. Conditions have stacked through the calls, this is why just pure $db_codes->fetch() gives 0 results.

From my understanding, this is not how it's supposed to work. I expect $db_codes->where() not to modify initial $db_codes instance, but maybe create a copy. Or maybe conditions should be reset on every ->fetch() call.

How am I supposed to find items in foreach()? Create a new instance of $db_codes every time?
I have found #4 issue, where you give example code

 $db->store('orders')->insert([
    'order_id' => '92837483',
    'items' => ['coco', 'test', 'foo']
  ]);

If I'd create a new store for every query, that will obviously work. But that's not how you have it in your manual. I'd like to do it like your manual states.

Instead of

$db = new \SleekDB\SleekDB(PATH_DB, ['auto_cache' => false]);
$code1 = $db->store('bonus_codes', PATH_DB, ['auto_cache' => false])->where('code', '=', $raw_code1)->fetch();
$code2 = $db->store('bonus_codes', PATH_DB, ['auto_cache' => false])->where('code', '=', $raw_code2)->fetch();
$codes_all = $db->store('bonus_codes', PATH_DB, ['auto_cache' => false])->fetch();

It should be possible to just

$db = new \SleekDB\SleekDB(PATH_DB, ['auto_cache' => false]);
$db_codes = $db->store('bonus_codes'); // path and options are preserved.
$db_something1 = $db->store('something1'); // path and options are preserved.
$db_something2 = $db->store('something2', ['auto_cache' => true]); // path is preserved, options are overridden.

$code1 = $db_codes->where('code', '=', $raw_code1)->fetch(); // get corresponding raw_code1 item.
$code2 = $db_codes->where('code', '=', $raw_code2)->fetch(); // get corresponding raw_code2 item.
$codes_all = $db_codes->fetch(); // get all items in db.

Help please.

delete status

Would be cool to return the count of deleted records. I do a fetch before to know the number of records that will be deleted.

Extend not possible due to private helper methods

Hello, please consider to make the private helper methods protected. It is not possible to extend SleekDb this way. After setting bootStore and initVariables from private to protected i was able to extend, but also had to copy the whole store method:

class LibreSleekDb extends \SleekDB\SleekDB
{
	public static function store( $storeName = false, $dataDir, $options = false ) {
		if ( !$storeName OR empty( $storeName ) ) throw new \Exception( 'Store name was not valid' );
		$_dbInstance = new LibreSleekDb( $dataDir, $options );
		$_dbInstance->storeName = $storeName;
		// Boot store.
		$_dbInstance->bootStore();
		// Initialize variables for the store.
		$_dbInstance->initVariables();
		return $_dbInstance;
	}

	public function fetch()
	{
		$results = parent::fetch();
		foreach ($results as $key => $result) {
			$results[$key] = (object) $result;
		}
		return $results;
	}
}

Now i can do LibreSleekDb::store('articles', $dataDir);

OR Condition Query

Hi Hasan, I am very exciting about your SleekDB project. I started to using it to build simple headless CMS. And the orWhere is little bit limitating to me. I would like to use construction such as Where(firstCondition)->Or(anotherCondition, anotherOneCondition). I think, actually something like this is not possible to do it in one query. What do you think about the idea?

If you like it, I can do it (but I need a little chance that you will merge it into your project :-D )

Add find methods to new Store class to make the QueryBuilder optional for simple queries.

For simple queries conveniently find documents without the need of QueryBuilder.

Get all documents of a store.

function findAll(): array

Get a single document based on its _id.

function findById($id): array|null

Get one or multiple documents.

function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array|null
  • $criteria
    • ["city" => "london", "age" => "18"]
  • $orderBy
    • ["name" => "asc"]

Get one document.

function findOneBy(array $criteria): array|null
  • $criteria
    • ["city" => "london", "age" => "18"]

Implement predicate-based filters

This would allow to implement any custom filter the user desires alongside with the existing simple filters of where, orWhere, in, etc. Example code would look like:

$db
    ->filter(
        'column', 
        function ($value) { return $value == 0; }
    )->fetch();

Allow to query on read-only file system

Sometimes I need to run some scripts without write permissions on file system and SleekDB throws an exception about that.
So, consider to add a new flag for readonly operations (something like the auto_cache flag), in this case, let the code throw the exception on file_put_contents (for example).

A copy of exception:

PHP Fatal error:  Uncaught Exception: Data directory is not writable at "/home/blah/dataDB/." Please change data directory permission. in /home/blah/SleekDB/traits/helpers.php:27
Stack trace:
#0 /home/blah/php/SleekDB/SleekDB.php(20): SleekDB\SleekDB->init(Array)
#1 /home/blah/php/SleekDB/SleekDB.php(26): SleekDB\SleekDB->__construct('/home/blah...', Array)
#2 /home/blah/php/demo.php(22): SleekDB\SleekDB::store('testLog', '/home/blah...', Array)
#3 {main}
  thrown in /home/blah/php/SleekDB/traits/helpers.php on line 27

Regards.

No default storage location - SleekDB 0.7.1

SleekDB 0.7.1 saves data inside the vendor directory if no custom path was found inside the config file, but it seems to be confusing and a very good chance that the developer would lost all the data while doing a compose update or installation.

The solution would be simpler,

  • Look for a location in the config file, where SleekDB can write data.
  • If no default location was provided in the config file then raise an error.

Feel free to reply to this issue if you have a better plan.

Cache Date in return

It would be awesome to have in the STORE data, to show the cache date if it's returning cached data.

Update multiple records at once

Is it possible to update multiple records at once? My use case is that I need to change one value in several records (in the same store) at once. I tried it in a loop, but that doesn't seem to work as expected.

Return distincted value

Is there an option to fetch distincted single values?

For example $store->select('name')->distinct()->where(...)->fetch();

Optimize delete method of Query class to also be able to return the results

3 Constants for deletion result

// Query class

public funtion delete($returnOption = self::DELETE_RETURN_BOOL): bool|array|int

Contants

DELETE_RETURN_BOOL

Value: 1
Returns true on success and false if nothing found to delete.

DELETE_RETURN_RESULTS

Value: 2
Returns the deleted documents as a two dimensional array on success and an empty array if nothing found to delete.

DELETE_RETURN_COUNT

Value: 3
Returns 0 if nothing found to delete and the count of deleted documents on success.

Insert in nested arrays

Hi,
this is my data :

$json= [
    'id'=>'1',
    'title'=>'#sample',
    'twit'=>['invoke'=>False,'content'=>'testdasdsaffjgkgdjopertop4i5845y478825y43895y498y5984uythiufhgdhgf'],
];

i want to add more data to the tweet collection
The tweet itself includes a collection of tweets related to one Hashtag !
like this example ( after insert )

$json= [
    'id'=>'1',
    'title'=>'#sample',
    'twit'=>[
        ['invoke'=>False,'content'=>'12334234234'],
        ['invoke'=>False,'content'=>'45767676756756'],
        ['invoke'=>False,'content'=>'6575676756756f'],
        ['invoke'=>False,'content'=>'56756765756756756'],
    ],
];

Looks like this feature has not been implemented yet, please add these feature! thanks

Great work! (suggestion, not an issue)

Looks like a mini_mongo db :-)
Each record is stored in a json file with an indexed value starting from 1. It will be nice to have a custom prefix to this... dynamically.

For example, i would prefer to prefix it with a username so that whenever i am in a hurry, i can open the related .json file straightaway instead of doing a find or instead of using sleekdb to find it

Is this doable?

Better search algorithm

Hi,

first of all great work and project.

It looks like the build in similar_text() function is not perfect.

I just made some little tests, but it looks like the returned percentages are not always what I expected.

It would be awesome if we can add some his string normalization:
https://stackoverflow.com/questions/35923029/similar-text-percentage-in-php

I have implemented several algorithms that will search for duplicates and they can be quite similar.

The approach I am usually using is the following:

    normalize the strings
    use a comparison algorithm (e.g. similar_text, levenshtein, etc.)

It appears to me that in implementing step 1) you will be able to improve your results drastically.

Example of normalization algorithm (I use "Sponsors back away from Sharapova after failed drug test" for the details):

1) lowercase the string

-> "sponsors back away from sharapova after failed drug test"

2) explode string in words

-> [sponsors, back, away, from, sharapova, after, failed, drug, test]

3) remove noisy words (like propositions, e.g. in, for, that, this, etc.). This step can be customized to your needs

-> [sponsors, sharapova, failed, drug, test]

4) sort the array alphabetically (optional, but this can help implementing the algorithm...)

-> [drug, failed, sharapova, sponsors, test]

Applying the very same algorithm to your other string, you would obtain:

[australian, drugs, failed, maria, open, sharapova, test]

This will help you elaborate a clever algorithm. For example:

    for each word in the first string, search the highest similarity in the words of the second string
    accumulate the highest similarity
    divide the accumulated similarity by the number of words

And/Or add some math from MySQLs Fulltext-Search score algorithm:
https://dba.stackexchange.com/questions/111738/mysql-match-relavancy-score

Relevance is computed based on the number of words in the row, the number of unique words in that row, the total number of words in the collection, and the number of documents (rows) that contain a particular word.

Add custom ranking key property to result

That ranking key can then be used in orderBy to sort the result.

Updating Cache Handling

Overview of current state

For caching the getCacheToken method is used, which generates a md5 hash out of the query parameters.

Users can interact with Caching by using the following methods:

  • makeCache()
  • disableCache()
  • useCache()
  • deleteCache()
  • deleteAllCache()

makeCache

Re-generate the cache for the query.

disableCache

Disable cache for the query.

useCache

Re-use existing cache or generate if it doesn't exists.

deleteCache

Delete cache for the current query.

deleteAllCache

Delete all cache of current store.

New Cache Handling

We could split/ separate the cache token into two parts with for example a dot:

  • First Part: Query
  • Second Part: File Content

MD5 and SHA hashes in raw form are binary, however their common representation is a hex-encoded string, which contains characters [a-fA-F0-9].

So if this is what you meant, then characters G-Z, g-z are "excluded".

https://stackoverflow.com/questions/12618321/what-pool-of-characters-do-md5-and-sha-have

New private methods

getQueryCacheToken

Returns first part of cacheToken, generated with query.

getContentCacheToken

Returns second part of cacheToken, generated with content.

getCachedFiles

Returns an array with paths to cached files. Either by QueryCacheToken or ContentCacheToken.

deleteCacheBy

Receives the ContentCache or QueryCache and uses the getCachedFiles to delete all files.

Updates

We will have to update all methods mentioned above to use the QueryCacheToken.
Also we need to update the following methods:

  • update()
  • delete()

Deeper look

getCachedFiles

We can use PHP`s glob function https://www.php.net/manual/de/function.glob.php to find the files.

useCache

We will look for cached files with the QueryCache and the getCachedFiles method. If there are non we will generate a new cache file.

update

Before updating the content we will delete all cache files considering the old content with the ContentCache of the old content and by using the deleteCacheBy method.

delete

Before deleting a file we will delete all cache files considering the old content with the ContentCache of the old content and by using the deleteCacheBy method.

Deprecation

We could mark the following methods as deprecated because they are no longer needed:

  • makeCache
  • deleteCache

Conclusion

Now the user of SleekDB just has to use useCache or the auto_cache configuration when generating a new store to activate caching and don't has to think about cache handling.

If the content changes the cache of it will be deleted.
If a file gets deleted the cache will be deleted too.

This solution would be compatible with old code using SleekDB.

Strange behavior

require_once "../SleekDB/SleekDB.php"; $db = new \SleekDB\SleekDB( "../mydb" ); $ordersStore = $db->store('orders'); $tasksStore = $db->store('tasks'); $workersStore = $db->store('workers');

When I print_r $ordersStore or $tasksStore it actually prints workersStore
If i comment $workersStore variable assign it will print tasksStore and so on.

High load distributed version

I love this project, I have been exploring it all day and worse case it will serve as a base for what I need.

I am really looking for ideas or suggestions on how to use this in the best case. I am working on a large indexing system to store and index pages as text. It will store longer strings in a "database" with a key for easy lookup and fetching and page content down to sentences can be split and stored in multiple "stores". The only downside I am having is access across multiple servers talking to the data at once, as far as I can see as it's not an outside access database this might be hard.

Any ideas or is this something on the roadmap? I am looking at this route as search will be really low and highly cached (woot already a check in this), and most data once generated will be cached, but I am looking to put 10-60k inserts a second.

Other then that this is amazing and I will be messing with it for the next week.

Use "results" property instead of returning data from methods

  • findStoreDocuments()
  • reGenerateCache()
  • useExistingCache()
    This above method should use $this->results property to set the data directly instead of returning the data to the fetch() method!

In the fetch method it will only return $this->results.

JOIN feature

I have started working on JOIN feature. This is how the query would look like:

  $articleStore = \SleekDB\SleekDB::store('article', './sleekdb_test_scripts');
  $userStore = \SleekDB\SleekDB::store('user', './sleekdb_test_scripts');

  $users = $userStore
      ->join(function ($user) use ($articleStore) {
          return $articleStore->where('author', '=', $user['_id']);
      }, 'articles')
      ->fetch();

Code lives in feature/join branch.

Let me know your thoughts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.