wwwouter / typed-knex

A TypeScript wrapper for Knex.js
MIT License
112 stars 13 forks source link

Composite key considerations #50

Open jellelicht opened 2 years ago

jellelicht commented 2 years ago

Issue type:

[x] Question

Database system/driver:

[x] Postgres

typed-knex version:

[x] latest Knex.js version: 1.0.4

Steps to reproduce or a small repository showing the problem:

Very simple question, but how would I represent composite keys in typed-knex?

From a glance at the source code, it seems this is not supported; my more pressing question is whether things will just work out if I don't annotate any columns as primary key for those tables that only have a composite key?

Obviously stuff like findByPrimaryKey won't work in that case, which is totally fine as my code obviously doesn't use that right now :smile:

wwwouter commented 2 years ago

Yeah, you're correct, findByPrimaryKey works when there is only one column. Only *ByPrimaryKey functions use the primary key annotation, so using other functions will work with your composite key.

I think the *ByPrimaryKey functions are a bit too much ORM-like and maybe were a mistake. My plan is to move a bit closer to Knex, being a querybuilder, and move away from ORM-like functionality.