hema/mongo_transaction
最新稳定版本:1.5
Composer 安装命令:
composer require hema/mongo_transaction
包简介
adding transaction feature to jenssegers/mongodb
README 文档
README
Laravel Mongo Transaction
How to Install:
Assuming you have already installed composer require jenssegers/mongodb and configured it fully according to the documentation (https://packagist.org/packages/jenssegers/mongodb), now run this to install mongo-transactions:
composer require hema/mongo_transaction
In your Model Or BaseModel Use The Flowing Model :
use Hema\MongoTransaction\Transactions\Eloquent\Model
Instead of Jenssegers Model
use use Jenssegers\Mongodb\Eloquent\Model
Note :
-
this package created for specific business needs. so, it's may not fit your needs 100%. but you still can fork it and extend or modify it.
-
you've to enable replica set in Mongo.
~$ sudo mongod --replSet "rs0"
and then run mongo
~$ sudo mongo
now you can use transaction this way :
use Hema\MongoTransaction\Transactions\Transaction
* Transaction::start(); // ........ A bunch of other db operations * Transaction::commit(); // ........ commit when success * Transaction::rollback(); // ........ Or rollback when error occure
Now You Can Use These Methods with transaction
* create(); * insert(); * update(); * delete(); * forceDelete(); * restore() * increment(); * decrement(); * trash(); //custome method for soft-delete * remove(); //custome method for hard-delete
Example :
Transaction::start(); try { User::insert($some_data); Profile::insert($some_data); Transaction::commit(); return 'done'; } catch (\Exception $e) { Transaction::rollback(); return $e->getMessage(); }
统计信息
- 总下载量: 200
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-10