Skip to content

Commit

Permalink
Reduce map lookup in ColumnTypeDatabaseTypeName.
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed May 25, 2023
1 parent d3e4fe6 commit f095c81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion collations.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package mysql

const defaultCollation = "utf8mb4_general_ci"
const binaryCollation = "binary"
const binaryCollationID = 63

// A list of available collations mapped to the internal ID.
// To update this map use the following MySQL query:
Expand Down
16 changes: 8 additions & 8 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (mf *mysqlField) typeDatabaseName() string {
case fieldTypeBit:
return "BIT"
case fieldTypeBLOB:
if mf.charSet != collations[binaryCollation] {
if mf.charSet != binaryCollationID {
return "TEXT"
}
return "BLOB"
Expand Down Expand Up @@ -49,7 +49,7 @@ func (mf *mysqlField) typeDatabaseName() string {
}
return "INT"
case fieldTypeLongBLOB:
if mf.charSet != collations[binaryCollation] {
if mf.charSet != binaryCollationID {
return "LONGTEXT"
}
return "LONGBLOB"
Expand All @@ -59,7 +59,7 @@ func (mf *mysqlField) typeDatabaseName() string {
}
return "BIGINT"
case fieldTypeMediumBLOB:
if mf.charSet != collations[binaryCollation] {
if mf.charSet != binaryCollationID {
return "MEDIUMTEXT"
}
return "MEDIUMBLOB"
Expand All @@ -77,7 +77,7 @@ func (mf *mysqlField) typeDatabaseName() string {
}
return "SMALLINT"
case fieldTypeString:
if mf.charSet == collations[binaryCollation] {
if mf.charSet == binaryCollationID {
return "BINARY"
}
return "CHAR"
Expand All @@ -91,17 +91,17 @@ func (mf *mysqlField) typeDatabaseName() string {
}
return "TINYINT"
case fieldTypeTinyBLOB:
if mf.charSet != collations[binaryCollation] {
if mf.charSet != binaryCollationID {
return "TINYTEXT"
}
return "TINYBLOB"
case fieldTypeVarChar:
if mf.charSet == collations[binaryCollation] {
if mf.charSet == binaryCollationID {
return "VARBINARY"
}
return "VARCHAR"
case fieldTypeVarString:
if mf.charSet == collations[binaryCollation] {
if mf.charSet == binaryCollationID {
return "VARBINARY"
}
return "VARCHAR"
Expand Down Expand Up @@ -194,7 +194,7 @@ func (mf *mysqlField) scanType() reflect.Type {

case fieldTypeBit, fieldTypeTinyBLOB, fieldTypeMediumBLOB, fieldTypeLongBLOB,
fieldTypeBLOB, fieldTypeVarString, fieldTypeString, fieldTypeGeometry:
if mf.charSet == 63 /* binary */ {
if mf.charSet == binaryCollationID {
return scanTypeBytes
}
fallthrough
Expand Down

0 comments on commit f095c81

Please sign in to comment.