package data_manage

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// EdbPythonCode python指标运算代码
type EdbPythonCode struct {
	EdbPythonCodeId int    `orm:"column(edb_python_code_id);pk"`
	EdbInfoId       int    `description:"指标id"`
	EdbCode         string `description:"指标编码"`
	PythonCode      string `description:"python代码"`
	ModifyTime      time.Time
	CreateTime      time.Time
}

// Update 更新EdbPythonCode信息
func (edbPythonCode *EdbPythonCode) Update(cols []string) (err error) {
	o := orm.NewOrmUsingDB("data")
	_, err = o.Update(edbPythonCode, cols...)
	return
}

// AddEdbPythonCode python指标运算代码
func AddEdbPythonCode(item *EdbPythonCode) (lastId int64, err error) {
	o := orm.NewOrmUsingDB("data")
	lastId, err = o.Insert(item)
	return
}

// GetEdbPythonCodeById 根据指标id获取python代码
func GetEdbPythonCodeById(edbInfoId int) (item *EdbPythonCode, err error) {
	o := orm.NewOrmUsingDB("data")
	sql := ` SELECT * FROM edb_python_code WHERE edb_info_id=? `
	err = o.Raw(sql, edbInfoId).QueryRow(&item)
	return
}
