A quick overview of database abstractions and ORMs for Deno

Deno 1.0 is barely a two weeks old, but it's seen quite a bit of hype (including some from me), but for it to walk the walk it will need to grow an ecosystem. Similar to Node.js, Deno will likely be used quite a bit as a data pump - sending streams of data from one place to another. In addition to piping data it will likely be used for persisting data to a persistent data store like NoSQL or a relational database.

Object Relational Mappers (ORMs) are libraries that abstracs a RDBMS to use object based interfaces for persisting data. Behind the scenes the ORM handles heavy lifting of schema management, reads and writes. ORMs (and ODMs for document databases) are a controversial topic as some see them as too much of an abstration. While ORMs are not for everyone and every use case, they are widely adopted.

You have likely heard of Hibernate for Java, Doctrine for PHP, TypeORM for TypeScript/JavaScript, Entity Framework for .NET or SQLAlchemy for Python. Usually a language ecosystem has one or two ORMs that have controlling marketshare. As boring as it is, building CRUD apps with a bunch of forms to store rows in a database remains a common use case for any HTTP capable server side technology.

I think it only a matter of time before Deno gets an ORM/ODM library (or two, three) with commanding market share. Hopefully it will also take the opportunity leverage new features like robust JSON support in MariaDB/MySQL and PostgreSQL. I also wouldn't mind it being lightweight (to avoid the Database Portability Fallacy). And in 2020 support for cloud databases like Cosmos DB or DynamoDB are a must.

Deno builds on a similar userland tech stack to Node.js, so it's not surprising that there are already solid database abstractions for Deno available when the paint on 1.0 is still wet. Let's consider a few:

  • DenoDB is a lightweight wrapper for SQLite, MySQL and PostgreSQL. It allows accessing databases with a TypeScript API using the native driver packages, but does not include schema management or defining entity relationships. Arguably it's not really even ORM.
  • TypeORM (denolib fork) is a fully fledged ORM written in TypeScript supporting a number of database backends. The library handles schema generation and allows complex relationships. As a fork of TypeORM for Node.js it is mature, but the question is how will it evolve going forward?
  • Deno Simple Orm (DSO) is new project that allows simple abstractions for use with MySQL only. It is quite rudimentary in it's feature set, but then again the whole codebase is of modest size. Not an ORM as it lacks schema generation and the works.
  • deno_mongo is a plain mongodb library for interacting with the popular document database. Building on Rust's MongoDB library package. As such it is robust and suitable for people comfortable with the raw MongoDB syntax. With great power comes great responsibility.
  • deno-postgres is the raw PostgreSQL driver for Deno. That sounds bad, but given the API just exposes bare Postgres connections it is suitable for database afficionados. Tight coupling to psql, but also full access to JSON or any other features in the latest PostgreSQL releases.
  • Massive.js is a lightweight PostgreSQL abstraction for Node.js. It offers a battle-tested API that makes working with relational data easy. Currently it is not officially supported in Deno, but hopefully it will be adapted it seems to hit the perfect balance between power and ease of use.

- Jani Tarvainen, 2020/05/24