
Green Barrel
ORM-like API MongoDB for Rust
To simulate fields of type ForeignKey and ManyToMany, a simplified alternative (Types of selective fields with dynamic addition of elements) is used.
- Support for GreenPanel is temporarily unavailable.

Attention
MongoDB tested on version 4.4
- Support for GreenPanel is temporarily unavailable.
Requirements
Install mongodb (if not installed)
```shell
Ubuntu, Mint:
$ sudo apt install mongodb
OR
Ubuntu 20.04, Mint 20.x:
$ sudo apt update
$ sudo apt install dirmngr gnupg apt-transport-https ca-certificates
$ wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
$ sudo add-apt-repository 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse'
$ sudo apt update
$ sudo apt install mongodb-org
$ sudo systemctl enable --now mongod
For check
$ mongod --version
$ mongo --eval 'db.runCommand({ connectionStatus: 1 })'
$ reboot
#
Configuration file:
$ sudo nano /etc/mongod.conf
#
Systemd:
$ sudo systemctl status mongod
$ sudo systemctl start mongod
$ sudo systemctl stop mongod
$ sudo systemctl restart mongod
$ sudo systemctl enable mongod
$ sudo systemctl disable mongod
#
Uninstall:
$ sudo systemctl stop mongod
$ sudo systemctl disable mongod
$ sudo apt --purge remove mongodb* # OR (for mongodb-org) - $ sudo apt --purge remove mongodb-org**
$ sudo rm -r /var/log/mongodb
$ sudo rm -r /var/lib/mongodb
$ sudo rm -f /etc/mongod.conf
$ sudo apt-add-repository --remove 'deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse' # for mongodb-org
$ sudo apt update
```
Usage:
Basic Example
Model parameters
( all parameters are optional )
| Parameter: | Default: | Description: |
| :------------------ | :----------- | :--------------------------------------------------------------------------------------------------- |
| dbquerydocslimit | 1000 | limiting query results. |
| isadddoc | true | Create documents in the database. false - Alternatively, use it to validate data from web forms. |
| isupdoc | true | Update documents in the database. |
| isdeldoc | true | Delete documents from the database. |
| ignorefields | empty string | Fields that are not included in the database (separated by commas). |
| isuseaddvalid | false | Allows additional validation - impl AdditionalValidation for ModelName. |
| isuse_hooks | false | Allows hooks methods - impl Hooks for ModelName. |
Field types
See documentation -fields.
Methods for Developers
Main
- hash()
- set_hash()
- obj_id()
- setobjid()
- created_at()
- updated_at()
Caching
- meta()
- new()
- json()
- updatedynfield()
Control
AdditionalValidation
Hooks
- pre_create()
- post_create()
- pre_update()
- post_update()
- pre_delete()
- post_delete()
QCommons
- aggregate()
- count_documents()
- delete_many()
- delete_one()
- distinct()
- drop()
- estimateddocumentcount()
- findmanytodoclist()
- findmanyto_json()
- findoneto_doc()
- findoneto_json()
- findoneto_instance()
- findoneand_delete()
- collection_name()
- namespace()
QPaladins
- check()
- save()
- delete()
- createpasswordhash()
- verify_password()
- update_password()
Fixtures
Changelog
- v1.3.5-beta Improved dates checking.
- v1.3.2-beta Fixed basic example and updated readme file.
- v1.3.0-beta Transition to asynchronous code.
- v1.2.0-beta Updated dependency mongodb to version 2.
- v1.1.14-beta Rename Model parameters: isadddocs, isupdocs, isdeldocs to isadddoc, isupdoc, isdeldoc.
- v1.1.9-beta Tests updated and README.md file updated.
- v1.1.0-beta Added support for Fixtures - To populate the database with pre-created data.
- v1.0.16-beta Added parameter targetdir for field types InputFile and InputImage._
- v1.0.10-beta Updated comments for dynamic field types.
- v1.0.8-beta The 150 character limit has been removed from the updatedynfield() method.
- v1.0.7-beta The administrator module has been removed and moved to a separate project.
- v1.0.0-beta Not compatible with green-barrel v0.x.x and metamorphose v0.x.x
- v0.12.14 Fixed README.md.
- v0.12.8 The dbupdatedynwidgets method has been renamed to updatedynwig and has been heavily modernized. See documentation: green-barrel > models > caching > Caching > updatedynwig._
- v0.12.4 Made two critical fixes to the check method and updated unit tests.
- v0.12.0 Deep modernization of the inputdata module and related modules._
- v0.11.4 outputdata module moved from widgets directory to models._
- v0.11.3 administrator module moved from dbquery api directory to models._
- v0.11.2 Renamed methods in trait Administrator - instanceforadmin to actixinstanceforadmin and resultforadmin to actixresultforadmin.
- v0.11.1 Added enum OutputDataAdmin for easier registration of Models in the administration panel.
- v0.11.0 Added trait Administrator for easier registration of Models in the administration panel.
- v0.10.100 Added new type UpdatePassword to enum OutputData. Updated documentation.
- v0.10.97 Added field attribute check - pattern.
- v0.10.95 For optimization, the outputdatatohtml mediator function has been excluded._
- v0.10.94 Added the ability to customize html code for web forms. See documentation: mangoorm > widgets > generatehtml > GenerateHtml > generatehtml() > source._
- v0.10.93 Rename trait ToModel to Main.
- v0.10.92 Added arguments for tohtml methods. Arguments: urlaction, httpmethod and enctype. See documentation: mangoorm > widgets > outputdata > OutputData > tohtml.
- v0.10.90 For the OutputData enum, the outputdatatohtml method is extended with the tohtml alias.
- v0.10.20 Removed the ability to change the createdat field of a model instance._
- v0.10.0 The createdat and updatedat fields are automatically added to the Model. The widget type is inputDateTime and disabled = true, ishide = true. Updated README.md. Updated documentation._
- v0.9.4-v.0.9.15 Import optimized.
- v0.9.0 Added hook methods. See documentation: mangoorm > models > hooks > Hooks._
- v0.8.26 Add findonetowig method. See documentation: mangoorm > models > dbqueryapi > commons > QCommons.
- v0.8.0 Deep modernization of common.rs and outputdata.rs modules. See documentation: mangoorm > models > dbqueryapi > commons > QCommons and mangoorm > models > outputdata > Converters.
- v0.7.4 Updated README.md, added model attributes.
- v0.7.0 *Added the ability to use the hash field in inputSlug - slug_sources: r#"["hash", "username"]"#*
- v0.6.30 Renamed methods: wig(), json(), html() -> towig(), tojson(), tohtml(). Updated README.md. Updated documentation. Updated versions of dependencies._
- v0.6.16 Renamed the Forms module to Widgets.
- v0.6.15 Updating by version of dependencies.
- v0.6.10 Updated test for dynamic widgets.
- v0.6.7 Removed hiddenSlug field.
- v0.6.6 Added ishide parameter for Widgets._
- v0.6.5 In the check() method, errors are redirected to the console, for fields of hidden type.
- v0.6.4 Fixes for fields of slug type.
- v0.6 1) Added inputSlug and hiddenSlug fields. 2) Fix - Added fields of hidden type to migration.
- v0.5.4 Optimization for creating thumbnails, for default images.
- v0.5.3 Improved cleaning of orphaned files.
- v0.5 Support for the Form macro has been removed.
License