Pi Garage Backend App Framework

As I had chosen to use a Raspberry Pi for the hardware this allows me to use any language and framework that I want as long as the Raspberry Pi supports it. To view the current Open Source code can see it here on GitHub.

I new that I wanted to write the app in Node.JS (my favourite) and to make my life easier I commonly use the application framework NestJS. This opinionated framework which is heavily inspired by Angular and it’s structure (and cli) allows you to build all sorts of applications quickly and easily.

Using NestJS I quickly built up an API project that I thought would work and incorporated the npm library automation-hat (which I also wrote) to interface with the Pimoroni Automation Hat.

Quickly I realised that I would need some data storage in the form of a database. I knew that I wanted a relational database so I had the choice of SQLite, MySQL & PostgreSQL. As this is not really a high load program I decided to use SQLite so that the resources on the Raspberry Pi would be less. Later I would come back to question this decision.

Next I needed to communicate with the database. I’ve done this many ways over the years, raw SQL, knex like libraries and full blown ORM’s like Entity Framework (for .NET). My personal favourite is the ORM route as there has been only 2 times I can recall where an ORM made worse query decisions than a human could and it makes development so much easier.

I looked over the recipes in NestJS and had a choice between TypeORM and MikroORM. I had not used MikroORM before so decided to give this ago. I remember it required some complex setup to do with NestJS, Typescript and the MikroORM config files. Ensuring you had the right mix of paths in the config file to point to the dist folder or migrations folder took some trial and error.

During this I did actually find a bug in MikroORM and helped the maintainer fix it.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *