refactor friendly name to just be name (#29)
This commit is contained in:
6 files changed
+109
-128
No files matched your search
@@ -19,14 +19,14 @@ Just some high-level usage highlights to get you started. Read the godocs for a
|
||||
err = rw.Create(context.Background(), user)
|
||||
|
||||
// There are reader methods like: LookupByPublicId,
|
||||
// LookupByFriendlyName, SearchBy, LookupBy, etc
|
||||
// LookupByName, SearchBy, LookupBy, etc
|
||||
// which will lookup resources for you and scan them into your Gorm struct
|
||||
err = rw.LookupByPublicId(context.Background(), foundUser)
|
||||
|
||||
// There's reader ScanRows that facilitates scanning rows from
|
||||
// a "raw" SQL query into your Gorm struct
|
||||
tx, err := rw.DB()
|
||||
where := "select * from test_users where friendly_name in ($1, $2)"
|
||||
where := "select * from test_users where name in ($1, $2)"
|
||||
rows, err := tx.Query(where, "alice", "bob")
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
|
||||
@@ -94,13 +94,12 @@ type StoreTestUser struct {
|
||||
UpdateTime *Timestamp `protobuf:"bytes,3,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
|
||||
// public_id is the used to access the AssignablScope via an API
|
||||
PublicId string `protobuf:"bytes,4,opt,name=public_id,json=publicId,proto3" json:"public_id,omitempty"`
|
||||
// FriendlyName is the optional friendly name used to
|
||||
// name is the optional friendly name used to
|
||||
// access the Scope via an API
|
||||
// @inject_tag: `gorm:"default:null"`
|
||||
FriendlyName string `protobuf:"bytes,5,opt,name=friendly_name,json=friendlyName,proto3" json:"friendly_name,omitempty" gorm:"default:null"`
|
||||
Name string `protobuf:"bytes,6,opt,name=name,proto3" json:"name,omitempty"`
|
||||
PhoneNumber string `protobuf:"bytes,7,opt,name=phone_number,json=phoneNumber,proto3" json:"phone_number,omitempty"`
|
||||
Email string `protobuf:"bytes,8,opt,name=email,proto3" json:"email,omitempty"`
|
||||
Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty" gorm:"default:null"`
|
||||
PhoneNumber string `protobuf:"bytes,6,opt,name=phone_number,json=phoneNumber,proto3" json:"phone_number,omitempty"`
|
||||
Email string `protobuf:"bytes,7,opt,name=email,proto3" json:"email,omitempty"`
|
||||
}
|
||||
|
||||
func (x *StoreTestUser) Reset() {
|
||||
@@ -163,13 +162,6 @@ func (x *StoreTestUser) GetPublicId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *StoreTestUser) GetFriendlyName() string {
|
||||
if x != nil {
|
||||
return x.FriendlyName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *StoreTestUser) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
@@ -207,12 +199,12 @@ type StoreTestCar struct {
|
||||
UpdateTime *Timestamp `protobuf:"bytes,3,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
|
||||
// public_id is the used to access the AssignablScope via an API
|
||||
PublicId string `protobuf:"bytes,4,opt,name=public_id,json=publicId,proto3" json:"public_id,omitempty"`
|
||||
// FriendlyName is the optional friendly name used to
|
||||
// name is the optional friendly name used to
|
||||
// access the Scope via an API
|
||||
// @inject_tag: `gorm:"default:null"`
|
||||
FriendlyName string `protobuf:"bytes,5,opt,name=friendly_name,json=friendlyName,proto3" json:"friendly_name,omitempty" gorm:"default:null"`
|
||||
Model string `protobuf:"bytes,6,opt,name=model,proto3" json:"model,omitempty"`
|
||||
Mpg int32 `protobuf:"varint,7,opt,name=mpg,proto3" json:"mpg,omitempty"`
|
||||
Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty" gorm:"default:null"`
|
||||
Model string `protobuf:"bytes,6,opt,name=model,proto3" json:"model,omitempty"`
|
||||
Mpg int32 `protobuf:"varint,7,opt,name=mpg,proto3" json:"mpg,omitempty"`
|
||||
}
|
||||
|
||||
func (x *StoreTestCar) Reset() {
|
||||
@@ -275,9 +267,9 @@ func (x *StoreTestCar) GetPublicId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *StoreTestCar) GetFriendlyName() string {
|
||||
func (x *StoreTestCar) GetName() string {
|
||||
if x != nil {
|
||||
return x.FriendlyName
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -312,12 +304,12 @@ type StoreTestRental struct {
|
||||
UpdateTime *Timestamp `protobuf:"bytes,3,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
|
||||
// public_id is the used to access the AssignablScope via an API
|
||||
PublicId string `protobuf:"bytes,4,opt,name=public_id,json=publicId,proto3" json:"public_id,omitempty"`
|
||||
// FriendlyName is the optional friendly name used to
|
||||
// name is the optional friendly name used to
|
||||
// access the Scope via an API
|
||||
// @inject_tag: `gorm:"default:null"`
|
||||
FriendlyName string `protobuf:"bytes,5,opt,name=friendly_name,json=friendlyName,proto3" json:"friendly_name,omitempty" gorm:"default:null"`
|
||||
UserId uint32 `protobuf:"varint,6,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
||||
CarId uint32 `protobuf:"varint,7,opt,name=car_id,json=carId,proto3" json:"car_id,omitempty"`
|
||||
Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty" gorm:"default:null"`
|
||||
UserId uint32 `protobuf:"varint,6,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
||||
CarId uint32 `protobuf:"varint,7,opt,name=car_id,json=carId,proto3" json:"car_id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *StoreTestRental) Reset() {
|
||||
@@ -380,9 +372,9 @@ func (x *StoreTestRental) GetPublicId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *StoreTestRental) GetFriendlyName() string {
|
||||
func (x *StoreTestRental) GetName() string {
|
||||
if x != nil {
|
||||
return x.FriendlyName
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -415,7 +407,7 @@ var file_controller_storage_db_db_test_v1_db_test_proto_rawDesc = []byte{
|
||||
0x12, 0x38, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52,
|
||||
0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0xca, 0x02, 0x0a, 0x0d, 0x53,
|
||||
0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0xa5, 0x02, 0x0a, 0x0d, 0x53,
|
||||
0x74, 0x6f, 0x72, 0x65, 0x54, 0x65, 0x73, 0x74, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02,
|
||||
0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x4c, 0x0a, 0x0b,
|
||||
0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
@@ -429,56 +421,51 @@ var file_controller_storage_db_db_test_v1_db_test_proto_rawDesc = []byte{
|
||||
0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70,
|
||||
0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c,
|
||||
0x69, 0x63, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x75, 0x62,
|
||||
0x6c, 0x69, 0x63, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x6c,
|
||||
0x79, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, 0x72,
|
||||
0x69, 0x65, 0x6e, 0x64, 0x6c, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61,
|
||||
0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x21,
|
||||
0x0a, 0x0c, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x07,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65,
|
||||
0x72, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x22, 0xa4, 0x02, 0x0a, 0x0c, 0x53, 0x74, 0x6f, 0x72,
|
||||
0x65, 0x54, 0x65, 0x73, 0x74, 0x43, 0x61, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x4c, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61,
|
||||
0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e,
|
||||
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61,
|
||||
0x67, 0x65, 0x2e, 0x64, 0x62, 0x2e, 0x64, 0x62, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x76, 0x31,
|
||||
0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61,
|
||||
0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x4c, 0x0a, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65,
|
||||
0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x63, 0x6f,
|
||||
0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65,
|
||||
0x2e, 0x64, 0x62, 0x2e, 0x64, 0x62, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x54,
|
||||
0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65,
|
||||
0x54, 0x69, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x69,
|
||||
0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x49,
|
||||
0x64, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x6c, 0x79, 0x5f, 0x6e, 0x61,
|
||||
0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64,
|
||||
0x6c, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x18,
|
||||
0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x12, 0x10, 0x0a, 0x03,
|
||||
0x6d, 0x70, 0x67, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6d, 0x70, 0x67, 0x22, 0xaf,
|
||||
0x02, 0x0a, 0x0f, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x6e, 0x74,
|
||||
0x61, 0x6c, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02,
|
||||
0x69, 0x64, 0x12, 0x4c, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d,
|
||||
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f,
|
||||
0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x64, 0x62, 0x2e,
|
||||
0x64, 0x62, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73,
|
||||
0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65,
|
||||
0x12, 0x4c, 0x0a, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18,
|
||||
0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c,
|
||||
0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x64, 0x62, 0x2e, 0x64, 0x62,
|
||||
0x5f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61,
|
||||
0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1b,
|
||||
0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x08, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x66,
|
||||
0x72, 0x69, 0x65, 0x6e, 0x64, 0x6c, 0x79, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x0c, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x6c, 0x79, 0x4e, 0x61, 0x6d, 0x65,
|
||||
0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28,
|
||||
0x0d, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x63, 0x61, 0x72,
|
||||
0x5f, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x63, 0x61, 0x72, 0x49, 0x64,
|
||||
0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68,
|
||||
0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x77, 0x61, 0x74, 0x63, 0x68, 0x74, 0x6f,
|
||||
0x77, 0x65, 0x72, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x64, 0x62, 0x2f,
|
||||
0x64, 0x62, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x3b, 0x64, 0x62, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x62,
|
||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x6c, 0x69, 0x63, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x68, 0x6f,
|
||||
0x6e, 0x65, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x0b, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05,
|
||||
0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61,
|
||||
0x69, 0x6c, 0x22, 0x93, 0x02, 0x0a, 0x0c, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x54, 0x65, 0x73, 0x74,
|
||||
0x43, 0x61, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52,
|
||||
0x02, 0x69, 0x64, 0x12, 0x4c, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69,
|
||||
0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72,
|
||||
0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x64, 0x62,
|
||||
0x2e, 0x64, 0x62, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65,
|
||||
0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d,
|
||||
0x65, 0x12, 0x4c, 0x0a, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65,
|
||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c,
|
||||
0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x64, 0x62, 0x2e, 0x64,
|
||||
0x62, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74,
|
||||
0x61, 0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12,
|
||||
0x1b, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x08, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
|
||||
0x12, 0x14, 0x0a, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x70, 0x67, 0x18, 0x07, 0x20,
|
||||
0x01, 0x28, 0x05, 0x52, 0x03, 0x6d, 0x70, 0x67, 0x22, 0x9e, 0x02, 0x0a, 0x0f, 0x53, 0x74, 0x6f,
|
||||
0x72, 0x65, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x12, 0x0e, 0x0a, 0x02,
|
||||
0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x4c, 0x0a, 0x0b,
|
||||
0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x0b, 0x32, 0x2b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73,
|
||||
0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x64, 0x62, 0x2e, 0x64, 0x62, 0x5f, 0x74, 0x65, 0x73,
|
||||
0x74, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a,
|
||||
0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x4c, 0x0a, 0x0b, 0x75, 0x70,
|
||||
0x64, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||
0x2b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x2e, 0x73, 0x74, 0x6f,
|
||||
0x72, 0x61, 0x67, 0x65, 0x2e, 0x64, 0x62, 0x2e, 0x64, 0x62, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x2e,
|
||||
0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x75, 0x70,
|
||||
0x64, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c,
|
||||
0x69, 0x63, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x75, 0x62,
|
||||
0x6c, 0x69, 0x63, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65,
|
||||
0x72, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72,
|
||||
0x49, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x63, 0x61, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01,
|
||||
0x28, 0x0d, 0x52, 0x05, 0x63, 0x61, 0x72, 0x49, 0x64, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74,
|
||||
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72,
|
||||
0x70, 0x2f, 0x77, 0x61, 0x74, 0x63, 0x68, 0x74, 0x6f, 0x77, 0x65, 0x72, 0x2f, 0x69, 0x6e, 0x74,
|
||||
0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x64, 0x62, 0x2f, 0x64, 0x62, 0x5f, 0x74, 0x65, 0x73, 0x74,
|
||||
0x3b, 0x64, 0x62, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -6,8 +6,7 @@ CREATE TABLE if not exists db_test_user (
|
||||
create_time timestamp with time zone default current_timestamp,
|
||||
update_time timestamp with time zone default current_timestamp,
|
||||
public_id text NOT NULL UNIQUE,
|
||||
friendly_name text UNIQUE,
|
||||
name text,
|
||||
name text UNIQUE,
|
||||
phone_number text,
|
||||
email text
|
||||
);
|
||||
@@ -16,7 +15,7 @@ CREATE TABLE if not exists db_test_car (
|
||||
create_time timestamp with time zone default current_timestamp,
|
||||
update_time timestamp with time zone default current_timestamp,
|
||||
public_id text NOT NULL UNIQUE,
|
||||
friendly_name text UNIQUE,
|
||||
name text UNIQUE,
|
||||
model text,
|
||||
mpg smallint
|
||||
);
|
||||
@@ -25,7 +24,7 @@ CREATE TABLE if not exists db_test_rental (
|
||||
create_time timestamp with time zone default current_timestamp,
|
||||
update_time timestamp with time zone default current_timestamp,
|
||||
public_id text NOT NULL UNIQUE,
|
||||
friendly_name text UNIQUE,
|
||||
name text UNIQUE,
|
||||
user_id bigint not null REFERENCES db_test_user(id),
|
||||
car_id bigint not null REFERENCES db_test_car(id)
|
||||
);
|
||||
+12
-12
@@ -16,8 +16,8 @@ import (
|
||||
|
||||
// Reader interface defines lookups/searching for resources
|
||||
type Reader interface {
|
||||
// LookupByFriendlyName will lookup resource by its friendly_name which must be unique
|
||||
LookupByFriendlyName(ctx context.Context, resource ResourceFriendlyNamer, opt ...Option) error
|
||||
// LookupByName will lookup resource by its friendly name which must be unique
|
||||
LookupByName(ctx context.Context, resource ResourceNamer, opt ...Option) error
|
||||
|
||||
// LookupByPublicId will lookup resource by its public_id which must be unique
|
||||
LookupByPublicId(ctx context.Context, resource ResourcePublicIder, opt ...Option) error
|
||||
@@ -77,9 +77,9 @@ type ResourcePublicIder interface {
|
||||
GetPublicId() string
|
||||
}
|
||||
|
||||
// ResourceFriendlyNamer defines an interface that LookupByFriendlyName() can use to get the resource's friendly name
|
||||
type ResourceFriendlyNamer interface {
|
||||
GetFriendlyName() string
|
||||
// ResourceNamer defines an interface that LookupByName() can use to get the resource's friendly name
|
||||
type ResourceNamer interface {
|
||||
GetName() string
|
||||
}
|
||||
|
||||
type OpType int
|
||||
@@ -381,10 +381,10 @@ func (w *GormReadWriter) DoTx(ctx context.Context, retries uint, backOff Backoff
|
||||
return info, nil
|
||||
}
|
||||
|
||||
// LookupByFriendlyName will lookup resource my its friendly_name which must be unique
|
||||
func (rw *GormReadWriter) LookupByFriendlyName(ctx context.Context, resource ResourceFriendlyNamer, opt ...Option) error {
|
||||
// LookupByName will lookup resource my its friendly name which must be unique
|
||||
func (rw *GormReadWriter) LookupByName(ctx context.Context, resource ResourceNamer, opt ...Option) error {
|
||||
if rw.Tx == nil {
|
||||
return errors.New("error tx nil for lookup by friendly name")
|
||||
return errors.New("error tx nil for lookup by name")
|
||||
}
|
||||
opts := getOpts(opt...)
|
||||
withDebug := opts.withDebug
|
||||
@@ -393,12 +393,12 @@ func (rw *GormReadWriter) LookupByFriendlyName(ctx context.Context, resource Res
|
||||
defer rw.Tx.LogMode(false)
|
||||
}
|
||||
if reflect.ValueOf(resource).Kind() != reflect.Ptr {
|
||||
return errors.New("error interface parameter must to be a pointer for lookup by friendly name")
|
||||
return errors.New("error interface parameter must to be a pointer for lookup by name")
|
||||
}
|
||||
if resource.GetFriendlyName() == "" {
|
||||
return errors.New("error friendly name empty string for lookup by friendly name")
|
||||
if resource.GetName() == "" {
|
||||
return errors.New("error name empty string for lookup by name")
|
||||
}
|
||||
return rw.Tx.Where("friendly_name = ?", resource.GetFriendlyName()).First(resource).Error
|
||||
return rw.Tx.Where("name = ?", resource.GetName()).First(resource).Error
|
||||
}
|
||||
|
||||
// LookupByPublicId will lookup resource my its public_id which must be unique
|
||||
|
||||
@@ -37,13 +37,13 @@ func TestGormReadWriter_Update(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
assert.Equal(foundUser.Id, user.Id)
|
||||
|
||||
user.FriendlyName = "friendly-" + id
|
||||
err = w.Update(context.Background(), user, []string{"FriendlyName"})
|
||||
user.Name = "friendly-" + id
|
||||
err = w.Update(context.Background(), user, []string{"Name"})
|
||||
assert.Nil(err)
|
||||
|
||||
err = w.LookupByPublicId(context.Background(), foundUser)
|
||||
assert.Nil(err)
|
||||
assert.Equal(foundUser.FriendlyName, user.FriendlyName)
|
||||
assert.Equal(foundUser.Name, user.Name)
|
||||
})
|
||||
t.Run("valid-WithOplog", func(t *testing.T) {
|
||||
w := GormReadWriter{Tx: db}
|
||||
@@ -63,8 +63,8 @@ func TestGormReadWriter_Update(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
assert.Equal(foundUser.Id, user.Id)
|
||||
|
||||
user.FriendlyName = "friendly-" + id
|
||||
err = w.Update(context.Background(), user, []string{"FriendlyName"},
|
||||
user.Name = "friendly-" + id
|
||||
err = w.Update(context.Background(), user, []string{"Name"},
|
||||
// write oplogs for this update
|
||||
WithOplog(
|
||||
TestWrapper(t),
|
||||
@@ -79,7 +79,7 @@ func TestGormReadWriter_Update(t *testing.T) {
|
||||
|
||||
err = w.LookupByPublicId(context.Background(), foundUser)
|
||||
assert.Nil(err)
|
||||
assert.Equal(foundUser.FriendlyName, user.FriendlyName)
|
||||
assert.Equal(foundUser.Name, user.Name)
|
||||
|
||||
var metadata store.Metadata
|
||||
err = db.Where("key = ? and value = ?", "resource-public-id", user.PublicId).First(&metadata).Error
|
||||
@@ -118,8 +118,8 @@ func TestGormReadWriter_Update(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
assert.Equal(foundUser.Id, user.Id)
|
||||
|
||||
user.FriendlyName = "friendly-" + id
|
||||
err = w.Update(context.Background(), user, []string{"FriendlyName"},
|
||||
user.Name = "friendly-" + id
|
||||
err = w.Update(context.Background(), user, []string{"Name"},
|
||||
WithOplog(
|
||||
nil,
|
||||
oplog.Metadata{
|
||||
@@ -149,8 +149,8 @@ func TestGormReadWriter_Update(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
assert.Equal(foundUser.Id, user.Id)
|
||||
|
||||
user.FriendlyName = "friendly-" + id
|
||||
err = w.Update(context.Background(), user, []string{"FriendlyName"},
|
||||
user.Name = "friendly-" + id
|
||||
err = w.Update(context.Background(), user, []string{"Name"},
|
||||
WithOplog(
|
||||
TestWrapper(t),
|
||||
nil,
|
||||
@@ -269,7 +269,7 @@ func TestGormReadWriter_Create(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestGormReadWriter_LookupByFriendlyName(t *testing.T) {
|
||||
func TestGormReadWriter_LookupByName(t *testing.T) {
|
||||
t.Parallel()
|
||||
cleanup, db := TestSetup(t, "migrations/postgres")
|
||||
defer cleanup()
|
||||
@@ -281,16 +281,15 @@ func TestGormReadWriter_LookupByFriendlyName(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
user, err := db_test.NewTestUser()
|
||||
assert.Nil(err)
|
||||
user.Name = "foo-" + id
|
||||
user.FriendlyName = "fn-" + id
|
||||
user.Name = "fn-" + id
|
||||
err = w.Create(context.Background(), user)
|
||||
assert.Nil(err)
|
||||
assert.True(user.Id != 0)
|
||||
|
||||
foundUser, err := db_test.NewTestUser()
|
||||
assert.Nil(err)
|
||||
foundUser.FriendlyName = "fn-" + id
|
||||
err = w.LookupByFriendlyName(context.Background(), foundUser)
|
||||
foundUser.Name = "fn-" + id
|
||||
err = w.LookupByName(context.Background(), foundUser)
|
||||
assert.Nil(err)
|
||||
assert.Equal(foundUser.Id, user.Id)
|
||||
})
|
||||
@@ -298,18 +297,18 @@ func TestGormReadWriter_LookupByFriendlyName(t *testing.T) {
|
||||
w := GormReadWriter{}
|
||||
foundUser, err := db_test.NewTestUser()
|
||||
assert.Nil(err)
|
||||
foundUser.FriendlyName = "fn-name"
|
||||
err = w.LookupByFriendlyName(context.Background(), foundUser)
|
||||
foundUser.Name = "fn-name"
|
||||
err = w.LookupByName(context.Background(), foundUser)
|
||||
assert.True(err != nil)
|
||||
assert.Equal("error tx nil for lookup by friendly name", err.Error())
|
||||
assert.Equal("error tx nil for lookup by name", err.Error())
|
||||
})
|
||||
t.Run("no-friendly-name-set", func(t *testing.T) {
|
||||
w := GormReadWriter{Tx: db}
|
||||
foundUser, err := db_test.NewTestUser()
|
||||
assert.Nil(err)
|
||||
err = w.LookupByFriendlyName(context.Background(), foundUser)
|
||||
err = w.LookupByName(context.Background(), foundUser)
|
||||
assert.True(err != nil)
|
||||
assert.Equal("error friendly name empty string for lookup by friendly name", err.Error())
|
||||
assert.Equal("error name empty string for lookup by name", err.Error())
|
||||
})
|
||||
t.Run("not-found", func(t *testing.T) {
|
||||
w := GormReadWriter{Tx: db}
|
||||
@@ -318,8 +317,8 @@ func TestGormReadWriter_LookupByFriendlyName(t *testing.T) {
|
||||
|
||||
foundUser, err := db_test.NewTestUser()
|
||||
assert.Nil(err)
|
||||
foundUser.FriendlyName = "fn-" + id
|
||||
err = w.LookupByFriendlyName(context.Background(), foundUser)
|
||||
foundUser.Name = "fn-" + id
|
||||
err = w.LookupByName(context.Background(), foundUser)
|
||||
assert.True(err != nil)
|
||||
assert.Equal(gorm.ErrRecordNotFound, err)
|
||||
})
|
||||
@@ -338,7 +337,6 @@ func TestGormReadWriter_LookupByPublicId(t *testing.T) {
|
||||
user, err := db_test.NewTestUser()
|
||||
assert.Nil(err)
|
||||
user.Name = "foo-" + id
|
||||
user.FriendlyName = "fn-" + id
|
||||
err = w.Create(context.Background(), user)
|
||||
assert.Nil(err)
|
||||
assert.True(user.PublicId != "")
|
||||
@@ -394,7 +392,6 @@ func TestGormReadWriter_LookupWhere(t *testing.T) {
|
||||
user, err := db_test.NewTestUser()
|
||||
assert.Nil(err)
|
||||
user.Name = "foo-" + id
|
||||
user.FriendlyName = "fn-" + id
|
||||
err = w.Create(context.Background(), user)
|
||||
assert.Nil(err)
|
||||
assert.True(user.PublicId != "")
|
||||
@@ -445,7 +442,6 @@ func TestGormReadWriter_SearchWhere(t *testing.T) {
|
||||
user, err := db_test.NewTestUser()
|
||||
assert.Nil(err)
|
||||
user.Name = "foo-" + id
|
||||
user.FriendlyName = "fn-" + id
|
||||
err = w.Create(context.Background(), user)
|
||||
assert.Nil(err)
|
||||
assert.True(user.PublicId != "")
|
||||
@@ -798,7 +794,7 @@ func TestGormReadWriter_ScanRows(t *testing.T) {
|
||||
assert.True(user.Id != 0)
|
||||
|
||||
tx, err := w.DB()
|
||||
where := "select * from db_test_user where friendly_name in ($1, $2)"
|
||||
where := "select * from db_test_user where name in ($1, $2)"
|
||||
rows, err := tx.Query(where, "alice", "bob")
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
|
||||
@@ -29,14 +29,13 @@ message StoreTestUser {
|
||||
// public_id is the used to access the AssignablScope via an API
|
||||
string public_id = 4;
|
||||
|
||||
// FriendlyName is the optional friendly name used to
|
||||
// name is the optional friendly name used to
|
||||
// access the Scope via an API
|
||||
// @inject_tag: `gorm:"default:null"`
|
||||
string friendly_name = 5;
|
||||
string name = 5;
|
||||
|
||||
string name = 6;
|
||||
string phone_number = 7;
|
||||
string email = 8;
|
||||
string phone_number = 6;
|
||||
string email = 7;
|
||||
}
|
||||
// TestCar for gorm test car model
|
||||
message StoreTestCar {
|
||||
@@ -54,10 +53,10 @@ message StoreTestCar {
|
||||
// public_id is the used to access the AssignablScope via an API
|
||||
string public_id = 4;
|
||||
|
||||
// FriendlyName is the optional friendly name used to
|
||||
// name is the optional friendly name used to
|
||||
// access the Scope via an API
|
||||
// @inject_tag: `gorm:"default:null"`
|
||||
string friendly_name = 5;
|
||||
string name = 5;
|
||||
|
||||
string model = 6;
|
||||
int32 mpg = 7;
|
||||
@@ -78,10 +77,10 @@ message StoreTestRental {
|
||||
// public_id is the used to access the AssignablScope via an API
|
||||
string public_id = 4;
|
||||
|
||||
// FriendlyName is the optional friendly name used to
|
||||
// name is the optional friendly name used to
|
||||
// access the Scope via an API
|
||||
// @inject_tag: `gorm:"default:null"`
|
||||
string friendly_name = 5;
|
||||
string name = 5;
|
||||
|
||||
uint32 user_id = 6;
|
||||
uint32 car_id = 7;
|
||||
|
||||
Reference in new issue
Block a user