rethinkdb.go 780 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package stores
  2. import (
  3. "time"
  4. log "github.com/alecthomas/log4go"
  5. r "github.com/dancannon/gorethink"
  6. )
  7. type rethinkStore struct {
  8. session *r.Session
  9. }
  10. type RethinkCfg struct {
  11. DatabaseName string
  12. }
  13. type Account struct {
  14. Id int `gorethink:"id"`
  15. NextDashboardId int
  16. }
  17. func NewRethinkStore(config *RethinkCfg) *rethinkStore {
  18. log.Info("Initializing rethink storage")
  19. session, err := r.Connect(r.ConnectOpts{
  20. Address: "localhost:28015",
  21. Database: config.DatabaseName,
  22. MaxIdle: 10,
  23. IdleTimeout: time.Second * 10,
  24. })
  25. if err != nil {
  26. log.Crash("Failed to connect to rethink database %v", err)
  27. }
  28. createRethinkDBTablesAndIndices(config, session)
  29. return &rethinkStore{
  30. session: session,
  31. }
  32. }
  33. func (self *rethinkStore) Close() {}