thedodd / wither

An ODM for MongoDB built on the official MongoDB Rust driver.
https://docs.rs/wither
Other
325 stars 40 forks source link

Use RON files or macros to define schemas #49

Open Figments opened 4 years ago

Figments commented 4 years ago

Much in the way Mongoose deals with schemas, I think it would be cool to see Wither handle document schemas in a way that's more natural with how documents are formatted within MongoDB itself, through either Diesel-style migrations using RON files in a migrations/[migration].ron kind of folder structure, or through macros.

An example RON file:

Users (
    _id: {
        type: String, // maybe as an enum of all supported types
    },
    username: {
        type: String,
        options: (
            // some miscellaneous options for this field
            required: true,
            unique: true,
        ),
    },
    // can also declare objects
    stats: {
        blogs: { type: Number, options: (required: false, default: 0)},
    },
    createdAt: {
        type: Date,
    },
)

(issue migrated from #47 so as not to clutter that one)