mongodb-macro
MongoDB Macro is a crate with macros for quickly creating structures when working with mongodb. In particular, macros are implemented for quick initialization of structures of the "factory" pattern. The purpose of this crate is to reduce the amount of boilerplate code when initializing standard structures.
installation
Install using cargo:
cargo install mongodb-macro
Make sure you also add to the project:
mongodb = "*"
clap = { version = "*", features = ["derive", "env"] }
Usage
Macro: Collection
use Bson;
// env DB_URL should contain a link to the mongodb url
// env DB_NAME should contain the database name
// env COLLECTION_NAME should contain the collection name
collection!;
// or with a specified env
// mongodb_macro::collection!(CollectionFactory; CollectionFactoryOpts; ("MONGO_DB_URL", "MONGO_DB_NAME", "MONGO_COLLECTION_NAME"));
async
Macro: Database
use Bson;
// env DB_URL should contain a link to the mongodb url
// env DB_NAME should contain the database name
database!;
// or with a specified env
// mongodb_macro::database!(DbFactory; DbFactoryOpts; ("MONGO_DB_URL", "MONGO_DB_NAME"));
async
Macro: Client
use Bson;
// env DB_URL should contain a link to the mongodb url
client!;
// or with a specified env
// mongodb_macro::client!(ClientFactory; ClientFactoryOpts; "MONGO_DB_URL");
async
Macro: Config
use Bson;
config!;
// equivalent to
// mongodb_macro::config!(Opts; "DB_NAME", "COLLECTION_NAME", "DB_URL");
//
// or with prefix
//
// mongodb_macro::config!(Opts, "MONGO");
// equivalent to
// mongodb_macro::config!(Opts; "MONGO_DB_NAME", "MONGO_COLLECTION_NAME", "MONGO_DB_URL");
async
Current version: 1.0.0
License: MIT