diff --git a/.travis.yml b/.travis.yml index c811007..c4ce01b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,7 @@ env: - PROVIDER=phalcon HAS_CACHING_METADATA_SUPPORT=1 HAS_BATCHING_SUPPORT=0 - PROVIDER=propel HAS_CACHING_METADATA_SUPPORT=0 HAS_BATCHING_SUPPORT=0 - PROVIDER=yii HAS_CACHING_METADATA_SUPPORT=1 HAS_BATCHING_SUPPORT=1 + - PROVIDER=nextrasorm HAS_CACHING_METADATA_SUPPORT=1 HAS_BATCHING_SUPPORT=1 matrix: fast_finish: true @@ -64,6 +65,7 @@ install: - echo 'SHOW VARIABLES LIKE "%version%"' | mysql -u root before_script: + - mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql - echo 'CREATE DATABASE orm_benchmark CHARSET=utf8 COLLATE=utf8_unicode_ci' | mysql -u root - echo "CREATE USER 'enigma'@'%' IDENTIFIED BY 'secret'" | mysql -u root - echo "GRANT ALL PRIVILEGES ON orm_benchmark.* TO 'enigma'@'%' WITH GRANT OPTION" | mysql -u root diff --git a/README.md b/README.md index 366716b..68c2838 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ We have noticed, that running benchmarks on Travis CI is a convenient, but not a * Propel ORM 2.0.0-alpha7 * Yii ActiveRecord 2.0.13.1 * DMS 0.8.2 +* Nextras ORM 3.0.0-rc2 ## What we test @@ -106,6 +107,7 @@ Available providers are: * `doctrine` * `activerecord` * `dms` +* `nextrasorm` Available tests are: @@ -179,6 +181,7 @@ Contributions for new ORMs are more than welcome! If anyone feels that there is * [Doctrine ORM](http://www.doctrine-project.org/projects/orm.html) * [PHP ActiveRecord](http://www.phpactiverecord.org/projects/main/wiki) * [DMS](http://dms-docs.readthedocs.io/en/latest/) +* [Nextras ORM](https://nextras.org/orm/) ## License diff --git a/config/nextrasorm.php b/config/nextrasorm.php new file mode 100644 index 0000000..71504d2 --- /dev/null +++ b/config/nextrasorm.php @@ -0,0 +1,9 @@ + 'mysqli', + 'host' => '127.0.0.1', + 'database' => 'orm_benchmark', + 'username' => 'enigma', + 'password' => 'secret', +]; diff --git a/docker/config/nextrasorm.php b/docker/config/nextrasorm.php new file mode 100644 index 0000000..9c2d5c6 --- /dev/null +++ b/docker/config/nextrasorm.php @@ -0,0 +1,9 @@ + 'mysqli', + 'host' => 'mysql', + 'database' => 'orm_benchmark', + 'username' => 'enigma', + 'password' => 'secret', +]; diff --git a/provider/nextrasorm/Models/Comment.php b/provider/nextrasorm/Models/Comment.php new file mode 100644 index 0000000..444d840 --- /dev/null +++ b/provider/nextrasorm/Models/Comment.php @@ -0,0 +1,17 @@ +=7.0.0", + "nextras/orm": "3.0.0-rc2" + }, + "autoload": { + "psr-4": { + "OrmBench\\NextrasOrm\\": "./" + } + } +} diff --git a/provider/nextrasorm/composer.lock b/provider/nextrasorm/composer.lock new file mode 100644 index 0000000..a863bb5 --- /dev/null +++ b/provider/nextrasorm/composer.lock @@ -0,0 +1,401 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "7ec042aa86e383d25169b1c93f9806b8", + "packages": [ + { + "name": "nette/caching", + "version": "v2.5.6", + "source": { + "type": "git", + "url": "https://github.com/nette/caching.git", + "reference": "1231735b5135ca02bd381b70482c052d2a90bdc9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/caching/zipball/1231735b5135ca02bd381b70482c052d2a90bdc9", + "reference": "1231735b5135ca02bd381b70482c052d2a90bdc9", + "shasum": "" + }, + "require": { + "nette/finder": "^2.2 || ~3.0.0", + "nette/utils": "^2.4 || ~3.0.0", + "php": ">=5.6.0" + }, + "conflict": { + "nette/nette": "<2.2" + }, + "require-dev": { + "latte/latte": "^2.4", + "nette/di": "^2.4 || ~3.0.0", + "nette/tester": "^2.0", + "tracy/tracy": "^2.4" + }, + "suggest": { + "ext-pdo_sqlite": "to use SQLiteStorage or SQLiteJournal" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0", + "GPL-3.0" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "⏱ Nette Caching: library with easy-to-use API and many cache backends.", + "homepage": "https://nette.org", + "keywords": [ + "cache", + "journal", + "memcached", + "nette", + "sqlite" + ], + "time": "2017-08-30T12:12:25+00:00" + }, + { + "name": "nette/finder", + "version": "v2.4.1", + "source": { + "type": "git", + "url": "https://github.com/nette/finder.git", + "reference": "4d43a66d072c57d585bf08a3ef68d3587f7e9547" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/finder/zipball/4d43a66d072c57d585bf08a3ef68d3587f7e9547", + "reference": "4d43a66d072c57d585bf08a3ef68d3587f7e9547", + "shasum": "" + }, + "require": { + "nette/utils": "^2.4 || ~3.0.0", + "php": ">=5.6.0" + }, + "conflict": { + "nette/nette": "<2.2" + }, + "require-dev": { + "nette/tester": "^2.0", + "tracy/tracy": "^2.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0", + "GPL-3.0" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "Nette Finder: Files Searching", + "homepage": "https://nette.org", + "time": "2017-07-10T23:47:08+00:00" + }, + { + "name": "nette/tokenizer", + "version": "v2.3.0", + "source": { + "type": "git", + "url": "https://github.com/nette/tokenizer.git", + "reference": "88373e9f79007245af0ccd8132fde117421723b2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/tokenizer/zipball/88373e9f79007245af0ccd8132fde117421723b2", + "reference": "88373e9f79007245af0ccd8132fde117421723b2", + "shasum": "" + }, + "require": { + "php": ">=5.4" + }, + "conflict": { + "nette/nette": "<2.2" + }, + "require-dev": { + "nette/tester": "~1.7", + "tracy/tracy": "^2.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0", + "GPL-3.0" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "Nette Tokenizer", + "homepage": "https://nette.org", + "time": "2017-09-08T14:16:06+00:00" + }, + { + "name": "nette/utils", + "version": "v2.4.9", + "source": { + "type": "git", + "url": "https://github.com/nette/utils.git", + "reference": "1e08eb4c9d26ae5aedced8260e8b4ed951ee4aa6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/utils/zipball/1e08eb4c9d26ae5aedced8260e8b4ed951ee4aa6", + "reference": "1e08eb4c9d26ae5aedced8260e8b4ed951ee4aa6", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "conflict": { + "nette/nette": "<2.2" + }, + "require-dev": { + "nette/tester": "~2.0", + "tracy/tracy": "^2.3" + }, + "suggest": { + "ext-gd": "to use Image", + "ext-iconv": "to use Strings::webalize() and toAscii()", + "ext-intl": "for script transliteration in Strings::webalize() and toAscii()", + "ext-json": "to use Nette\\Utils\\Json", + "ext-mbstring": "to use Strings::lower() etc...", + "ext-xml": "to use Strings::length() etc. when mbstring is not available" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0", + "GPL-3.0" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.", + "homepage": "https://nette.org", + "keywords": [ + "array", + "core", + "datetime", + "images", + "json", + "nette", + "paginator", + "password", + "slugify", + "string", + "unicode", + "utf-8", + "utility", + "validation" + ], + "time": "2018-02-06T15:40:36+00:00" + }, + { + "name": "nextras/dbal", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/nextras/dbal.git", + "reference": "a662e100ae6908711c5e255d2e4e93a11e363403" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nextras/dbal/zipball/a662e100ae6908711c5e255d2e4e93a11e363403", + "reference": "a662e100ae6908711c5e255d2e4e93a11e363403", + "shasum": "" + }, + "require": { + "php": ">=7.0" + }, + "require-dev": { + "mockery/mockery": "~1.0@dev", + "nette/caching": "~2.2", + "nette/di": "~2.3", + "nette/tester": "~2.0.0", + "phpstan/phpstan-shim": "~0.9.1", + "tracy/tracy": "~2.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Nextras\\Dbal\\": "src/" + }, + "classmap": [ + "src/exceptions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nextras Project", + "homepage": "https://github.com/nextras/dbal/graphs/contributors" + } + ], + "description": "Nextras database abstraction layer", + "homepage": "https://github.com/nextras/dbal", + "keywords": [ + "database", + "dbal", + "nextras" + ], + "time": "2017-12-23T22:30:44+00:00" + }, + { + "name": "nextras/orm", + "version": "v3.0.0-rc2", + "source": { + "type": "git", + "url": "https://github.com/nextras/orm.git", + "reference": "442601564ab9b100729d2b896c2b8f733c860e33" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nextras/orm/zipball/442601564ab9b100729d2b896c2b8f733c860e33", + "reference": "442601564ab9b100729d2b896c2b8f733c860e33", + "shasum": "" + }, + "require": { + "nette/caching": "~2.2", + "nette/tokenizer": "~2.2", + "nette/utils": "~2.4 >=2.4.3", + "nextras/dbal": "~3.0@dev", + "php": ">=7.0" + }, + "require-dev": { + "mockery/mockery": "~1.0@dev", + "nette/bootstrap": "~2.3", + "nette/tester": "~2.0.0", + "phpstan/phpstan-nette": "~0.9", + "phpstan/phpstan-shim": "~0.9.1", + "tracy/tracy": "~2.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Nextras\\Orm\\": "src/" + }, + "classmap": [ + "src/exceptions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nextras Project", + "homepage": "https://github.com/nextras/orm/graphs/contributors" + } + ], + "description": "Nextras Orm framework", + "homepage": "https://github.com/nextras/orm", + "keywords": [ + "database", + "nextras", + "orm" + ], + "time": "2017-12-27T22:21:13+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "nextras/orm": 5 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=7.0.0" + }, + "platform-dev": [] +} diff --git a/src/Provider/Nextrasorm.php b/src/Provider/Nextrasorm.php new file mode 100644 index 0000000..7398ddf --- /dev/null +++ b/src/Provider/Nextrasorm.php @@ -0,0 +1,83 @@ +isUseMetadataCaching()) { + $storage = new FileStorage(DOCROOT . '/storage/nextrasorm/cache'); // metadata will be automatically cached + } else { + $storage = new DevNullStorage(); + } + $cache = new Cache($storage); + $connection = new Connection(require_once DOCROOT . '/config/nextrasorm.php'); + $mapperCoordinator = new DbalMapperCoordinator($connection); + $metadataParserFactory = new MetadataParserFactory(); + + $simpleModelFactory = new SimpleModelFactory($cache, [ + 'posts' => new PostsRepository(new PostsMapper($connection, $mapperCoordinator, $cache)), + 'comments' => new CommentsRepository(new CommentsMapper($connection, $mapperCoordinator, $cache)), + ], $metadataParserFactory); + + $this->model = $simpleModelFactory->create(); + } + + public function create() + { + $post = new Post(); + + $post->title = 'Yet another article: ' . __CLASS__; + $post->body = 'This is the body of the article.'; + $post->createdAt = time(); + $post->updatedAt = time(); + + $this->model->persist($post); + $this->model->flush(); + + assert($post instanceof Post); + assert(is_numeric($post->id)); + assert($post->getPersistedId() > 0); + } + + public function read(int $id) + { + $post = $this->model->getRepositoryForEntity(Post::class) + ->getById([$id]); + + assert($post instanceof Post); + + $comments = $post->comments; + assert($comments->get()->fetch()->body === 'It is a comment.'); + } + + public function readBatch(array $ids) + { + $posts = $this->model->getRepositoryForEntity(Post::class) + ->findBy(['id' => $ids]); + + foreach ($posts as $post) { + assert($post instanceof Post); + $comments = $post->comments; + assert($comments->get()->fetch()->body === 'It is a comment.'); + } + } +} diff --git a/storage/nextrasorm/cache/.gitignore b/storage/nextrasorm/cache/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/nextrasorm/cache/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore