Git Product home page Git Product logo

flywheel's People

Contributors

4d47 avatar alessandrofrancesconi avatar astoltz avatar brzuchal avatar caseycs avatar jamesmoss avatar joeholdcroft avatar mattketmo avatar n-peugnet avatar remo 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

flywheel's Issues

Document ID doesn't automatically generated

I've got thi error when trying to create a document without having to set the id:

Type: Exception
Message: `` is not a valid document ID.
File: /path/to/vendor/jamesmoss/flywheel/src/JamesMoss/Flywheel/Repository.php
Line: 157

I'm using v0.4.0

Query not returning result when using first()

Version: flywheel==0.4.4

I have encountered with an empty result issue when using "first" function on flywheel query object, but got result when using the "all" function (with the same query)

DB schema:


class User(Modal):
__metadata__ = {
        '_name': 'test_table',
        'global_indexes': [
            GlobalIndex('name-age-index', 'name', 'age_min').throughput(5, 3),
        ]
    }
name = Field(hash_key=True)
age_min = Field(data_type=int)      # OPTIONAL
age_max = Field(data_type=int)       # OPTIONAL

Query:

Return None: engine.query(User).filter(User.name == 'Erik', User.age_min <= age, User.age_max >= 18).first()

Return value: engine.query(User).filter(User.name == 'Erik', User.age_min <= age, User.age_max >= 18).all()

Tests don't comply with PSR-0 autoloading standard

Hey ๐Ÿ‘‹
Thanks for this useful package, I'm using it in some of my projects :)

Now on to the issue:
When generating the autoload files with composer I encountered these two deprecation notices:

Deprecation Notice: Class JamesMoss\Flywheel\NestedRespositoryTest located in ./vendor/jamesmoss/flywheel/test/JamesMoss/Flywheel/NestedRepositoryTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201

Deprecation Notice: Class JamesMoss\Flywheel\RespositoryTest located in ./vendor/jamesmoss/flywheel/test/JamesMoss/Flywheel/RepositoryTest.php does not comply with psr-0 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201

Using composer v1.10.1 (latest). Just wanted to let you know...

Select returned fields

It might be helpful to be able to query->select(fields) to be returned to prevent overhead.

Wrong orderBy when comparing integers

Hello,

I just found that the order in inversed when using orderBy with a field which contains an integer.

Example:

<?php
require __DIR__.'/vendor/autoload.php';

use JamesMoss\Flywheel\Config;
use JamesMoss\Flywheel\Document;
use JamesMoss\Flywheel\Repository;

$rootDir = sys_get_temp_dir().'/poc_flywheel_orderBy_'.rand();
$config = new Config($rootDir);
$repo = new Repository('posts', $config);

$posts = [
    new Document(['title' => 'AAA', 'number' => 1]),
    new Document(['title' => 'BBB', 'number' => 2]),
    new Document(['title' => 'CCC', 'number' => 3]),
];

foreach ($posts as $post) {
    $repo->store($post);
}

echo "Order by title ASC:\n";
$posts = $repo->query()->orderBy('title ASC')->execute();
foreach ($posts as $post) {
    echo "{$post->title} - {$post->number}\n";
}

echo PHP_EOL;

echo "Order by number ASC:\n";
$posts = $repo->query()->orderBy('number ASC')->execute();
foreach ($posts as $post) {
    echo "{$post->title} - {$post->number}\n";
}

It displays:

Order by title ASC:
AAA - 1
BBB - 2
CCC - 3

Order by number ASC:
CCC - 3
BBB - 2
AAA - 1

The two list should be the same but the second one is inversed.

where('IN') not working

I think there is a typo in the code example, but even when changed it gives an error.

Both examples give errors

(seems a comma is missing after 'IN')

$posts = $repo->query()
    ->where('__id', 'IN' array(1, 7, 8))
    ->execute();

$posts = $repo->query()
    ->where('__id', 'IN', array(1, 7, 8))
    ->execute();

produces: Uncaught InvalidArgumentException: Unknown operator `IN`.

Test running failed (phpunit)

Hello, thank you for the FlyWheel ! It's very usefull and work like a charm.

