rethink.go
func (rs RethinkStore) CreateTable(store string, schema interface{}) (err error) {
	logger.Info("creating table " + store)
	var res []interface{}
	_ = r.DB(rs.Database).TableCreate(store).Exec(rs.Session)
	// if err != nil{
	// 	// logger.Warn("unable to create table ", "table", store)
	//
	// }
	result, err := r.DB(rs.Database).Table(store).IndexList().Run(rs.Session)
	if err != nil {
		panic(err)
	}
	if result.Err() != nil {
		panic(err)
	}
	result.All(&res)
	logger.Debug(store+" indexList", res)
	//also create indexes
	if schema != nil {
		s := schema.(map[string]interface{})
		if indexes, ok := s["index"].(map[string]interface{}); ok {
			for name, _vals := range indexes {
				if !hasIndex(name, res) {
					logger.Info("creating index", "name", name, "val", _vals)
					if vals, ok := _vals.([]interface{}); ok && len(vals) > 0 {
						logger.Info("creating compound index", "name", name, "vals", vals)
						if _, err = r.DB(rs.Database).Table(store).IndexCreateFunc(name, func(row r.Term) interface{} {
							index_fields := []interface{}{}
							for _, v := range vals {
								index_fields = append(index_fields, row.Field(v.(string)))
							}
							return index_fields
						}).RunWrite(rs.Session); err != nil {
							return
						}
					} else {
						logger.Info("creating index", "name", name)
						if err = r.DB(rs.Database).Table(store).IndexCreate(name).Exec(rs.Session); err != nil {
							// logger.Warn("cannot create index [" + name + "] in " + store)
							// logger.Warn("cannot create index")
							println(err.Error())

						} else {
							if err = r.DB(rs.Database).Table(store).IndexWait(name).Exec(rs.Session); err == nil {
								logger.Info("created index [" + name + "] in " + store)
							}
						}
					}
				}
			}
		}
	}

	return
}
func (rs RethinkStore) CreateTable(store string, schema interface{}) (err error) {
	logger.Info("creating table " + store)
	var res []interface{}
	_ = r.DB(rs.Database).TableCreate(store).Exec(rs.Session)
	// if err != nil{
	// 	// logger.Warn("unable to create table ", "table", store)
	//
	// }
	result, err := r.DB(rs.Database).Table(store).IndexList().Run(rs.Session)
	if err != nil {
		panic(err)
	}
	if result.Err() != nil {
		panic(err)
	}
	result.All(&res)
	logger.Debug(store+" indexList", res)
	//also create indexes
	if schema != nil {
		s := schema.(map[string]interface{})
		if indexes, ok := s["index"].(map[string]interface{}); ok {
			for name, _vals := range indexes {
				if !hasIndex(name, res) {
					logger.Info("creating index", "name", name, "val", _vals)
					if vals, ok := _vals.([]interface{}); ok && len(vals) > 0 {
						logger.Info("creating compound index", "name", name, "vals", vals)
						if _, err = r.DB(rs.Database).Table(store).IndexCreateFunc(name, func(row r.Term) interface{} {
							index_fields := []interface{}{}
							for _, v := range vals {
								index_fields = append(index_fields, row.Field(v.(string)))
							}
							return index_fields
						}).RunWrite(rs.Session); err != nil {
							return
						}
					} else {
						logger.Info("creating index", "name", name)
						if err = r.DB(rs.Database).Table(store).IndexCreate(name).Exec(rs.Session); err != nil {
							// logger.Warn("cannot create index [" + name + "] in " + store)
							// logger.Warn("cannot create index")
							println(err.Error())

						} else {
							if err = r.DB(rs.Database).Table(store).IndexWait(name).Exec(rs.Session); err == nil {
								logger.Info("created index [" + name + "] in " + store)
							}
						}
					}
				}
			}
		}
	}

	return
}
func ( rs RethinkStore ) CreateTable ( store string , schema interface { } ) ( err error ) { logger . Info ( " " + store ) var res [ ] interface { } _ = r . DB ( rs . Database ) . TableCreate ( store ) . Exec ( rs . Session ) // if err != nil{ // 	// logger.Warn("unable to create table ", "table", store) // // } result , err := r . DB ( rs . Database ) . Table ( store ) . IndexList ( ) . Run ( rs . Session ) if err != nil { panic ( err ) } if result . Err ( ) != nil { panic ( err ) } result . All ( & res ) logger . Debug ( store + " " , res ) //also create indexes if schema != nil { s := schema . ( map [ string ] interface { } ) if indexes , ok := s [ " " ] . ( map [ string ] interface { } ) ; ok { for name , _vals := range indexes { if ! hasIndex ( name , res ) { logger . Info ( " " , " " , name , " " , _vals ) if vals , ok := _vals . ( [ ] interface { } ) ; ok && len ( vals ) > 0 { logger . Info ( " " , " " , name , " " , vals ) if _ , err = r . DB ( rs . Database ) . Table ( store ) . IndexCreateFunc ( name , func ( row r . Term ) interface { } { index_fields := [ ] interface { } { } for _ , v := range vals { index_fields = append ( index_fields , row . Field ( v . ( string ) ) ) } return index_fields } ) . RunWrite ( rs . Session ) ; err != nil { return } } else { logger . Info ( " " , " " , name ) if err = r . DB ( rs . Database ) . Table ( store ) . IndexCreate ( name ) . Exec ( rs . Session ) ; err != nil { // logger.Warn("cannot create index [" + name + "] in " + store) // logger.Warn("cannot create index") println ( err . Error ( ) ) } else { if err = r . DB ( rs . Database ) . Table ( store ) . IndexWait ( name ) . Exec ( rs . Session ) ; err == nil { logger . Info ( " " + name + " " + store ) } } } } } } } return }
//TODO: fix index creation, indexes are not created properly
TODO : fix index creation indexes are not created properly