GO-SQLite v0.3.0 introduces chainable API design, unified return types, and comprehensive context support for SQLite operations.
The GO-SQLite library has reached version 0.3.0, bringing significant improvements to its API design and functionality. This update focuses on modernizing the library with chainable syntax, consistent return values, and enhanced context support for better database operations.
Chainable API Design
The most notable change in v0.3.0 is the introduction of a chainable API pattern. The new Context(ctx context.Context) method allows developers to easily pass context through the query chain, making it simpler to manage request-scoped operations and cancellations. This follows modern Go practices where context propagation is essential for building robust applications.
Unified Return Types
Consistency has been improved across the board with unified return types:
Insert()now returns(int64, error)including the LastInsertIdUpdate()returns(int64, error)with RowsAffected count- These changes replace the previous
(sql.Result, error)pattern, making it easier to work with the results directly
The Delete method has been added with support for a force boolean parameter, giving developers more control over deletion operations.
Refactored SQL Building
SQL construction logic has been extracted into dedicated methods:
buildJoin()buildOrderBy()buildLimit()buildOffset()
This separation improves code organization and makes the query building process more maintainable.
Context Method Deprecation
Several older context-specific methods have been marked as deprecated:
InsertContext(),InsertReturningID(),InsertContextReturningID()InsertConflict(),InsertContexConflict(),InsertConflictReturningID(),InsertContextConflictReturningID()GetContext(),GetWithTotal(),GetWithTotalContext()FirstContext(),CountContext(),UpdateContext()
Developers are encouraged to migrate to the new chainable context approach.
Code Organization
To improve maintainability, the Where() and OrWhere() methods have been moved to dedicated files. The deprecated insertBuilderConflict() internal function has also been removed.
File Changes
The update touches multiple files:
builder.go- Modified with new featuresinsert.go- Modified with refactoringselect.go- Modified with refactoringselect_ext.go- Modified with refactoringselect_where.go- Modified with refactoringselect_or_where.go- Modified with refactoringupdate.go- Modified with refactoringmain_test.go- Modified with test updatesREADME.mdandREADME.zh.md- Updated documentation
This release represents a significant step forward in making GO-SQLite more modern, consistent, and easier to use while maintaining backward compatibility through the deprecation cycle.

Comments
Please log in or register to join the discussion