34 stable releases

1.7.8 Sep 7, 2023
1.6.7 Jun 18, 2023
1.3.25-beta Dec 21, 2022
1.2.1-beta Nov 27, 2022
0.12.24 Aug 10, 2022

#147 in Database interfaces


Used in admin-gp

MIT/Apache

395KB
7K SLoC

Logo

Green Barrel

ORM-like API MongoDB for Rust

For simulate relationship Many-to-One and Many-to-Many, a simplified alternative (Types of selective fields with dynamic addition of elements) is used.

crates.io crates.io Green Barrel on docs.rs crates.io crates.io

Attention

MongoDB tested on versions 4.2, 4.4, 5.0, 6.0

  • Support for GreenPanel is temporarily unavailable.

Requirements

Install mongodb (if not installed)

Follow the link Install MongoDB.

Usage:

Basic Example

Tests for examples

Model parameters

( all parameters are optional )

Parameter: Default: Description:
db_query_docs_limit 1000 limiting query results.
is_add_doc true Create documents in the database. false - Alternatively, use it to validate data from web forms.
is_up_doc true Update documents in the database.
is_del_doc true Delete documents from the database.
ignore_fields empty string Fields that are not included in the database (separated by commas).
is_use_addition false Allows methods for additional actions and additional validation.
is_use_hooks false Allows hooks methods - impl Hooks for ModelName.

Field types

See documentation -fields.

Methods for Developers

Main

  • hash()
  • set_hash()
  • obj_id()
  • set_obj_id()
  • created_at()
  • updated_at()

Caching

  • meta()
  • new()
  • json()
  • update_dyn_field()

Control

  • custom()

Addition

  • add_actions()
  • add_validation()

Hooks

  • pre_create()
  • post_create()
  • pre_update()
  • post_update()
  • pre_delete()
  • post_delete()

QCommons

  • create_index()
  • drop_index()
  • create_indexes()
  • drop_indexes()
  • aggregate()
  • count_documents()
  • delete_many()
  • delete_one()
  • distinct()
  • drop()
  • estimated_document_count()
  • find_many_to_doc_list()
  • find_many_to_json()
  • find_one_to_doc()
  • find_one_to_json()
  • find_one_to_instance()
  • find_one_and_delete()
  • collection_name()
  • namespace()

QPaladins

  • check()
  • save()
  • delete()
  • create_password_hash()
  • verify_password()
  • update_password()

Fixtures

  • run_fixture()

Changelog

View the change history.

License

This project is licensed under the MIT and Apache Version 2.0

Dependencies

~43–58MB
~1M SLoC