[PR #2044] [CLOSED] [Maintanence] Harden types in core database functions #4083

Closed
opened 2026-02-28 20:51:16 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/2044
Author: @kymckay
Created: 12/6/2023
Status: Closed

Base: masterHead: tsx-db


📝 Commits (1)

  • 3a8cef8 Harden types in core generic database functions

📊 Changes

1 file changed (+51 additions, -43 deletions)

View changed files

📝 packages/loot-core/src/server/db/index.ts (+51 -43)

📄 Description

Opening as draft before going further with this because a thought occurred to me which could use some more input:

The way I've typed this so far is quite generic to facilitate the way these functions are used across different tables where the common structure is the ID column. However, to be exhaustively strict with typing we could alternatively have an overload for every possible table and the type it stores (that is, where functions have table: string, row: DatabaseRow instead having a set of overloaded functions like table: "payees", row: PayeeEntity).

There's a trade off here between strictness of typing and maintainability. The more exhaustive approach would ensure use of these functions is strictly correct, but the code is then tightly coupled to the database structure which means maintaining and updating both in tandem (in an ideal world something like this could be done with codegen whenever the database changes).

Should I continue with the more generic approach in the diff here, or switch to the more exhaustive approach described?


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/actualbudget/actual/pull/2044 **Author:** [@kymckay](https://github.com/kymckay) **Created:** 12/6/2023 **Status:** ❌ Closed **Base:** `master` ← **Head:** `tsx-db` --- ### 📝 Commits (1) - [`3a8cef8`](https://github.com/actualbudget/actual/commit/3a8cef8e8d699c4bad98a8ae0c40bfb03810ebf5) Harden types in core generic database functions ### 📊 Changes **1 file changed** (+51 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `packages/loot-core/src/server/db/index.ts` (+51 -43) </details> ### 📄 Description Opening as draft before going further with this because a thought occurred to me which could use some more input: The way I've typed this so far is quite generic to facilitate the way these functions are used across different tables where the common structure is the ID column. However, to be exhaustively strict with typing we could alternatively have an overload for every possible table and the type it stores (that is, where functions have `table: string, row: DatabaseRow` instead having a set of overloaded functions like `table: "payees", row: PayeeEntity`). There's a trade off here between strictness of typing and maintainability. The more exhaustive approach would ensure use of these functions is strictly correct, but the code is then tightly coupled to the database structure which means maintaining and updating both in tandem (in an ideal world something like this could be done with codegen whenever the database changes). Should I continue with the more generic approach in the diff here, or switch to the more exhaustive approach described? --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-02-28 20:51:16 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#4083