Coder Social home page Coder Social logo

flat's People

Contributors

mattbit avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flat's Issues

Fatal: SplFileInfo->_bad_state_ex()

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

Missing offset(), count() and all()

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

Enhancement: push()

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"
        ]
    }
}

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.