database: remove old rethinkdb code

This commit is contained in:
Cadey Ratio 2017-04-28 18:09:14 -07:00
parent 3845626231
commit 8fd83ff179
1 changed files with 7 additions and 78 deletions

View File

@ -1,37 +1,9 @@
package database package database
import ( import (
"git.xeserv.us/xena/route/routerpc" proto "git.xeserv.us/xena/route/proto"
r "github.com/GoRethink/gorethink"
) )
// DB is the high level wrapper to the datastore.
type DB struct {
s *r.Session
}
// New takes a rethinkdb host and databasea and sets up a connection.
func New(host, database string) (*DB, error) {
session, err := r.Connect(r.ConnectOpts{
Address: host,
Database: database,
})
if err != nil {
return nil, err
}
db := &DB{
s: session,
}
return db, nil
}
var tables = []string{
"certs",
"routes",
}
// Route is a single HTTP route. // Route is a single HTTP route.
type Route struct { type Route struct {
ID string `gorethink:"id,omitempty" storm:"id"` ID string `gorethink:"id,omitempty" storm:"id"`
@ -41,54 +13,11 @@ type Route struct {
Token string `gorethink:"token" storm:"-"` // deprecated Token string `gorethink:"token" storm:"-"` // deprecated
} }
// SaveRoute adds the route to the database. // AsProto converts this into the protobuf.
func (db *DB) SaveRoute(resp *routerpc.AddHostResponse) error { func (r Route) AsProto() *proto.Route {
rt := &Route{ return &proto.Route{
Hostname: resp.Hostname, Id: r.ID,
Token: resp.Token, Creator: r.Creator,
Host: r.Hostname,
} }
// TODO: check if OnionHostname or Hostname actually exists in
// the database. RethinkDB doesn't support unique secondary indexes.
_, err := r.Table("routes").Insert(rt).RunWrite(db.s)
if err != nil {
return err
}
return nil
}
func (db *DB) GetRouteForHost(name string) (*Route, error) {
rows, err := r.Table("routes").Filter(map[string]interface{}{"hostname": name}).Run(db.s)
if err != nil {
return nil, err
}
result := &Route{}
err = rows.One(result)
if err != nil {
return nil, err
}
return result, nil
}
// GetAllRoutes fetches all of the route entries from the database
// and returns them. This is intended for the startup process or
// admin tooling.
func (db *DB) GetAllRoutes() ([]Route, error) {
rows, err := r.Table("routes").Run(db.s)
if err != nil {
return nil, err
}
var routes []Route
err = rows.All(&routes)
if err != nil {
return nil, err
}
return routes, nil
} }