Skip to content

Instantly share code, notes, and snippets.

@HAOYUatHZ
Created January 15, 2019 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HAOYUatHZ/264cce3c4ea66e6c47203b894d4452d7 to your computer and use it in GitHub Desktop.
Save HAOYUatHZ/264cce3c4ea66e6c47203b894d4452d7 to your computer and use it in GitHub Desktop.
test gorm association
package main
import (
"fmt"
// "github.com/jinzhu/gorm"
log "github.com/sirupsen/logrus"
"github.com/blockcenter/config"
"github.com/blockcenter/database"
"github.com/blockcenter/database/orm"
)
func main() {
cfg := config.NewConfig()
db, err := database.NewMySQLDB(cfg.MySQL, cfg.Updater.MySQLConnCfg)
if err != nil {
log.WithField("err", err).Panic("initialize mysql db error")
}
utxo := &orm.Utxo{
Asset: &orm.Asset{ID: 2, CoinID: 1, Asset: "caonima"},
}
db.Master().Save(utxo)
fmt.Println(utxo)
}
/*
(/home/gavin/work/go/src/github.com/blockcenter/main.go:25)
[2019-01-15 10:45:05] [103.97ms] UPDATE `assets` SET `coin_id` = '1', `asset` = 'caonima', `alias` = '', `description` = '', `definition` = '', `decimals` = '0', `usd_price` = '0', `cny_price` = '0', `btc_price` = '0' WHERE `assets`.`id` = '2'
[0 rows affected or returned ]
(/home/gavin/work/go/src/github.com/blockcenter/main.go:25)
[2019-01-15 10:45:05] [114.43ms] SELECT * FROM `assets` WHERE `assets`.`id` = '2' ORDER BY `assets`.`id` ASC LIMIT 1
[0 rows affected or returned ]
(/home/gavin/work/go/src/github.com/blockcenter/main.go:25)
[2019-01-15 10:45:05] [97.89ms] INSERT INTO `assets` (`id`,`coin_id`,`asset`,`alias`,`description`,`definition`,`decimals`,`usd_price`,`cny_price`,`btc_price`) VALUES ('2','1','caonima','','','','0','0','0','0')
[1 rows affected or returned ]
(/home/gavin/work/go/src/github.com/blockcenter/main.go:25)
[2019-01-15 10:45:06] Error 1364: Field 'control_program' doesn't have a default value
(/home/gavin/work/go/src/github.com/blockcenter/main.go:25)
[2019-01-15 10:45:06] [116.10ms] INSERT INTO `utxos` (`block_height`,`valid_height`,`address_id`,`asset_id`,`is_spend`,`hash`,`amount`,`raw_data`,`lock_until`) VALUES ('0','0','0','2','false','','0','',NULL)
[0 rows affected or returned ]
&{0 0 0 0 2 false 0 <nil> {13765094122351233072 693230516 0x8a5140} {13765094122351233072 693230516 0x8a5140} <nil> 0xc4201c8280}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment