From ba9755855f96ccd64ae22300909d7de90514e645 Mon Sep 17 00:00:00 2001 From: qqxhb <1252905006@qq.com> Date: Thu, 19 Dec 2024 20:51:45 +0800 Subject: [PATCH] feat: interface template add method Rows --- internal/template/struct.go | 2 ++ tests/.expect/dal_3/query/banks.gen.go | 3 +++ tests/.expect/dal_3/query/credit_cards.gen.go | 3 +++ tests/.expect/dal_3/query/customers.gen.go | 3 +++ tests/.expect/dal_3/query/people.gen.go | 3 +++ tests/.expect/dal_3/query/users.gen.go | 3 +++ tests/.expect/dal_4/query/banks.gen.go | 5 ++++- tests/.expect/dal_4/query/credit_cards.gen.go | 5 ++++- tests/.expect/dal_4/query/customers.gen.go | 5 ++++- tests/.expect/dal_4/query/people.gen.go | 5 ++++- tests/.expect/dal_4/query/users.gen.go | 2 ++ tests/.expect/dal_5/query/users.gen.go | 3 +++ tests/.expect/dal_6/query/users.gen.go | 3 +++ 13 files changed, 41 insertions(+), 4 deletions(-) diff --git a/internal/template/struct.go b/internal/template/struct.go index 8b83a12e..d0415cb0 100644 --- a/internal/template/struct.go +++ b/internal/template/struct.go @@ -201,6 +201,8 @@ type I{{.ModelStructName}}Do interface { FirstOrCreate() (*{{.StructInfo.Package}}.{{.StructInfo.Type}}, error) FindByPage(offset int, limit int) (result []*{{.StructInfo.Package}}.{{.StructInfo.Type}}, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) I{{.ModelStructName}}Do UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_3/query/banks.gen.go b/tests/.expect/dal_3/query/banks.gen.go index 863cd584..c644b19a 100644 --- a/tests/.expect/dal_3/query/banks.gen.go +++ b/tests/.expect/dal_3/query/banks.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -163,6 +164,8 @@ type IBankDo interface { FirstOrCreate() (*model.Bank, error) FindByPage(offset int, limit int) (result []*model.Bank, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) IBankDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_3/query/credit_cards.gen.go b/tests/.expect/dal_3/query/credit_cards.gen.go index 99b18762..217978ad 100644 --- a/tests/.expect/dal_3/query/credit_cards.gen.go +++ b/tests/.expect/dal_3/query/credit_cards.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -177,6 +178,8 @@ type ICreditCardDo interface { FirstOrCreate() (*model.CreditCard, error) FindByPage(offset int, limit int) (result []*model.CreditCard, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) ICreditCardDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_3/query/customers.gen.go b/tests/.expect/dal_3/query/customers.gen.go index d9a78890..b1824d5c 100644 --- a/tests/.expect/dal_3/query/customers.gen.go +++ b/tests/.expect/dal_3/query/customers.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -167,6 +168,8 @@ type ICustomerDo interface { FirstOrCreate() (*model.Customer, error) FindByPage(offset int, limit int) (result []*model.Customer, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) ICustomerDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_3/query/people.gen.go b/tests/.expect/dal_3/query/people.gen.go index 9c89dd0f..6b844f24 100644 --- a/tests/.expect/dal_3/query/people.gen.go +++ b/tests/.expect/dal_3/query/people.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -231,6 +232,8 @@ type IPersonDo interface { FirstOrCreate() (*model.Person, error) FindByPage(offset int, limit int) (result []*model.Person, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) IPersonDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_3/query/users.gen.go b/tests/.expect/dal_3/query/users.gen.go index 63287a57..81389c80 100644 --- a/tests/.expect/dal_3/query/users.gen.go +++ b/tests/.expect/dal_3/query/users.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -184,6 +185,8 @@ type IUserDo interface { FirstOrCreate() (*model.User, error) FindByPage(offset int, limit int) (result []*model.User, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) IUserDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_4/query/banks.gen.go b/tests/.expect/dal_4/query/banks.gen.go index 30233266..c644b19a 100644 --- a/tests/.expect/dal_4/query/banks.gen.go +++ b/tests/.expect/dal_4/query/banks.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -16,7 +17,7 @@ import ( "gorm.io/plugin/dbresolver" - "gorm.io/gen/tests/.gen/dal_4/model" + "gorm.io/gen/tests/.gen/dal_3/model" ) func newBank(db *gorm.DB, opts ...gen.DOOption) bank { @@ -163,6 +164,8 @@ type IBankDo interface { FirstOrCreate() (*model.Bank, error) FindByPage(offset int, limit int) (result []*model.Bank, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) IBankDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_4/query/credit_cards.gen.go b/tests/.expect/dal_4/query/credit_cards.gen.go index 5543f328..217978ad 100644 --- a/tests/.expect/dal_4/query/credit_cards.gen.go +++ b/tests/.expect/dal_4/query/credit_cards.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -16,7 +17,7 @@ import ( "gorm.io/plugin/dbresolver" - "gorm.io/gen/tests/.gen/dal_4/model" + "gorm.io/gen/tests/.gen/dal_3/model" ) func newCreditCard(db *gorm.DB, opts ...gen.DOOption) creditCard { @@ -177,6 +178,8 @@ type ICreditCardDo interface { FirstOrCreate() (*model.CreditCard, error) FindByPage(offset int, limit int) (result []*model.CreditCard, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) ICreditCardDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_4/query/customers.gen.go b/tests/.expect/dal_4/query/customers.gen.go index 5e81eb4c..b1824d5c 100644 --- a/tests/.expect/dal_4/query/customers.gen.go +++ b/tests/.expect/dal_4/query/customers.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -16,7 +17,7 @@ import ( "gorm.io/plugin/dbresolver" - "gorm.io/gen/tests/.gen/dal_4/model" + "gorm.io/gen/tests/.gen/dal_3/model" ) func newCustomer(db *gorm.DB, opts ...gen.DOOption) customer { @@ -167,6 +168,8 @@ type ICustomerDo interface { FirstOrCreate() (*model.Customer, error) FindByPage(offset int, limit int) (result []*model.Customer, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) ICustomerDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_4/query/people.gen.go b/tests/.expect/dal_4/query/people.gen.go index eb4933ca..6b844f24 100644 --- a/tests/.expect/dal_4/query/people.gen.go +++ b/tests/.expect/dal_4/query/people.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -16,7 +17,7 @@ import ( "gorm.io/plugin/dbresolver" - "gorm.io/gen/tests/.gen/dal_4/model" + "gorm.io/gen/tests/.gen/dal_3/model" ) func newPerson(db *gorm.DB, opts ...gen.DOOption) person { @@ -231,6 +232,8 @@ type IPersonDo interface { FirstOrCreate() (*model.Person, error) FindByPage(offset int, limit int) (result []*model.Person, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) IPersonDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_4/query/users.gen.go b/tests/.expect/dal_4/query/users.gen.go index 41a7c76b..fc4d5e12 100644 --- a/tests/.expect/dal_4/query/users.gen.go +++ b/tests/.expect/dal_4/query/users.gen.go @@ -189,6 +189,8 @@ type IUserDo interface { FirstOrCreate() (*model.User, error) FindByPage(offset int, limit int) (result []*model.User, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) IUserDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_5/query/users.gen.go b/tests/.expect/dal_5/query/users.gen.go index 2a36a48c..3dccc403 100644 --- a/tests/.expect/dal_5/query/users.gen.go +++ b/tests/.expect/dal_5/query/users.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -184,6 +185,8 @@ type IUserDo interface { FirstOrCreate() (*model.User, error) FindByPage(offset int, limit int) (result []*model.User, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) IUserDo UnderlyingDB() *gorm.DB diff --git a/tests/.expect/dal_6/query/users.gen.go b/tests/.expect/dal_6/query/users.gen.go index 13ad2815..1482c8ba 100644 --- a/tests/.expect/dal_6/query/users.gen.go +++ b/tests/.expect/dal_6/query/users.gen.go @@ -6,6 +6,7 @@ package query import ( "context" + "database/sql" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -184,6 +185,8 @@ type IUserDo interface { FirstOrCreate() (*model.User, error) FindByPage(offset int, limit int) (result []*model.User, count int64, err error) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) + Rows() (*sql.Rows, error) + Row() *sql.Row Scan(result interface{}) (err error) Returning(value interface{}, columns ...string) IUserDo UnderlyingDB() *gorm.DB