Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mirshahriar committed May 21, 2018
1 parent 2c11c98 commit 7acce77
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
8 changes: 1 addition & 7 deletions pkg/dialect/postgres/dialect_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@ func (s *postgres) ColumnSignatureOf(field *descriptor.Field) string {
var sqlType, at = dialect.ParseColumnSignature(field, Type2SQLType)

switch sqlType.Name {
case Int:
case Integer:
if at.SetConstraint[dialect.ConstraintAutoIncrement] {
sqlType.Name = Serial
} else {
sqlType.Name = Integer
}
case BigInt:
if at.SetConstraint[dialect.ConstraintAutoIncrement] {
sqlType.Name = BigSerial
} else {
sqlType.Name = BigInt
}
case Float, Double:
sqlType.Name = Numeric
case Varchar:
size := sqlType.DefaultLength
if !(size > 0 && size < 65532) {
Expand Down
12 changes: 4 additions & 8 deletions pkg/dialect/postgres/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import (

// Supported Data type
const (
Int = "INT"
BigInt = "BIGINT"
Varchar = "VARCHAR"
Text = "TEXT"
Float = "FLOAT"
Double = "DOUBLE"
Numeric = "NUMERIC"
Bool = "BOOL"
Boolean = "BOOLEAN"
Expand All @@ -28,10 +25,9 @@ func Type2SQLType(field *descriptor.Field) (st dialect.SQLType) {
filedType := field.FieldDescriptorProto.GetType()
typeName := field.FieldDescriptorProto.GetTypeName()
switch filedType {
case protod.FieldDescriptorProto_TYPE_DOUBLE:
st = dialect.SQLType{Name: Double, DefaultLength: 0}
case protod.FieldDescriptorProto_TYPE_FLOAT:
st = dialect.SQLType{Name: Float, DefaultLength: 0}
case protod.FieldDescriptorProto_TYPE_DOUBLE,
protod.FieldDescriptorProto_TYPE_FLOAT:
st = dialect.SQLType{Name: Numeric, DefaultLength: 0}
case protod.FieldDescriptorProto_TYPE_INT64,
protod.FieldDescriptorProto_TYPE_UINT64,
protod.FieldDescriptorProto_TYPE_FIXED64,
Expand All @@ -43,7 +39,7 @@ func Type2SQLType(field *descriptor.Field) (st dialect.SQLType) {
protod.FieldDescriptorProto_TYPE_UINT32,
protod.FieldDescriptorProto_TYPE_SFIXED32,
protod.FieldDescriptorProto_TYPE_SINT32:
st = dialect.SQLType{Name: Int, DefaultLength: 0}
st = dialect.SQLType{Name: Integer, DefaultLength: 0}
case protod.FieldDescriptorProto_TYPE_BOOL:
st = dialect.SQLType{Name: Bool, DefaultLength: 0}
case protod.FieldDescriptorProto_TYPE_STRING:
Expand Down
6 changes: 3 additions & 3 deletions pkg/dialect/postgres/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ func TestType2SQLType(t *testing.T) {
Type: &fType,
},
}
assert.Equal(t, Type2SQLType(f).Name, Double)
assert.Equal(t, Type2SQLType(f).Name, Numeric)

fType = protod.FieldDescriptorProto_TYPE_FLOAT
assert.Equal(t, Type2SQLType(f).Name, Float)
assert.Equal(t, Type2SQLType(f).Name, Numeric)
fType = protod.FieldDescriptorProto_TYPE_SINT64
assert.Equal(t, Type2SQLType(f).Name, BigInt)
fType = protod.FieldDescriptorProto_TYPE_SINT32
assert.Equal(t, Type2SQLType(f).Name, Int)
assert.Equal(t, Type2SQLType(f).Name, Integer)
fType = protod.FieldDescriptorProto_TYPE_BOOL
assert.Equal(t, Type2SQLType(f).Name, Bool)
fType = protod.FieldDescriptorProto_TYPE_STRING
Expand Down

0 comments on commit 7acce77

Please sign in to comment.