Skip to content

Drizzle or native SQL

  • habit-tracker

Development of a habit tracker is underway.

I took a short break and didn’t share the development progress to figure out how convenient it is to work with Expo SQLite and what is better to use - pure SQL queries or some kind of ORM.

I once tried to connect TypeORM to Expo and it was a pain - you had to enable some experimental flags, roll out patches - in general, it worked very poorly then. And the application is quite simple - there is no particular sense in ORM.

And then I decided to try Drizzle https://orm.drizzle.team/ and was absolutely delighted.

Drizzle is a so-called SQL builder - it provides very light abstractions on top of SQL - i.e. instead of writing:

SELECT * FROM test

you write:

db.select().from(test);

the same thing will happen with joins, instead of:

SELECT * FROM users LEFT JOIN pets ON users.user_id = pets.owner_id

you write:

db.select().from(users).leftJoin(pets, eq(users.id, pets.ownerId));

Basically, you write SQL and this SQL is executed as is without any extra magic or additional calculations. And accordingly, the performance of a query via Drizzle is the same as a naive query using pure SQL.

Why not stick to pure SQL then?

This is where the main charm of Drizzle comes in - before you start working with the database and making requests, you describe its scheme. And all the data you receive comes to you with types.

Plus a convenient tool for migration - if the scheme has changed, Drizzle itself migrates the existing database, plus an admin panel for working with the database on Expo - if, for example, you can connect to a third-party database with any SQL client, then Expo SQLite does not support third-party connections, but here the data can be edited in the UI - very convenient.