Skip to content

Refactor database connection handling and streamline show commands#449

Merged
OutOfBedlam merged 8 commits into
mainfrom
refactor-tql-show-command
Jul 20, 2026
Merged

Refactor database connection handling and streamline show commands#449
OutOfBedlam merged 8 commits into
mainfrom
refactor-tql-show-command

Conversation

@OutOfBedlam

Copy link
Copy Markdown
Contributor

This pull request refactors database connection handling and SQL execution across the codebase to standardize on Go's database/sql package and improve consistency, reliability, and maintainability. It replaces custom connection interfaces with *sql.Conn, updates function signatures, and refactors SQL execution logic in server handlers and TQL modules. Additionally, it modernizes error handling and improves test diagnostics.

Database connection and execution refactoring:

  • Replaced custom api.Conn usage with *sql.Conn from the standard library throughout the server and TQL modules, updating function signatures and connection acquisition logic accordingly. (mods/server/http.go, mods/server/http_query.go, mods/server/http_write.go, mods/tql/fm_dbsink.go, mods/tql/fm_dbsrc.go) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]

  • Refactored SQL execution paths to use context-aware methods (ExecContext, QueryRowContext) and improved error propagation and handling. (mods/server/http_write.go, mods/tql/fm_dbsink.go, mods/tql/fm_dbsrc.go) [1] [2] [3] [4]

Server handler improvements:

  • Updated HTTP handlers to use the new connection methods, added stricter authorization checks for license installation, and improved resource cleanup with proper defer usage. (mods/server/http.go) [1] [2] [3]

  • Changed table listing logic to pass errors directly and improved callback signatures for clarity. (mods/server/http_query.go)

TQL module enhancements:

  • Simplified and clarified TQL node implementations by removing unnecessary provider indirection, ensuring connections are acquired and closed consistently, and updating SQL sink logic to use the new connection style. (mods/tql/fm_dbsink.go, mods/tql/fm_dbsrc.go) [1] [2] [3] [4]

Testing and dependency updates:

  • Improved test diagnostics by including response bodies in assertion messages for easier debugging. (mods/server/http_test.go)

  • Updated dependency version for github.com/machbase/neo-client in go.mod.

- Removed the `testInsertAndQuery` function from `machsvr_test.go` and integrated its logic into `spi_test.go` for better organization and clarity.
- Updated the `ShowTags` function in `show.go` to use the new query handling approach, replacing the previous method of describing tables.
- Modified the `ListTagsWalk` and `QueryTagStat` functions to accept `*sql.Conn` instead of `api.Conn`, ensuring consistency in connection handling.
- Enhanced the `TestShowTables` function in `show_test.go` to correctly parse time without unnecessary timezone conversions.
- Cleaned up the `InsertAndQuery` function in `tables.go` by removing redundant code and ensuring it follows the new query execution pattern.
- Updated the `TestAll` function in `testsuite.go` to remove the now redundant `InsertAndQuery` test case.
- Refactored the `unit_test.go` to streamline the stub connection implementation and improve error handling in test scenarios.
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.71154% with 126 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.92%. Comparing base (0c754c5) to head (258c64c).

Files with missing lines Patch % Lines
spi/do.go 50.00% 16 Missing and 8 partials ⚠️
spi/database.go 25.92% 19 Missing and 1 partial ⚠️
mods/tql/fm_dbsink.go 35.71% 7 Missing and 11 partials ⚠️
spi/show.go 94.02% 4 Missing and 7 partials ⚠️
mods/server/http_query.go 54.54% 4 Missing and 6 partials ⚠️
spi/watch.go 56.52% 8 Missing and 2 partials ⚠️
mods/server/http_write.go 50.00% 4 Missing and 5 partials ⚠️
mods/tql/fm_dbsrc.go 78.04% 5 Missing and 4 partials ⚠️
mods/server/http.go 38.46% 8 Missing ⚠️
mods/server/mqtt_write.go 45.45% 3 Missing and 3 partials ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #449      +/-   ##
==========================================
- Coverage   65.95%   65.92%   -0.04%     
==========================================
  Files         345      343       -2     
  Lines       70557    70286     -271     
==========================================
- Hits        46533    46333     -200     
+ Misses      19087    18997      -90     
- Partials     4937     4956      +19     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@OutOfBedlam
OutOfBedlam merged commit 3215d94 into main Jul 20, 2026
9 checks passed
@OutOfBedlam
OutOfBedlam deleted the refactor-tql-show-command branch July 20, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant