forked from AplaProject/go-apla
/
app_param.go
36 lines (31 loc) · 1.02 KB
/
app_param.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package model
// AppParam is model
type AppParam struct {
tableName string
ID int64 `gorm:"primary_key;not null"`
AppID int64 `gorm:"not null"`
Name string `gorm:"not null;size:100"`
Value string `gorm:"not null"`
Conditions string `gorm:"not null"`
}
// TableName returns name of table
func (sp *AppParam) TableName() string {
return sp.tableName
}
// SetTablePrefix is setting table prefix
func (sp *AppParam) SetTablePrefix(tablePrefix string) {
sp.tableName = tablePrefix + "_app_params"
}
// Get is retrieving model from database
func (sp *AppParam) Get(transaction *DbTransaction, app int64, name string) (bool, error) {
return isFound(GetDB(transaction).Where("app_id=? and name = ?", app, name).First(sp))
}
// GetAllAppParameters is returning all state parameters
func (sp *AppParam) GetAllAppParameters(app int64) ([]AppParam, error) {
parameters := make([]AppParam, 0)
err := DBConn.Table(sp.TableName()).Find(¶meters).Error
if err != nil {
return nil, err
}
return parameters, nil
}