PageRenderTime 1328ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/tasks/create.go

https://gitlab.com/IIC2173-2015-2-Grupo2/news-api
Go | 37 lines | 19 code | 9 blank | 9 comment | 2 complexity | bb40e7945ca7ee3d1bddfc9993293bd1 MD5 | raw file
  1. //usr/bin/env go run $0 "$@"; exit
  2. package tasks
  3. import (
  4. "fmt"
  5. "github.com/IIC2173-2015-2-Grupo2/news-api/models"
  6. "github.com/jinzhu/gorm"
  7. _ "github.com/lib/pq"
  8. )
  9. func main() {
  10. db, err := gorm.Open("postgres", "user=gslopez dbname=newsapi sslmode=disable")
  11. // db, err := gorm.Open("foundation", "dbname=gorm") // FoundationDB.
  12. // db, err := gorm.Open("mysql", "user:password@/dbname?charset=utf8&parseTime=True&loc=Local")
  13. // db, err := gorm.Open("sqlite3", "/tmp/gorm.db")
  14. // You can also use an existing database connection handle
  15. // dbSql, _ := sql.Open("postgres", "user=gorm dbname=gorm sslmode=disable")
  16. // db, _ := gorm.Open("postgres", dbSql)
  17. // Get database connection handle [*sql.DB](http://golang.org/pkg/database/sql/#DB)
  18. if err != nil {
  19. fmt.Printf(err.Error())
  20. fmt.Printf("Se debe crear la base de datos 'newsapi'")
  21. }
  22. db.DB()
  23. // Then you could invoke `*sql.DB`'s functions with it
  24. db.DB().Ping()
  25. db.DB().SetMaxIdleConns(10)
  26. db.DB().SetMaxOpenConns(100)
  27. db.CreateTable(&models.User{})
  28. }