You are here

ModelType is a program that I came up with to help me write my Mongoose Models. I use Typescript, so for me to define a model I need to declare both the Mongoose Schema and the Typescript Interface. That's when I decided to write ModelType, a generator for my mongoose models. It allows me to define my models in YAML, then generates the representations of them in code. 

After I tweaked it and got it working smoothly for Typescript, I needed to add a microservice to process data. The service needed to receive a document from a message queue, pull up all the relevent MongoDB documents and run some CPU intensive calculations on them. I ended up writing the service in Java, and quickly realized that continously casting objects in Java was tedious. That's when I wrote the Java wrapper for ModelType. It essentially wraps the raw BSON Document with methods that you to get the properties in a manner almost similar to Typescript. Here's an example of what a model definition would look like, and the subsequent generated code.

With ModelType, I avoided writing all the boilerplate code and quickly generated a model. My time spent writing data models went down dramatically.

ModelType is still in it's early stages, and could support a lot more than what it currently does. Plus it also needs Unit Tests, so if any enterprising individual would like to help out, check out the GitHub repo!