Adding proper comments

This commit is contained in:
Louis Brauer 2018-06-07 17:21:23 +02:00
parent 1aca53985b
commit 72f41543a4

View File

@ -10,6 +10,7 @@ import (
"strings" "strings"
"time" "time"
// Importing mssql driver package only in dialect file, otherwide not needed
_ "github.com/denisenkom/go-mssqldb" _ "github.com/denisenkom/go-mssqldb"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
) )
@ -205,20 +206,22 @@ func currentDatabaseAndTable(dialect gorm.Dialect, tableName string) (string, st
return dialect.CurrentDatabase(), tableName return dialect.CurrentDatabase(), tableName
} }
type Json struct { // JSON type to support easy handling of JSON data in character table fields
// using golang json.RawMessage for deferred decoding/encoding
type JSON struct {
json.RawMessage json.RawMessage
} }
// Value get value of Jsonb // Value get value of JSON
func (j Json) Value() (driver.Value, error) { func (j JSON) Value() (driver.Value, error) {
if len(j.RawMessage) == 0 { if len(j.RawMessage) == 0 {
return nil, nil return nil, nil
} }
return j.MarshalJSON() return j.MarshalJSON()
} }
// Scan scan value into Json // Scan scan value into JSON
func (j *Json) Scan(value interface{}) error { func (j *JSON) Scan(value interface{}) error {
str, ok := value.(string) str, ok := value.(string)
if !ok { if !ok {
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value (strcast):", value)) return errors.New(fmt.Sprint("Failed to unmarshal JSONB value (strcast):", value))