The Tnuctipun of Ringworld β ancient, subversive, ingenious β or a type-safe MongoDB builder library.
- Type-safe field access: Use compile-time validated field names
- MongoDB query building: Build complex queries with type safety
- MongoDB projection building: Create projections with fluent method chaining
- MongoDB update building: Create update documents with type-safe field operations
- Derive macros: Automatically generate field witnesses and comparable traits
- Compile-time validation: Catch field name typos and type mismatches at compile time
Add this to your Cargo.toml
:
[dependencies]
tnuctipun = "0.1.1"
The library only requires the bson
crate for MongoDB document types and provides type-safe query building capabilities.
use tnuctipun::{FieldWitnesses, MongoComparable, filters::empty, projection, updates};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, FieldWitnesses, MongoComparable)]
struct User {
pub name: String,
pub age: i32,
pub email: String,
}
// Type-safe filter building with compile-time field validation
let mut filter_builder = empty::<User>();
filter_builder.eq::<user_fields::Name, _>("John".to_string());
filter_builder.gt::<user_fields::Age, _>(18);
// Convert to MongoDB document
let filter_doc = filter_builder.and();
// Results in: { "$and": [{ "name": "John" }, { "age": { "$gt": 18 } }] }
// Type-safe projection building with method chaining
let projection_doc = projection::empty::<User>()
.includes::<user_fields::Name>()
.includes::<user_fields::Age>()
.excludes::<user_fields::Email>() // Hide sensitive data
.build();
// Results in: { "name": 1, "age": 1, "email": 0 }
// Type-safe update building with compile-time field validation
let update_doc = updates::empty::<User>()
.set::<user_fields::Name, _>("Jane".to_string())
.inc::<user_fields::Age, _>(1)
.unset::<user_fields::Email>()
.build();
// Results in: {
// "$set": { "name": "Jane" },
// "$inc": { "age": 1 },
// "$unset": { "email": "" }
// }
- User Guide - Comprehensive documentation with examples and tutorials
- API Documentation - Complete API reference
- Crates.io Documentation - Released version docs
For information about contributing and releasing new versions, see:
- Release Guide - How to publish new versions
- Changelog - What's new in each version
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.