I planed to correct the miss of 'IN' in the $operators array in the Predicate.php file and add the coma in the readme.

I also planed to add a listAllId() function, generating a array of all the __id in the database folder only by checking the folder without needing to read the jsons.

But as I forked the repo, I had problem while running the tests.

PS C:\Users\Utilisateur\Documents\web\fork_flywheel>
PS C:\Users\Utilisateur\Documents\web\fork_flywheel> composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Package operations: 11 installs, 0 updates, 0 removals
  - Installing mikey179/vfsstream (v1.2.0): Loading from cache
  - Installing mockery/mockery (dev-master d92a1ae): Cloning d92a1ae149 from cache
  - Installing mustangostang/spyc (dev-master eba310c): Cloning eba310c268 from cache
  - Installing phpunit/php-token-stream (1.2.1): Loading from cache
  - Installing symfony/yaml (v2.4.2): Loading from cache
  - Installing phpunit/php-text-template (1.2.0): Loading from cache
  - Installing phpunit/phpunit-mock-objects (1.2.3): Loading from cache
  - Installing phpunit/php-timer (1.0.5): Loading from cache
  - Installing phpunit/php-file-iterator (1.3.4): Loading from cache
  - Installing phpunit/php-code-coverage (1.2.15): Loading from cache
  - Installing phpunit/phpunit (3.7.31): Loading from cache
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/phpunit suggests installing phpunit/php-invoker (>=1.1.0,<1.2.0)
Generating autoload files
PS C:\Users\Utilisateur\Documents\web\fork_flywheel> phpunit
PHPUnit 3.7.31 by Sebastian Bergmann.

Configuration read from C:\Users\Utilisateur\Documents\web\fork_flywheel\phpunit.xml.dist

S......PHP Fatal error:  Declaration of PHPUnit_Framework_Comparator_DOMDocument::assertEquals($expected, $actual, $delta = 0, $canonicalize = false, $ignoreCase = false) must be compatible with PHPUnit_Framework_Comparator_Object::assertEquals($expected, $actual, $delta = 0, $canonicalize = false, $ignoreCase = false, array &$processed = Array) in C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\Comparator\DOMDocument.php on line 114
PHP Stack trace:
PHP   1. {main}() C:\xampp\php\phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() C:\xampp\php\phpunit:46
PHP   3. PHPUnit_TextUI_Command->run() C:\xampp\php\pear\PHPUnit\TextUI\Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() C:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
PHP   5. PHPUnit_Framework_TestSuite->run() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\TextUI\TestRunner.php:348
PHP   6. PHPUnit_Framework_TestSuite->run() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestSuite.php:704
PHP   7. PHPUnit_Framework_TestSuite->runTest() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestSuite.php:745
PHP   8. JamesMoss\Flywheel\DocumentTest->run() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestSuite.php:775
PHP   9. PHPUnit_Framework_TestResult->run() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestCase.php:783
PHP  10. JamesMoss\Flywheel\DocumentTest->runBare() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestResult.php:648
PHP  11. JamesMoss\Flywheel\DocumentTest->runTest() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestCase.php:838
PHP  12. ReflectionMethod->invokeArgs() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestCase.php:982
PHP  13. JamesMoss\Flywheel\DocumentTest->testGettingId() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestCase.php:982
PHP  14. PHPUnit_Framework_Assert::assertEquals() C:\Users\Utilisateur\Documents\web\fork_flywheel\test\JamesMoss\Flywheel\DocumentTest.php:16
PHP  15. PHPUnit_Framework_Assert::assertThat() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\Assert.php:475
PHP  16. PHPUnit_Framework_Constraint_IsEqual->evaluate() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\Assert.php:2134
PHP  17. PHPUnit_Framework_ComparatorFactory::getDefaultInstance() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\Constraint\IsEqual.php:149
PHP  18. PHPUnit_Framework_ComparatorFactory->__construct() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\ComparatorFactory.php:95
PHP  19. spl_autoload_call() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\ComparatorFactory.php:83
PHP  20. Composer\Autoload\ClassLoader->loadClass() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\ComparatorFactory.php:83
PHP  21. Composer\Autoload\includeFile() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\composer\ClassLoader.php:322

