Skip to content
/ fsdb Public

The ultimate way to access database for prototyping, on top of the filesystem.

Notifications You must be signed in to change notification settings

abbychau/fsdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FSDB

The ultimate prototyping database on top of the filesystem.

Introduction

I am always thinking what is the best way to implement a backend, especially a RESTful one.

Obviously, PHP is the best choice to me, just because of its Associative Array and interaction with json_encode/json_decode, but nothing else.

Usually, I was doing in this way:

//WRITE STATES
register_shutdown_function(function () {
    global $LOCK_FILE;
    foreach (STATES as $v) {
        global $$v;
        $gstate[$v] = $$v;
    }
    file_put_contents($STATE_FILE, marshall($var), LOCK_EX);
    FileLocker::unlockFile($LOCK_FILE);
});

However, this is not the best way to do it, becasuse serialization + unserialization for each request is very slow.

And also, data is unable to be accessed by multiple requests.

So, you may use frameworks like swoole or workerman, so to maintain the state of the system in an array, and then serialize it to json and unserialize it when needed. The array can then be protected by a mutex.

However, does it really solve the problem? No, because serialization + unserialization is still slow; and also, data is still unable to be accessed by multiple requests.

To make our life easier, I would like to have a database that can be accessed like this:

$db['1'] = '1';
$db['2'] = ['testing' => '3'];
$db['2'] = [3, 2, 1, 4];
$db['3'] = ['asdf'];
echo json_encode($db);

foreach ($db as $k => $v) {
    echo `$k\n`;
    var_dump($v);
}

echo $db['2'][3];

FSDB implemented \ArrayAccess, \JsonSerializable, \Iterator and store the great assoc array in files in synchronous manner.

Winning hackathons can never be easier.

Usage

Precautions

  • current() of \Iterator will lead to iteration of a directory
  • There may induce a lot of files in the database directory (may use an VFS to solve this problem?)

Readiness

!!! IMPORTANT !!!

NOT READY YET!

About

The ultimate way to access database for prototyping, on top of the filesystem.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages