mattbit / flat Goto Github PK
View Code? Open in Web Editor NEWA flat file database for PHP
A flat file database for PHP
Hey Matt,
I get this Fatal error when a collection is empty using PHP Version 7.0.6.
Fatal error: Uncaught LogicException: The parent constructor was not called: the object is in an invalid state in \src\Flat\Storage\FilesystemIterator.php:45
Stack trace: #0 src\Flat\Storage\FilesystemIterator.php(45): SplFileInfo->_bad_state_ex()
Mattbit\Flat\Collection->find() #5 {main} thrown in \src\Flat\Storage\FilesystemIterator.php on line 45
I am missing some functions like offset(), count(), all() Which will also make somepaging of the results more easily possible. I think it would be worth to has these.
I wrote some code that add count() and all(), but there might be a better implementation.
/src/Flat/Collection.php
public function all()
{
return $this->store->scan();
}
public function count($criteria = NULL)
{
if($criteria) return count($this->onMatch($criteria));
return $this->store->count();
}
/src/Flat/Storage/DocumentStore.php
public function count()
{
return count(glob($this->engine->getpath('*', $this->namespace)));
}
/src/Flat/Storage/FilesystemEngine.php (since path() is protected)
public function getpath($id, $collection, $ext = NULL)
{
return $this->path($id, $collection, $ext);
}
This now enables 2 new functions, where 'postid' in comment is a reference:
$db->collection('posts')->find(['_id' => $id]); // Get Post
$db->collection('comment')->count(['postid' => $id]); // Count Comments for post
$db->collection('posts')->all(); // Get All Posts
Hey Matt. Based on doing some experiments with Flat and looking at MongoDB docs, I could see some value to be able to append to a document key that is an array (what $push does for MongoDB).
See the comments in document below. This type of structure would have benefits in many type of documents.
{
"_doc": {
"type": "posts",
"title": "A first Flat document by Steve",
"published": true,
"_user": "5a2d77a131dab",
"_id": "5a2d7885abd59",
"_comments": [
"5a2d8c5854d38",
"5a2d8c8936a28"
]
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.