Fatal error: Declaration of PHPUnit_Framework_Comparator_DOMDocument::assertEquals($expected, $actual, $delta = 0, $canonicalize = false, $ignoreCase = false) must be compatible with PHPUnit_Framework_Comparator_Object::assertEquals($expected, $actual, $delta = 0, $canonicalize = false, $ignoreCase = false, array &$processed = Array) in C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\Comparator\DOMDocument.php on line 114

Call Stack:
    0.2122     377296   1. {main}() C:\xampp\php\phpunit:0
    0.2267     545080   2. PHPUnit_TextUI_Command::main() C:\xampp\php\phpunit:46
    0.2268     547384   3. PHPUnit_TextUI_Command->run() C:\xampp\php\pear\PHPUnit\TextUI\Command.php:129
    0.4084    2401424   4. PHPUnit_TextUI_TestRunner->doRun() C:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
    0.4135    2571920   5. PHPUnit_Framework_TestSuite->run() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\TextUI\TestRunner.php:348
    0.4350    2951440   6. PHPUnit_Framework_TestSuite->run() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestSuite.php:704
    0.4351    2951440   7. PHPUnit_Framework_TestSuite->runTest() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestSuite.php:745
    0.4351    2951440   8. JamesMoss\Flywheel\DocumentTest->run() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestSuite.php:775
    0.4351    2951440   9. PHPUnit_Framework_TestResult->run() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestCase.php:783
    0.4351    2951440  10. JamesMoss\Flywheel\DocumentTest->runBare() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestResult.php:648
    0.4354    2989576  11. JamesMoss\Flywheel\DocumentTest->runTest() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestCase.php:838
    0.4354    2989832  12. ReflectionMethod->invokeArgs() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestCase.php:982
    0.4354    2989840  13. JamesMoss\Flywheel\DocumentTest->testGettingId() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\TestCase.php:982
    0.4362    2999672  14. PHPUnit_Framework_Assert::assertEquals() C:\Users\Utilisateur\Documents\web\fork_flywheel\test\JamesMoss\Flywheel\DocumentTest.php:16
    0.4366    3012112  15. PHPUnit_Framework_Assert::assertThat() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\Assert.php:475
    0.4366    3012112  16. PHPUnit_Framework_Constraint_IsEqual->evaluate() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\Assert.php:2134
    0.4370    3025160  17. PHPUnit_Framework_ComparatorFactory::getDefaultInstance() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\Constraint\IsEqual.php:149
    0.4370    3025248  18. PHPUnit_Framework_ComparatorFactory->__construct() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\ComparatorFactory.php:95
    0.4403    3092160  19. spl_autoload_call() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\ComparatorFactory.php:83
    0.4403    3092224  20. Composer\Autoload\ClassLoader->loadClass() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\phpunit\phpunit\PHPUnit\Framework\ComparatorFactory.php:83
    0.4403    3092224  21. Composer\Autoload\includeFile() C:\Users\Utilisateur\Documents\web\fork_flywheel\vendor\composer\ClassLoader.php:322

I would like to verify my fork using your test but I don't know how to fix this. Tell me if you can fix it before I propose a merge.

Thank you for your work

Bye

Vincent

Results->first fails: undefined offset

When a query has a where, the document array offsets aren't reset. This causes first (which directly calls for offset 0) to fail to return the first document. results->first() should call current($this->documents) instead and query->where should create a new array of successful values rather than striping/changing the original.

Deeper JSON property access

Currently one cannot query, order by, etc any property that isn't at the top level of a json doc. While this works fine for simple docs, a way to access deeper properties would be nice.

Multiple orderBy

I'm running constantly in the situation where I need to order twice. Is there any chance this will be added as feature?

Update version in README

Update install in README

"require": {
    "jamesmoss/flywheel": "0.4.*"
}

I have just installed the package and I get an error if I use 0.1.

Great package!!

Project Status?

This is not an issue. I'm considering using this for one of my projects, and would like to know if this project has been abandoned? I see a decent todo list, however most of the commits are very old. And if this project has gone stale because of better alternatives, just let me know. Thanks.

Undefined property & Query.php

