publish.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package dao
  2. import (
  3. "database/sql"
  4. "fmt"
  5. )
  6. func PublishTempToDB(id, snowFlakeId int64) int64 { //上传临时数据,封面和动画地址默认。
  7. /* vd :=entities.Video2{
  8. AuthorId: id,
  9. PlayUrl: "http://pathcystore.oss-cn-shanghai.aliyuncs.com/verifysource/verify.mp4",
  10. CoverUrl: "http://pathcystore.oss-cn-shanghai.aliyuncs.com/verifysource/verify.jpg",
  11. FavoriteCount: 0,
  12. CommentCount: 0,
  13. IsFavorite: false,
  14. }
  15. res:=dao.Db.Table("video").Create(&vd)*/
  16. //ConnectDb()
  17. db, err := sql.Open("mysql", "root:97782078@tcp(127.0.0.1:3306)/douyin?charset=utf8&parseTime=True&loc=Local")
  18. if err = db.Ping(); err != nil {
  19. fmt.Println("没连上")
  20. }
  21. res, err := db.Exec("INSERT INTO video(id,author_id,play_url,cover_url,favorite_count,comment_count,is_favorite) values (?,?,?,?,0,0,false)", snowFlakeId, id, "http://pathcystore.oss-cn-shanghai.aliyuncs.com/verifysource/verify.mp4", "http://pathcystore.oss-cn-shanghai.aliyuncs.com/verifysource/verify.jpg")
  22. if err != nil {
  23. fmt.Println("bug了")
  24. }
  25. lastIns, _ := res.LastInsertId()
  26. fmt.Println(lastIns)
  27. //res.Last
  28. fmt.Print("新插入的ID为: ")
  29. fmt.Println(lastIns)
  30. return lastIns
  31. }