Ejemplo n.º 1
0
func SetupDB() *sqlx.DB {
	db := persistence.ConnectDb()
	db.Exec("DELETE from climbs")
	db.Exec("DELETE from rocks")

	return db
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()
	db := persistence.ConnectDb()

	// clear database
	fmt.Println("Clearing Database")
	factory.ClearDB(db)

	// create records
	r := factory.Rock{}
	c := factory.Climb{}

	fmt.Println(fmt.Sprintf("Generating %v records...", *n))
	for i := 0; i < *n; i++ {
		rm := rock.Model{
			Latitude:  float32(rand.Intn(60-20)+20) + (float32(rand.Intn(10)) * .1),
			Longitude: -float32(rand.Intn(130-60)+60) + (float32(rand.Intn(10)) * .1),
		}
		r.Create(db, &rm)

		cm := climb.Model{
			RockID:      rm.ID,
			Name:        fake.Words(),
			Rating:      rand.Intn(14),
			Description: fake.Sentences(),
		}
		c.Create(db, &cm)
		fmt.Println(fmt.Sprintf("%v generated", i+1))
	}

	fmt.Println("DONE")
}
Ejemplo n.º 3
0
func main() {
	port := os.Getenv("PORT")

	if port == "" {
		log.Fatal("$PORT must be set")
	}

	db := persistence.ConnectDb()

	router := mux.NewRouter()

	router.HandleFunc("/hello", hello)
	location.AddRoutes(router, db)
	climb.AddRoutes(router, db)
	rock.AddRoutes(router, db)

	http.ListenAndServe(":"+port, router)
}
Ejemplo n.º 4
0
package sql_test

import (
	"github.com/jmoiron/sqlx"
	"github.com/nicholasray/sandstone/lib/persistence"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"testing"
)

var db *sqlx.DB

func TestSql(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Sql Suite")
}

var _ = BeforeSuite(func() {
	db = persistence.ConnectDb()
})

var _ = AfterSuite(func() {
	db.Close()
})