chore: linting (#15813)
This commit is contained in:
@@ -43,14 +43,14 @@ func (p *PrimaryKeyEntry) GetTableName() protoreflect.FullName {
|
||||
func (p *PrimaryKeyEntry) String() string {
|
||||
if p.Value == nil {
|
||||
return fmt.Sprintf("PK %s %s -> _", p.TableName, fmtValues(p.Key))
|
||||
} else {
|
||||
valBz, err := stablejson.Marshal(p.Value)
|
||||
valStr := string(valBz)
|
||||
if err != nil {
|
||||
valStr = fmt.Sprintf("ERR %v", err)
|
||||
}
|
||||
return fmt.Sprintf("PK %s %s -> %s", p.TableName, fmtValues(p.Key), valStr)
|
||||
}
|
||||
|
||||
valBz, err := stablejson.Marshal(p.Value)
|
||||
valStr := string(valBz)
|
||||
if err != nil {
|
||||
valStr = fmt.Sprintf("ERR %v", err)
|
||||
}
|
||||
return fmt.Sprintf("PK %s %s -> %s", p.TableName, fmtValues(p.Key), valStr)
|
||||
}
|
||||
|
||||
func fmtValues(values []protoreflect.Value) string {
|
||||
@@ -108,9 +108,9 @@ func fmtFields(fields []protoreflect.Name) string {
|
||||
func (i *IndexKeyEntry) String() string {
|
||||
if i.IsUnique {
|
||||
return fmt.Sprintf("UNIQ %s", i.string())
|
||||
} else {
|
||||
return fmt.Sprintf("IDX %s", i.string())
|
||||
}
|
||||
|
||||
return fmt.Sprintf("IDX %s", i.string())
|
||||
}
|
||||
|
||||
// SeqEntry represents a sequence for tables with auto-incrementing primary keys.
|
||||
|
||||
@@ -177,11 +177,12 @@ func (cdc *KeyCodec) CompareKeys(values1, values2 []protoreflect.Value) int {
|
||||
}
|
||||
|
||||
// values are equal but arrays of different length
|
||||
if j == k {
|
||||
switch {
|
||||
case j == k:
|
||||
return 0
|
||||
} else if j < k {
|
||||
case j < k:
|
||||
return -1
|
||||
} else {
|
||||
default:
|
||||
return 1
|
||||
}
|
||||
}
|
||||
@@ -247,19 +248,20 @@ func (cdc KeyCodec) CheckValidRangeIterationKeys(start, end []protoreflect.Value
|
||||
y := end[i]
|
||||
|
||||
cmp = fieldCdc.Compare(x, y)
|
||||
if cmp > 0 {
|
||||
switch {
|
||||
case cmp > 0:
|
||||
return ormerrors.InvalidRangeIterationKeys.Wrapf(
|
||||
"start must be before end for field %s",
|
||||
cdc.fieldDescriptors[i].FullName(),
|
||||
)
|
||||
} else if !fieldCdc.IsOrdered() && cmp != 0 {
|
||||
case !fieldCdc.IsOrdered() && cmp != 0:
|
||||
descriptor := cdc.fieldDescriptors[i]
|
||||
return ormerrors.InvalidRangeIterationKeys.Wrapf(
|
||||
"field %s of kind %s doesn't support ordered range iteration",
|
||||
descriptor.FullName(),
|
||||
descriptor.Kind(),
|
||||
)
|
||||
} else if cmp < 0 {
|
||||
case cmp < 0:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,12 +107,12 @@ func (u UniqueKeyCodec) DecodeIndexKey(k, v []byte) (indexFields, primaryKey []p
|
||||
return ks, pk, nil
|
||||
}
|
||||
|
||||
func (cdc UniqueKeyCodec) extractPrimaryKey(keyValues, valueValues []protoreflect.Value) []protoreflect.Value {
|
||||
numPkFields := len(cdc.pkFieldOrder)
|
||||
func (u UniqueKeyCodec) extractPrimaryKey(keyValues, valueValues []protoreflect.Value) []protoreflect.Value {
|
||||
numPkFields := len(u.pkFieldOrder)
|
||||
pkValues := make([]protoreflect.Value, numPkFields)
|
||||
|
||||
for i := 0; i < numPkFields; i++ {
|
||||
fo := cdc.pkFieldOrder[i]
|
||||
fo := u.pkFieldOrder[i]
|
||||
if fo.inKey {
|
||||
pkValues[i] = keyValues[fo.i]
|
||||
} else {
|
||||
@@ -160,11 +160,10 @@ func (u UniqueKeyCodec) EncodeEntry(entry Entry) (k, v []byte, err error) {
|
||||
if !fieldOrder.inKey {
|
||||
// goes in values because it is not present in the index key otherwise
|
||||
values = append(values, value)
|
||||
} else {
|
||||
// does not go in values, but we need to verify that the value in index values matches the primary key value
|
||||
if u.keyCodec.fieldCodecs[fieldOrder.i].Compare(value, indexEntry.IndexValues[fieldOrder.i]) != 0 {
|
||||
return nil, nil, ormerrors.BadDecodeEntry.Wrapf("value in primary key does not match corresponding value in index key")
|
||||
}
|
||||
}
|
||||
// does not go in values, but we need to verify that the value in index values matches the primary key value
|
||||
if u.keyCodec.fieldCodecs[fieldOrder.i].Compare(value, indexEntry.IndexValues[fieldOrder.i]) != 0 {
|
||||
return nil, nil, ormerrors.BadDecodeEntry.Wrapf("value in primary key does not match corresponding value in index key")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user