Using of kysely for DB acccess

Version

wip

Status

ACCEPTED

Revision Comment

Initial Version

Commit

(worktree)

Repository

https://github.com/rattermeyer/rr-mantine-template.git

Last Re-evaluation

25.1 - 11.03.2025

Last Reviewers

Richard Attermeyer

Contributors

Richard

Informed

Team

Keywords

DB, postgres, query builder, ORM

Superseded by

Context and Problem Statement

Database access should also be type-safe and type checking should highlight issues, if queries do not match to the configured DB schema.

Architectural Drivers

  • Database First development philosophy

  • Type Safety

  • Postgres Database

Decision

Using kysely for DB access

Kysely, currently seems to be the most typesafe option, as shown in the github issue. Furthermore, kysely also supports Oracle through a community dialect.

Relationship to other Architectural Decisions

Consequences

If you often need to fetch sub-elements it might be better with an ORM. However, with postgres you could achieve some of this using json_agg function.

Considered Alternatives

drizzle ORM

As put in the github issue:

Drizzle gives the impression of type-safety. However, only the query results have type information. You can write invalid queries with Drizzle.

However, drizzle orm has the advantage of supporting row-level-security in postgres. This might be important, if you need RLS, e.g. for multi-tenancy.

This is at least valid, if you use Postgres as a database.

drizzle on the other hand does not support Oracle.