├── .gitignore ├── .travis.yml ├── composer.json ├── license.md ├── readme.md └── src └── Defenestrator └── Laravel5 └── CouchDb ├── CouchDbConnection.php └── CouchDbServiceProvider.php /.gitignore: -------------------------------------------------------------------------------- 1 | # Laravel 5 # 2 | vendor/ 3 | .env 4 | .env.behat 5 | composer.lock 6 | storage/ 7 | Homestead.yaml 8 | Homestead.json 9 | 10 | # NodeJS # 11 | node_modules/ 12 | */node_modules 13 | phantomjsdriver.log 14 | config.js 15 | dump.rdb 16 | npm-debug.log 17 | 18 | # Compiled source # 19 | *.com 20 | *.class 21 | *.dll 22 | *.exe 23 | *.o 24 | *.so 25 | 26 | # Packages # 27 | # it's better to unpack these files and commit the raw source 28 | # git has its own built in compression methods 29 | .7z 30 | .dmg 31 | .gz 32 | .iso 33 | .jar 34 | .rar 35 | .tar 36 | .zip 37 | 38 | # Logs and databases # 39 | *.log 40 | *.sql 41 | 42 | # include sqlite db resource # 43 | */.sqlite 44 | 45 | # JetBrains' IDEA # 46 | .idea/ 47 | *.token 48 | 49 | # OS generated files # 50 | .DS_Store 51 | .DS_Store? 52 | ._* 53 | .Spotlight-V100 54 | .Trashes 55 | ehthumbs.db 56 | Thumbs.db -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - '5.6' 4 | - '7.0' 5 | matrix: 6 | fast_finish: true 7 | sudo: false 8 | before_script: 9 | - phpenv config-rm xdebug.ini 10 | script: 11 | - composer self-update 12 | - composer install --prefer-source 13 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "defenestrator/laravel5-couchdb", 3 | "description": "CouchDB Driver for the Laravel 5 family. Includes doctrine/couchdb as a dependency in composer.json and sets up a Laravel and Eloquent-friendly Service Provider for you. Enjoy!", 4 | "authors": [ 5 | { 6 | "name": "Jeremy Anderson", 7 | "email": "jeremy@copacetic.co" 8 | } 9 | ], 10 | "require": { 11 | "illuminate/database": "^5.2", 12 | "illuminate/support": "^5.2" 13 | }, 14 | "minimum-stability": "dev", 15 | "prefer-stable": true 16 | } 17 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | ## The MIT License (MIT) 2 | 3 | ### Copyright (c) 2016 Jeremy Anderson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # laravel5-couchdb 2 | CouchDB database driver for Laravel 5 3 | 4 | ## Dependencies 5 | 6 | *laravel5-couchdb* uses [doctrine/couchdb](https://github.com/doctrine/couchdb). 7 | 8 | ## Installation 9 | 10 | `composer require defenestrator/laravel5-couchdb`. 11 | 12 | Add the service provider in `app/config/app.php`: 13 | 14 | ```php 15 | 'Defenestrator\Laravel5\Couchdb\CouchdbServiceProvider', 16 | ``` 17 | 18 | When using couchdb connections, Laravel will automatically provide you with the corresponding couchdb objects. 19 | 20 | ## Configuration 21 | 22 | Change your default database connection name in `app/config/database.php`: 23 | 24 | ```php 25 | 'default' => 'couchdb', 26 | ``` 27 | 28 | And add a new couchdb connection: 29 | 30 | ```php 31 | 'couchdb' => array( 32 | 'driver' => 'couchdb', 33 | 'type' => 'socket', 34 | 'host' => 'localhost', 35 | 'ip' => null, 36 | 'port' => 5984, 37 | 'dbname' => 'database', 38 | 'user' => 'username', 39 | 'password' => 'password', 40 | 'logging' => false, 41 | ), 42 | ``` 43 | ## Examples 44 | 45 | ```php 46 | /** 47 | * @var \Defenestrator\Laravel5\Couchdb\CouchdbConnection 48 | */ 49 | $connection = DB::connection('couchdb'); 50 | 51 | /** 52 | * @var \Doctrine\CouchDB\CouchDBClient 53 | */ 54 | $couchdb = $connection->getCouchDB(); 55 | ``` 56 | 57 | **Create/Update/Find Document example** 58 | 59 | ```php 60 | $connection = DB::connection('couchdb'); 61 | $couchdb = $connection->getCouchDB(); 62 | 63 | list($id, $rev) = $connection->postDocument(array('foo' => 'bar')); 64 | $couchdb->putDocument(array('foo' => 'baz'), $id, $rev); 65 | $doc = DB::connection('couchdb')->findDocument($id); 66 | ``` 67 | 68 | All three methods can be called on $connection or $couchdb. 69 | 70 | -------------------------------------------------------------------------------- /src/Defenestrator/Laravel5/CouchDb/CouchDbConnection.php: -------------------------------------------------------------------------------- 1 | config = $config; 20 | $this->db = CouchDBClient::create($config); 21 | } 22 | /** 23 | * Get the CouchDB database object. 24 | * 25 | * @return \Doctrine\CouchDB\CouchDBClient 26 | */ 27 | public function getCouchDB() 28 | { 29 | return $this->db; 30 | } 31 | /** 32 | * 33 | * @return string 34 | */ 35 | public function getDriverName() 36 | { 37 | return 'couchdb'; 38 | } 39 | /** 40 | * Dynamically pass methods to the connection. 41 | * 42 | * @param string $method 43 | * @param array $parameters 44 | * @return mixed 45 | */ 46 | public function __call($method, $parameters) 47 | { 48 | return call_user_func_array(array($this->db, $method), $parameters); 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/Defenestrator/Laravel5/CouchDb/CouchDbServiceProvider.php: -------------------------------------------------------------------------------- 1 | app['db']->extend('couchdb', function($config) 14 | { 15 | return new CouchdbConnection($config); 16 | }); 17 | } 18 | } --------------------------------------------------------------------------------