Since I’m currently exploring Nim and wanted to build a simple project for my own personal use and also to learn the language deeper, I decided to build a simple CLI application for storing bookmarks, and in this project I’m planning to use ORM because this project will depend on a database like SQLite so I don’t have to write raw SQL statements (I’m lazy).

Looking for an ORM in Nim Ecosystem

So two days ago, I headed to nimble.directory, a place where Nim libraries and tools are listed. I typed ORM there, and the results are showing. The first entry was Norm and I see that it has many stars, so I was giving it a shot.

After I initialized my project with nimble init, I read Norm’s README on GitHub and also the library’s dedicated documentation. After reading it, I decided to try it by running nimble add norm. The interesting part is Norm has a scaffolding and migration manager called Norman so it seems like both Norm and Norman are expected to behave similarly to SQLAlchemy and Alembic pair.

First Attempt on Norm and Norman

I was a little bit skeptical because Norman itself hasn’t been updated since four years ago, but I didn’t really mind it, so I just went straight to coding and added that too—nimble add norman. After adding Norman, I was following Norm’s tutorial on how to create tables with iNim, a community-maintained Nim REPL (sigh, I wish there were an official Nim REPL already). The guide is pretty great; I was able to follow it through on the interactive shell.

After that, I opened my favorite text editor, Neovim, implementing what I already did on the REPL session to a real .nim file. It worked great too; there were not any errors.

Then, I wanted to try the migration tool, Norman; I read the documentation first on its README since it doesn’t have dedicated documentation like Norm does; there’s a URL on the project description, but when I clicked it, my browser couldn’t find that site. So, I was heavily dependent on the README only. It’s still great because it has a usage section that is meant for developers to follow along. But I experienced something weird here on Norman.

After Norman generated the directories and the files for it to be able to get to work, the usage tells us to create the model by running norman model -n <model name>. The documentation shows that it’ll create the model and the model’s migration file, but on my side it didn’t. Since the next steps are dependent on the migration file—applying the migration and editing the migration file—I gave up easily on this.

I already assumed that maybe the README is just not updated, and I still can see the actual source code for me to read, but since I’m really new to Nim syntax and the file structure is modular, I think I’m giving up on this one because I don’t want to have a headache on learning a language that is really new to me.

So, I decided to seek another solution. I tried to search for another ORM on the Nimble directory, and I found out that the Nim language creator, Araq, has actually already developed an ORM called Ormin so I’m checking that one.

Second Attempt on Ormin

I also was a little bit skeptical about this one because the release tag is only one, and it’s version 0.1.0 from 2017. But I see that there’s a new commit there, so it gives me hope.

After a walk-through reading the documentation, I’m a little bit excited because Ormin uses DSL to create queries. This gives me Ruby vibes.

I replaced norm and norman from my project dependency with ormin. This one doesn’t use nimble add ormin but I have to clone the whole ormin repository to my project root directory. I also feel that the documentation for Ormin is not really well-covered because the installation guide is not there; it’s directly about how to use Ormin in your code and use the ormin_importer to parse SQL schema files into Nim type information.

Learning by Reading Tests instead of Docs

I was having a headache too with Ormin since the documentation is not really clear for me, BUT Ormin has test specs so I can see the code there about how to use the functions it provides. Norm has test specs too, but its migration tool, Norman, doesn’t.

I was forcing myself on this one. Because I believe that if a tool is created by the core developers, it will be maintained and won’t stall, I always have a bias in favor of official tools over community-maintained ones.

Therefore, I was able to successfully implement Ormin by reading and comprehending the test syntax and function logics. I’m happy, lol.

Reflections

My overall experience in Nim is sadly not satisfying because most libraries are not well documented, in my opinion. This forces me to read the actual source code rather than the one that already rendered beautifully on markdowns (I know I’m acting spoiled).

What I’ll Do Next

Since I already know how to work with Ormin, I’ll post the tutorial on my next post on this blog to make it easy for other beginners that are interested in Nim and looking for an ORM for their projects.

I’m still feeling challenged to do database stuff with Norm, so I’ll get my hands on it once my hobby project in Nim is done. Also, probably I’ll contribute to the documentation for both Ormin and Norm once I’m decent in Nim. Norm and Norman are promising, actually, so I likely will prioritize it.