summaryrefslogtreecommitdiffstats
path: root/store/sql_store.go
diff options
context:
space:
mode:
authorFlorian Orben <florian.orben@gmail.com>2015-11-05 23:32:44 +0100
committerFlorian Orben <florian.orben@gmail.com>2015-11-05 23:33:21 +0100
commitb085bc2d56bdc98101b8cb50848aee248d42af28 (patch)
tree9e19e790ed53aa1fbaa4b5c0c5574e03ae801577 /store/sql_store.go
parent4b6eb56415c2085bc9078836b70b833b1e01a60d (diff)
downloadchat-b085bc2d56bdc98101b8cb50848aee248d42af28.tar.gz
chat-b085bc2d56bdc98101b8cb50848aee248d42af28.tar.bz2
chat-b085bc2d56bdc98101b8cb50848aee248d42af28.zip
PLT-857: Support for Incoming Webhooks - Try #2
Diffstat (limited to 'store/sql_store.go')
-rw-r--r--store/sql_store.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/store/sql_store.go b/store/sql_store.go
index e5c540e06..d2cca21d0 100644
--- a/store/sql_store.go
+++ b/store/sql_store.go
@@ -50,6 +50,15 @@ type SqlStore struct {
preference PreferenceStore
}
+type Column struct {
+ Field string
+ Type string
+ Null string
+ Key interface{}
+ Default interface{}
+ Extra interface{}
+}
+
func NewSqlStore() Store {
sqlStore := &SqlStore{}
@@ -455,6 +464,20 @@ func IsUniqueConstraintError(err string, mysql string, postgres string) bool {
return unique && field
}
+func (ss SqlStore) GetColumnInformation(tableName, columnName string) Column {
+ var col Column
+ err := ss.GetMaster().SelectOne(&col, "SHOW COLUMNS FROM "+tableName+" WHERE Field = :Columnname", map[string]interface{}{
+ "Columnname": columnName,
+ })
+ if err != nil {
+ l4g.Critical("Failed to get information for column %s from table %s: %v", tableName, columnName, err.Error())
+ time.Sleep(time.Second)
+ panic("Failed to get information for column " + tableName + " from table " + columnName + ": " + err.Error())
+ }
+
+ return col
+}
+
func (ss SqlStore) GetMaster() *gorp.DbMap {
return ss.master
}
@@ -529,6 +552,8 @@ func (me mattermConverter) ToDb(val interface{}) (interface{}, error) {
return model.ArrayToJson(t), nil
case model.EncryptStringMap:
return encrypt([]byte(utils.Cfg.SqlSettings.AtRestEncryptKey), model.MapToJson(t))
+ case model.StringInterface:
+ return model.StringInterfaceToJson(t), nil
}
return val, nil
@@ -572,6 +597,16 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
return json.Unmarshal(b, target)
}
return gorp.CustomScanner{new(string), target, binder}, true
+ case *model.StringInterface:
+ binder := func(holder, target interface{}) error {
+ s, ok := holder.(*string)
+ if !ok {
+ return errors.New("FromDb: Unable to convert StringInterface to *string")
+ }
+ b := []byte(*s)
+ return json.Unmarshal(b, target)
+ }
+ return gorp.CustomScanner{new(string), target, binder}, true
}
return gorp.CustomScanner{}, false