Commit 865a9bcd authored by szh's avatar szh

update models and sql

parent a4447955
......@@ -10,7 +10,7 @@ Target Server Type : MYSQL
Target Server Version : 50553
File Encoding : 65001
Date: 2019-10-09 09:31:51
Date: 2019-10-09 11:53:20
*/
SET FOREIGN_KEY_CHECKS=0;
......@@ -20,7 +20,9 @@ SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
DROP TABLE IF EXISTS `rasp_config`;
CREATE TABLE `rasp_config` (
`height` bigint(20) DEFAULT '0'
`height` bigint(20) DEFAULT '0',
`config` varchar(64) NOT NULL,
PRIMARY KEY (`config`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
......
......@@ -3,19 +3,20 @@ package models
type RaspConfig struct {
Model
Height int64 `json:"height"`
Config string `json:"config"`
}
// GetHeight get lastheight in chain33
func GetHeight() (int64, error) {
var list []*RaspConfig
err := db.Find(&list).Error
var rasp RaspConfig
err := db.Select("Height").Where("config = ?","height").First(&rasp).Error
if err != nil {
//if err == gorm.ErrRecordNotFound {
// return 0, err
//}
return 0,err
}
return list[0].Height, nil
return rasp.Height, nil
}
// EditArticle modify a single article
......@@ -31,6 +32,7 @@ func UpdateHeight(height int64) error {
func InitHeight() error {
config := RaspConfig{
Height: 0,
Config: "height",
}
if err := db.Create(&config).Error; err != nil {
return err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment