diff --git a/example/bookstore/rpc/model/bookmodel.go b/example/bookstore/rpc/model/bookmodel.go index 094cdd35..76f9483f 100755 --- a/example/bookstore/rpc/model/bookmodel.go +++ b/example/bookstore/rpc/model/bookmodel.go @@ -18,7 +18,7 @@ var ( bookRowsExpectAutoSet = strings.Join(stringx.Remove(bookFieldNames, "create_time", "update_time"), ",") bookRowsWithPlaceHolder = strings.Join(stringx.Remove(bookFieldNames, "book", "create_time", "update_time"), "=?,") + "=?" - cacheBookBookPrefix = "cache#Book#book#" + bookPrefix = "cache#Book#book#" ) type ( @@ -46,9 +46,9 @@ func (m *BookModel) Insert(data Book) (sql.Result, error) { } func (m *BookModel) FindOne(book string) (*Book, error) { - bookBookKey := fmt.Sprintf("%s%v", cacheBookBookPrefix, book) + bookKey := fmt.Sprintf("%s%v", bookPrefix, book) var resp Book - err := m.QueryRow(&resp, bookBookKey, func(conn sqlx.SqlConn, v interface{}) error { + err := m.QueryRow(&resp, bookKey, func(conn sqlx.SqlConn, v interface{}) error { query := `select ` + bookRows + ` from ` + m.table + ` where book = ? limit 1` return conn.QueryRow(v, query, book) }) @@ -63,19 +63,19 @@ func (m *BookModel) FindOne(book string) (*Book, error) { } func (m *BookModel) Update(data Book) error { - bookBookKey := fmt.Sprintf("%s%v", cacheBookBookPrefix, data.Book) + bookKey := fmt.Sprintf("%s%v", bookPrefix, data.Book) _, err := m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) { query := `update ` + m.table + ` set ` + bookRowsWithPlaceHolder + ` where book = ?` return conn.Exec(query, data.Price, data.Book) - }, bookBookKey) + }, bookKey) return err } func (m *BookModel) Delete(book string) error { - bookBookKey := fmt.Sprintf("%s%v", cacheBookBookPrefix, book) + bookKey := fmt.Sprintf("%s%v", bookPrefix, book) _, err := m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) { query := `delete from ` + m.table + ` where book = ?` return conn.Exec(query, book) - }, bookBookKey) + }, bookKey) return err } diff --git a/go.sum b/go.sum index ab115321..916a67be 100644 --- a/go.sum +++ b/go.sum @@ -425,6 +425,7 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=