From 3b392a31c5d825d4d050e192a4a3ec14af707c1c Mon Sep 17 00:00:00 2001 From: Oddur Magnusson Date: Fri, 16 Aug 2013 16:57:50 +0200 Subject: [PATCH] Adding support for custom types When you have a custom type, like type UserType int as a part of your struct, hood should use the underlaying Kind as the sql datatype. --- postgres.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/postgres.go b/postgres.go index 5f171c4..08492db 100644 --- a/postgres.go +++ b/postgres.go @@ -3,6 +3,7 @@ package hood import ( "fmt" _ "github.com/lib/pq" + "reflect" "strings" "time" ) @@ -43,6 +44,14 @@ func (d *postgres) SqlType(f interface{}, size int) string { } return "text" } + + switch reflect.TypeOf(f).Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32: + return "integer" + case reflect.Int64: + return "bigint" + } + panic("invalid sql type") }