go-ozzo / ozzo-dbx

A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.
MIT License
636 stars 91 forks source link

Can't get last inserted id for pgx. #94

Closed lookharm closed 4 years ago

lookharm commented 4 years ago

@qiangxue The program that I wrote use pgx driver (https://github.com/jackc/pgx) for PostgreSQL. I found the dbx can use pgx driver from here. https://github.com/go-ozzo/ozzo-dbx/blob/c0868b7fa469684fd21331c4b0c334d732d039f9/db.go#L75-L82 When I try to insert a new record with the Insert() method like the document page. The code as below.

err := db.Model(&customer).Insert()

I encountered some error like "LastInsertId is not supported by this driver"

I think the function insertAndReturnPK() should also check for pgx driver. Both pgx and postgres driver use for PostgreSQL, but PostgreSQL doesn't support for LastInsertID(). https://github.com/go-ozzo/ozzo-dbx/blob/c0868b7fa469684fd21331c4b0c334d732d039f9/model_query.go#L107-L114

[sory for my poor English skill]

qiangxue commented 4 years ago

Thank you for reporting this issue! Could you verify the fix?

dharmavagabond commented 2 years ago

Yes, it works. :thumbsup: