GO-SQLite@v0.3.0: SQLite client with chained method calls
#Dev

[email protected]: SQLite client with chained method calls

Backend Reporter
2 min read

GO-SQLite has released version 0.3.0, introducing a Delete method and refactoring the API to use a chainable Context pattern for better consistency and context propagation.

The GO-SQLite library has reached a significant milestone with its v0.3.0 release, bringing substantial improvements to its API design and functionality. This update focuses on consistency, context propagation, and better organization of the codebase.

Chainable Context Pattern

The most notable change in this release is the introduction of a chainable Context(ctx context.Context) method. This allows developers to propagate context throughout their database operations in a fluent, chainable manner. The pattern enables more flexible and readable code when working with database operations that need context awareness.

Unified Return Values

A major refactoring effort has unified the return values for Insert and Update operations. Previously, these methods returned different types, which could lead to inconsistent handling in client code. Now both operations return (int64, error):

  • Insert() returns the last insert ID
  • Update() returns the number of rows affected

This consistency simplifies error handling and result processing across different database operations.

New Delete Method

The addition of the Delete(force ...bool) method provides a straightforward way to remove rows from the database. The optional force parameter allows for unprotected deletes when needed, giving developers more control over deletion operations.

SQL Building Logic Extraction

To improve maintainability, the SQL building logic has been extracted into dedicated methods:

  • buildJoin()
  • buildOrderBy()
  • buildLimit()
  • buildOffset()

This separation of concerns makes the codebase more modular and easier to test.

Context-Aware Execution

The new ExecAutoAsignContext() helper automatically uses the provided context when available, reducing boilerplate code and ensuring consistent context handling across different operations.

Code Organization Improvements

Where clauses have been moved to dedicated files (select_where.go and select_or_where.go), improving code organization and making the codebase more maintainable.

Deprecated Methods

Several legacy context methods have been marked as deprecated, including:

  • InsertContext(), InsertReturningID(), InsertContextReturningID()
  • InsertConflict(), InsertContexConflict(), InsertConflictReturningID(), InsertContextConflictReturningID()
  • GetContext(), GetWithTotal(), GetWithTotalContext()
  • FirstContext(), CountContext(), UpdateContext()

This cleanup helps maintain a cleaner API surface and encourages the use of the new chainable context pattern.

Impact on Developers

For developers using GO-SQLite, this release represents a significant improvement in API consistency and usability. The chainable context pattern makes it easier to write clean, readable database code while maintaining proper context propagation throughout the application.

The unified return values reduce the cognitive load when working with different database operations, and the extracted SQL building logic provides a clearer separation of concerns.

Getting Started

You can find the updated library on GitHub at Pardnchiu/go-sqlite. The documentation has been updated to reflect these changes, and the test suite has been expanded to cover the new functionality.

This release demonstrates the library's commitment to improving developer experience while maintaining backward compatibility through the deprecation process rather than breaking changes.

Comments

Loading comments...