Skip to content

πŸ‘οΈ The Tnuctipun of Ringworld β€” ancient, subversive, ingenious β€” or a type-safe MongoDB builder library.

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE-APACHE
Notifications You must be signed in to change notification settings

cchantep/tnuctipun

Tnuctipun

CI Crates.io API Documentation Codecov

The Tnuctipun of Ringworld β€” ancient, subversive, ingenious β€” or a type-safe MongoDB builder library.

Features

  • 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

Usage

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.

Example

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": "" } 
// }

Documentation

Development

For information about contributing and releasing new versions, see:

License

This project is licensed under either of

at your option.

Contribution

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.

About

πŸ‘οΈ The Tnuctipun of Ringworld β€” ancient, subversive, ingenious β€” or a type-safe MongoDB builder library.

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE-APACHE

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks