[PR #4247] [MERGED] [TypeScript] Make db.runQuery generic to make it easy to type DB query results #5281

Closed
opened 2026-02-28 21:09:45 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/4247
Author: @joel-jeremy
Created: 1/28/2025
Status: Merged
Merged: 2/18/2025
Merged by: @joel-jeremy

Base: masterHead: ts-runQuery-new


📝 Commits (3)

  • 89047ef Make runQuery generic to make it easy to type DB query results.
  • 29c817a Release notes
  • a4a40a6 typo

📊 Changes

12 files changed (+428 additions, -66 deletions)

View changed files

📝 packages/loot-core/src/server/budget/base.ts (+2 -2)
📝 packages/loot-core/src/server/budget/statements.ts (+2 -2)
📝 packages/loot-core/src/server/budget/template-notes.test.ts (+2 -3)
📝 packages/loot-core/src/server/db/index.ts (+77 -34)
📝 packages/loot-core/src/server/db/mappings.ts (+6 -8)
packages/loot-core/src/server/db/types.d.ts (+0 -9)
packages/loot-core/src/server/db/types/index.ts (+315 -0)
📝 packages/loot-core/src/server/main.ts (+11 -5)
📝 packages/loot-core/src/server/sync/index.ts (+1 -1)
📝 packages/loot-core/src/server/sync/migrate.test.ts (+5 -1)
📝 packages/loot-core/src/server/tools/app.ts (+1 -1)
upcoming-release-notes/4247.md (+6 -0)

📄 Description

This PR is to make the runQuery function generic to make it easy to type DB query results and propagate the proper types from the bottom up. Right now the runQuery returns any which means we lose type safety on the callers of this function unless we cast the result to the proper type.

Note: We have 2 runQuerys in the codebase. One is for AQL (server/aql folder) and the other is for direct DB access (server/db folder). This PR is for the DB.

The next phase for this is to make the higher level functions e.g. first, all, firstSync, etc, generic and all of their callers.

  • db.runQuery
  • db.first
  • db.firstSync
  • db.all
  • db.select
  • db.selectWithSchema
  • db.selectFirstWithSchema

🔄 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/4247 **Author:** [@joel-jeremy](https://github.com/joel-jeremy) **Created:** 1/28/2025 **Status:** ✅ Merged **Merged:** 2/18/2025 **Merged by:** [@joel-jeremy](https://github.com/joel-jeremy) **Base:** `master` ← **Head:** `ts-runQuery-new` --- ### 📝 Commits (3) - [`89047ef`](https://github.com/actualbudget/actual/commit/89047efa10cd2c2b4bd837441dbbde6b3b84f1d3) Make runQuery generic to make it easy to type DB query results. - [`29c817a`](https://github.com/actualbudget/actual/commit/29c817a4fe487798963532495fafcc3d46f0866f) Release notes - [`a4a40a6`](https://github.com/actualbudget/actual/commit/a4a40a6b7535ee46e01c3320b7e1336c7c249b03) typo ### 📊 Changes **12 files changed** (+428 additions, -66 deletions) <details> <summary>View changed files</summary> 📝 `packages/loot-core/src/server/budget/base.ts` (+2 -2) 📝 `packages/loot-core/src/server/budget/statements.ts` (+2 -2) 📝 `packages/loot-core/src/server/budget/template-notes.test.ts` (+2 -3) 📝 `packages/loot-core/src/server/db/index.ts` (+77 -34) 📝 `packages/loot-core/src/server/db/mappings.ts` (+6 -8) ➖ `packages/loot-core/src/server/db/types.d.ts` (+0 -9) ➕ `packages/loot-core/src/server/db/types/index.ts` (+315 -0) 📝 `packages/loot-core/src/server/main.ts` (+11 -5) 📝 `packages/loot-core/src/server/sync/index.ts` (+1 -1) 📝 `packages/loot-core/src/server/sync/migrate.test.ts` (+5 -1) 📝 `packages/loot-core/src/server/tools/app.ts` (+1 -1) ➕ `upcoming-release-notes/4247.md` (+6 -0) </details> ### 📄 Description <!-- Thank you for submitting a pull request! Make sure to follow the instructions to write release notes for your PR — it should only take a minute or two: https://github.com/actualbudget/docs#writing-good-release-notes --> This PR is to make the `runQuery` function generic to make it easy to type DB query results and propagate the proper types from the bottom up. Right now the `runQuery` returns `any` which means we lose type safety on the callers of this function unless we cast the result to the proper type. Note: We have 2 `runQuery`s in the codebase. One is for AQL (server/aql folder) and the other is for direct DB access (server/db folder). This PR is for the DB. The next phase for this is to make the higher level functions e.g. `first`, `all`, `firstSync`, etc, generic and all of their callers. - [x] `db.runQuery` - [ ] `db.first` - [ ] `db.firstSync` - [ ] `db.all` - [ ] `db.select` - [ ] `db.selectWithSchema` - [ ] `db.selectFirstWithSchema` --- <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 21:09:45 -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#5281