Skip to content

Refactor datastore internals and tighten query option safety#3

Merged
squeakycheese75 merged 2 commits into
mainfrom
codex/refactor-datastore-for-better-cohesion
Apr 1, 2026
Merged

Refactor datastore internals and tighten query option safety#3
squeakycheese75 merged 2 commits into
mainfrom
codex/refactor-datastore-for-better-cohesion

Conversation

@squeakycheese75

Copy link
Copy Markdown
Contributor

Motivation

  • Improve cohesion by splitting datastore logic into files grouped by concern and make client behavior clearer.
  • Ensure consistent, safe query behavior where empty result sets return an empty slice rather than an error.
  • Harden query option validation so callers cannot rely on implicit inference of allowed columns from user input.
  • Improve error messages and use %w wrapping for better error propagation.

Description

  • Split internal/datastore into focused files: client.go, query_options.go, postgres_client.go, sqlite_client.go, sqlite_storage.go, plus existing factory.go, sqlite_storage_local.go, and sqlite_storage_s3.go.
  • Renamed SqliteDataStoreClient to SQLiteDataStoreClient and kept constructor APIs NewSQLiteDataStoreClient / NewSQLiteDataStoreClientWithStorage intact.
  • Changed Find and Query in both SQLite and Postgres clients to return []map[string]interface{}{} with nil error when no rows are found, and improved error messages using %w wrapping where appropriate.
  • Tightened ApplyQueryOptionsWithSafety so it no longer infers AllowedCols from Filters/OrderBy when AllowedCols is empty and now validates/returns an error for invalid filter or order columns.
  • Cleaned up factory error messages to use %w wrapping and corrected a Postgres unmarshal error label.
  • Added internal/datastore/client_query_test.go to cover empty-result handling and invalid query options.

Testing

  • Added unit tests in internal/datastore/client_query_test.go covering empty results for Find/Query and invalid QueryOptions, and they passed when running the package tests.
  • Ran go test ./internal/datastore and it completed successfully.
  • Ran go test ./... and the full test suite completed successfully (no failures reported).

Codex Task

@squeakycheese75
squeakycheese75 merged commit 1f77573 into main Apr 1, 2026
3 checks passed
@squeakycheese75
squeakycheese75 deleted the codex/refactor-datastore-for-better-cohesion branch April 1, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant