3 import "github.com/go-pg/pg"
5 type MarketConfig struct {
7 MarketName string `sql:",notnull"`
8 UserId int64 `sql:",notnull"`
9 Config map[string]string
12 func InsertMarketConfig(config *MarketConfig) error {
13 return DB.Insert(config)
16 func GetUserMarketConfig(userId int64, market string) (*MarketConfig, error) {
17 var config MarketConfig
19 err := DB.Model(&config).Where("user_id = ?", userId).Where("market_name = ?", market).First()
21 if err != nil && err != pg.ErrNoRows {
25 if err == pg.ErrNoRows {
32 func SetUserMarketConfig(userId int64, market string, newConfig map[string]string) (*MarketConfig, error) {
33 config := MarketConfig{
39 _, err := DB.Model(&config).
40 OnConflict("(user_id, market_name) DO UPDATE").
41 Set("config = ?", newConfig).