If a property isn't defined in a document that is being queried upon, it should assume it is null (which works perfectly). However, currently it will cause a PHP notice on line 93 of Query.php because you aren't checking the property exists before trying to access it.

Just add the @ operator to the beginning of that line to shut the "error" up or validate the property exists before accessing it.

JSON decode issue when querying database

Version is 0.44 running on python 3.43 under Windows 7
The db structure is:

class scrobble(Model):
artist = Field(hash_key=True)
ts = Field(data_type=datetime, range_key=True)

Works fine when database is queried through boto or when exploring through the DynamoDB Web interface

However, all queries are throwing an Exception as follows:

>>> z = engine(scrobble).filter(artist="Lucinda Williams")
>>> z.first()
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\site-packages\flywheel\query.py", line 155, in first
attributes=attributes, filter_or=filter_or):
  File "C:\Python34\lib\site-packages\flywheel\query.py", line 80, in gen
yield self.model.ddb_load_(self.engine, result)
  File "C:\Python34\lib\site-packages\flywheel\models.py", line 458, in ddb_load_
obj.set_ddb_val_(key, val)
  File "C:\Python34\lib\site-packages\flywheel\models.py", line 450, in set_ddb_val_
setattr(self, key, Field.ddb_load_overflow(val))
  File "C:\Python34\lib\site-packages\flywheel\fields\__init__.py", line 265, in ddb_load_overflow
return json.loads(val)
  File "C:\Python34\lib\json\__init__.py", line 318, in loads
return _default_decoder.decode(s)
  File "C:\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

Empty data object returned if json_decode fails

This library returns an empty document if PHP cannot decode the json data. One reason this would happen is a race condition between reads and writes since atomic writes are not used.

I'll submit a pull request in a couple minutes.

Query result with non consecutive array keys

When I use a 'where' clause in a query:

        $result = $this->repository->query()
            ->where('id', '==', $id)
            ->execute();

Result array has no consecutive integer keys because array_filter keeps the original keyfor each array value.

So when I use $result->first() method an exception is thrown becuase 0 offset does not exist:

    public function first()
    {
        return !empty($this->documents) ? $this->documents[0] : false;
    }

The problem is documents[0] does not exist if the filter removes the first element in the array.

I have applied this quick patch to Query class:

    public function execute()
    {
        $documents = $this->repo->findAll();

        // DEBUG
        //var_dump($documents);

        if ($this->where) {
            list($field, $operator, $predicate) = $this->where;
            $documents = array_filter($documents, function ($doc) use ($field, $operator, $predicate) {
                $value = $doc->{$field};

                switch (true) {
                    case ($operator === '==' && $value == $predicate): return true;
                    case ($operator === '===' && $value === $predicate): return true;
                    case ($operator === '>'  && $value >  $predicate): return true;
                    case ($operator === '>=' && $value >= $predicate): return true;
                    case ($operator === '<'  && $value <  $predicate): return true;
                    case ($operator === '>=' && $value >= $predicate): return true;
                }

                return false;
            });

            $reindexKeysDocuments = array();
            foreach($documents as $document) {
                $reindexKeysDocuments[] = $document;
            }
            $documents = $reindexKeysDocuments;
        }

but maybe you could use another array function as array_walk()

Warning: fread(): Length parameter must be greater than 0

I did a test with the given example of the project itself.

the saved files are the size of 442bytes (1kb)

When executing the method "findAll ()", for example it gives the following warning:

Warning: fread (): Length parameter must be greater than 0 in C: \ xampp \ htdocs \ Decolar \ Christine \ class \ vendor \ jamesmoss \ flywheel \ src \ JamesMoss \ Flywheel \ Repository.php on line 92

What I had found was that the fread () function does not read files smaller than 0kb. ref

image

Allow a different class to be used instead of Document

You might sometimes want to have different classes for different types of documents rather than them all being Document. This would be really handy for type hinting etc.

It'd be nice to pass an anonymous function that returns an empty instance of a class that implements some sort of DocumentInterface to the Repository.

Detailed documentation needed

The current code snippets in the readme file give a good overview of how the library works but full documentation with good code examples are needed longer term.

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.