Skip to content

MySQL/SQLite: support returning LastInsertId #1459

Closed
@housingdreams

Description

@housingdreams

:exec only checks the error
:execresult returns the full sql.Result
:execrows returns the sql.Result.RowsAffected() (int64, error)

We just need one more return type to support the full interface:

:execlastinsertid would just be a matter of calling .LastInsertId() rather than .RowsAffected() on the sql.Result.

This will avoid sql.Result database information leaking across the boundary of the pkg.Querier interface. It's not good for the service code to be handling DB specific method calls. This is a MySQL/SQLite issue as Postgres uses RETURNING so you can use :one instead.

Solution: duplicate the template code used for :execrows

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions