Exemplo n.º 1
0
func GetTmUserByName(username string, db *sqlx.DB) (TmUser, error) {
	ret := []TmUser{}
	// this works in pq - $1
	// err := db.GlobalDB.Get(&ret, "select * from tm_user where username=$1", username)
	// if err != nil {
	// 	log.Println(err)
	// }

	// this works in mysql - ?
	// err := db.GlobalDB.Get(&ret, "select * from tm_user where username=?", username)
	// if err != nil {
	// 	log.Println(err)
	// }

	// this works in both
	arg := TmUser{Username: null.StringFrom(username)}
	nstmt, err := db.PrepareNamed(`select * from tm_user where username=:username`)
	if err != nil {
		log.Println(err)
		return TmUser{}, err
	}
	defer nstmt.Close()

	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return TmUser{}, err
	}
	if len(ret) != 1 {
		err = errors.New("Username " + username + " is not unique!")
		return TmUser{}, err
	}

	return ret[0], err
}
Exemplo n.º 2
0
func newRepository(db *sqlx.DB) (*repository, error) {
	r := repository{db: db}

	stmts := map[string]**sqlx.NamedStmt{
		findMood:       &r.findMood,
		setMood:        &r.setMood,
		deleteMood:     &r.deleteMood,
		insertConvo:    &r.insertConvo,
		getConvo:       &r.getConvo,
		deleteConvo:    &r.deleteConvo,
		findConvoLines: &r.findConvoLines,
		insertLine:     &r.insertLine,
		getLine:        &r.getLine,
		deleteLine:     &r.deleteLine,

		fmt.Sprintf(listConvos, ">", "ASC"):  &r.listConvosAsc,
		fmt.Sprintf(listConvos, "<", "DESC"): &r.listConvosDesc,
		fmt.Sprintf(listMoods, ">", "ASC"):   &r.listMoodsAsc,
		fmt.Sprintf(listMoods, "<", "DESC"):  &r.listMoodsDesc,
	}

	for sqlStr, stmt := range stmts {
		prepped, err := db.PrepareNamed(sqlStr)
		*stmt = prepped
		if err != nil {
			return nil, errors.Annotatef(err, "preparing statement %s", sqlStr)
		}
		r.closers = append(r.closers, prepped)
	}

	return &r, nil
}
Exemplo n.º 3
0
func (r Rock) Create(db *sqlx.DB, m *rock.Model) error {
	stmt, err := db.PrepareNamed(`INSERT INTO rocks (latitude, longitude) VALUES (:latitude, :longitude) RETURNING *`)
	if err != nil {
		log.Fatal(err)
	}

	err = stmt.Get(m, m)

	return err
}
Exemplo n.º 4
0
// @Title getGooseDbVersionById
// @Description retrieves the goose_db_version information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    GooseDbVersion
// @Resource /api/2.0
// @Router /api/2.0/goose_db_version/{id} [get]
func getGooseDbVersionById(id int, db *sqlx.DB) (interface{}, error) {
	ret := []GooseDbVersion{}
	arg := GooseDbVersion{Id: int64(id)}
	nstmt, err := db.PrepareNamed(`select * from goose_db_version where id=:id`)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 5
0
// \todo add port (Servers PK is a compound key, host_name and port
func getCSConfigRemap(serverName string, db *sqlx.DB) ([]CsconfigRemap, error) {
	ret := []CsconfigRemap{}
	arg := api.Servers{HostName: serverName}
	nstmt, err := db.PrepareNamed(`select * from csconfig_remap where host_name=:host_name`)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 6
0
func getCSConfigParams(profile int64, db *sqlx.DB) ([]CsconfigParam, error) {
	ret := []CsconfigParam{}
	arg := CsconfigParam{Profile: profile}
	nstmt, err := db.PrepareNamed(`select * from csconfig_params where profile=:profile`)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 7
0
func getCSConfigRemap(serverId int64, db *sqlx.DB) ([]CsconfigRemap, error) {
	ret := []CsconfigRemap{}
	arg := api.Server{Id: serverId}
	nstmt, err := db.PrepareNamed(`select * from csconfig_remap where server_id=:id`)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 8
0
// @Title getTypeById
// @Description retrieves the type information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Type
// @Resource /api/2.0
// @Router /api/2.0/type/{id} [get]
func getTypeById(id int, db *sqlx.DB) (interface{}, error) {
	ret := []Type{}
	arg := Type{}
	arg.Id = int64(id)
	queryStr := "select *, concat('" + API_PATH + "type/', id) as self "
	queryStr += " from type where id=:id"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 9
0
func GetServerByName(serverName string, db *sqlx.DB) (Server, error) {

	ret := []Server{}
	arg := Server{HostName: serverName}
	nstmt, err := db.PrepareNamed(`select * from server where host_name=:host_name`)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
	}
	if len(ret) != 1 {
		err = errors.New("Host name " + serverName + " is not unique!")
	}
	nstmt.Close()
	return ret[0], err
}
// @Title getFederationResolversById
// @Description retrieves the federation_resolvers information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    FederationResolvers
// @Resource /api/2.0
// @Router /api/2.0/federation_resolvers/{id} [get]
func getFederationResolver(id int64, db *sqlx.DB) (interface{}, error) {
	ret := []FederationResolvers{}
	arg := FederationResolvers{}
	arg.Id = id
	queryStr := "select *, concat('" + API_PATH + "federation_resolvers/', id) as self"
	queryStr += " from federation_resolvers WHERE id=:id"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 11
0
// @Title getLogById
// @Description retrieves the log information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Log
// @Resource /api/2.0
// @Router /api/2.0/log/{id} [get]
func getLog(id int64, db *sqlx.DB) (interface{}, error) {
	ret := []Log{}
	arg := Log{}
	arg.Id = id
	queryStr := "select *, concat('" + API_PATH + "log/', id) as self"
	queryStr += " from log WHERE id=:id"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 12
0
Arquivo: hub.go Projeto: jhbsz/cloud
func (h *Hub) Delete(db *sqlx.DB) error {
	nstmt, err := db.PrepareNamed(`DELETE FROM hubs
	WHERE slug = (:slug)
	RETURNING *;
	`)
	if err != nil {
		return err
	}
	defer nstmt.Close()

	err = nstmt.QueryRow(h).StructScan(h)
	// TODO?: Handle possible error cases? Eg...
	// hub record_not_found error would have already been caught in Get Method above.
	return err
}
Exemplo n.º 13
0
// @Title getRolesById
// @Description retrieves the roles information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Roles
// @Resource /api/2.0
// @Router /api/2.0/roles/{id} [get]
func getRole(name string, db *sqlx.DB) (interface{}, error) {
	ret := []Roles{}
	arg := Roles{}
	arg.Name = name
	queryStr := "select *, concat('" + API_PATH + "roles/', name) as self"
	queryStr += " from roles WHERE name=:name"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
// @Title getDeliveryservicesUsersById
// @Description retrieves the deliveryservices_users information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    DeliveryservicesUsers
// @Resource /api/2.0
// @Router /api/2.0/deliveryservices_users/{id} [get]
func getDeliveryservicesUser(deliveryservice string, username string, db *sqlx.DB) (interface{}, error) {
	ret := []DeliveryservicesUsers{}
	arg := DeliveryservicesUsers{}
	arg.Deliveryservice = deliveryservice
	arg.Username = username
	queryStr := "select *, concat('" + API_PATH + "deliveryservices_users', '/deliveryservice/', deliveryservice, '/username/', username) as self"
	queryStr += " from deliveryservices_users WHERE deliveryservice=:deliveryservice AND username=:username"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 15
0
// @Title getFederationUsersById
// @Description retrieves the federation_users information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    FederationUsers
// @Resource /api/2.0
// @Router /api/2.0/federation_users/{id} [get]
func getFederationUser(federationId int64, username string, db *sqlx.DB) (interface{}, error) {
	ret := []FederationUsers{}
	arg := FederationUsers{}
	arg.FederationId = federationId
	arg.Username = username
	queryStr := "select *, concat('" + API_PATH + "federation_users', '/federation_id/', federation_id, '/username/', username) as self"
	queryStr += " from federation_users WHERE federation_id=:federation_id AND username=:username"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
// @Title getProfilesParametersById
// @Description retrieves the profiles_parameters information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    ProfilesParameters
// @Resource /api/2.0
// @Router /api/2.0/profiles_parameters/{id} [get]
func getProfilesParameter(profile string, parameterId int64, db *sqlx.DB) (interface{}, error) {
	ret := []ProfilesParameters{}
	arg := ProfilesParameters{}
	arg.Profile = profile
	arg.ParameterId = parameterId
	queryStr := "select *, concat('" + API_PATH + "profiles_parameters', '/profile/', profile, '/parameter_id/', parameter_id) as self"
	queryStr += " from profiles_parameters WHERE profile=:profile AND parameter_id=:parameter_id"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 17
0
// @Title getAsnsById
// @Description retrieves the asns information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Asns
// @Resource /api/2.0
// @Router /api/2.0/asns/{id} [get]
func getAsn(asn int64, db *sqlx.DB) (interface{}, error) {
	ret := []Asns{}
	arg := Asns{}
	arg.Asn = asn
	queryStr := "select *, concat('" + API_PATH + "asns/', asn) as self"
	queryStr += ", concat('" + API_PATH + "cachegroups/', cachegroups) as cachegroups_name_ref"
	queryStr += " from asns WHERE asn=:asn"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 18
0
// @Title getExtensionsById
// @Description retrieves the extensions information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Extensions
// @Resource /api/2.0
// @Router /api/2.0/extensions/{id} [get]
func getExtension(name string, db *sqlx.DB) (interface{}, error) {
	ret := []Extensions{}
	arg := Extensions{}
	arg.Name = name
	queryStr := "select *, concat('" + API_PATH + "extensions/', name) as self"
	queryStr += ", concat('" + API_PATH + "extensions_types/', type) as extensions_types_name_ref"
	queryStr += " from extensions WHERE name=:name"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
// @Title getDeliveryservicesRegexesById
// @Description retrieves the deliveryservices_regexes information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    DeliveryservicesRegexes
// @Resource /api/2.0
// @Router /api/2.0/deliveryservices_regexes/{id} [get]
func getDeliveryservicesRegex(deliveryservice string, regexId int64, db *sqlx.DB) (interface{}, error) {
	ret := []DeliveryservicesRegexes{}
	arg := DeliveryservicesRegexes{}
	arg.Deliveryservice = deliveryservice
	arg.RegexId = regexId
	queryStr := "select *, concat('" + API_PATH + "deliveryservices_regexes', '/deliveryservice/', deliveryservice, '/regex_id/', regex_id) as self"
	queryStr += " from deliveryservices_regexes WHERE deliveryservice=:deliveryservice AND regex_id=:regex_id"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 20
0
// @Title getRegexesById
// @Description retrieves the regexes information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Regexes
// @Resource /api/2.0
// @Router /api/2.0/regexes/{id} [get]
func getRegex(id int64, db *sqlx.DB) (interface{}, error) {
	ret := []Regexes{}
	arg := Regexes{}
	arg.Id = id
	queryStr := "select *, concat('" + API_PATH + "regexes/', id) as self"
	queryStr += ", concat('" + API_PATH + "regexes_types/', type) as regexes_types_name_ref"
	queryStr += " from regexes WHERE id=:id"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
// @Title getFederationsFederationResolversById
// @Description retrieves the federations_federation_resolvers information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    FederationsFederationResolvers
// @Resource /api/2.0
// @Router /api/2.0/federations_federation_resolvers/{id} [get]
func getFederationsFederationResolver(federationId int64, federationResolver int64, db *sqlx.DB) (interface{}, error) {
	ret := []FederationsFederationResolvers{}
	arg := FederationsFederationResolvers{}
	arg.FederationId = federationId
	arg.FederationResolver = federationResolver
	queryStr := "select *, concat('" + API_PATH + "federations_federation_resolvers', '/federation_id/', federation_id, '/federation_resolver/', federation_resolver) as self"
	queryStr += " from federations_federation_resolvers WHERE federation_id=:federation_id AND federation_resolver=:federation_resolver"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 22
0
// @Title getAsnById
// @Description retrieves the asn information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Asn
// @Resource /api/2.0
// @Router /api/2.0/asn/{id} [get]
func getAsnById(id int, db *sqlx.DB) (interface{}, error) {
	ret := []Asn{}
	arg := Asn{}
	arg.Id = int64(id)
	queryStr := "select *, concat('" + API_PATH + "asn/', id) as self "
	queryStr += ", concat('" + API_PATH + "cachegroup/', cachegroup) as cachegroup_id_ref"
	queryStr += " from asn where id=:id"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
// @Title getFederationsDeliveryservicesById
// @Description retrieves the federations_deliveryservices information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    FederationsDeliveryservices
// @Resource /api/2.0
// @Router /api/2.0/federations_deliveryservices/{id} [get]
func getFederationsDeliveryservice(federationId int64, deliveryservice string, db *sqlx.DB) (interface{}, error) {
	ret := []FederationsDeliveryservices{}
	arg := FederationsDeliveryservices{}
	arg.FederationId = federationId
	arg.Deliveryservice = deliveryservice
	queryStr := "select *, concat('" + API_PATH + "federations_deliveryservices', '/federation_id/', federation_id, '/deliveryservice/', deliveryservice) as self"
	queryStr += " from federations_deliveryservices WHERE federation_id=:federation_id AND deliveryservice=:deliveryservice"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 24
0
// @Title getRegionById
// @Description retrieves the region information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Region
// @Resource /api/2.0
// @Router /api/2.0/region/{id} [get]
func getRegionById(id int, db *sqlx.DB) (interface{}, error) {
	ret := []Region{}
	arg := Region{}
	arg.Id = int64(id)
	queryStr := "select *, concat('" + API_PATH + "region/', id) as self "
	queryStr += ", concat('" + API_PATH + "division/', division) as division_id_ref"
	queryStr += " from region where id=:id"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 25
0
// @Title getServercheckById
// @Description retrieves the servercheck information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Servercheck
// @Resource /api/2.0
// @Router /api/2.0/servercheck/{id} [get]
func getServercheckById(id int, db *sqlx.DB) (interface{}, error) {
	ret := []Servercheck{}
	arg := Servercheck{}
	arg.Id = int64(id)
	queryStr := "select *, concat('" + API_PATH + "servercheck/', id) as self "
	queryStr += ", concat('" + API_PATH + "server/', server) as server_id_ref"
	queryStr += " from servercheck where id=:id"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 26
0
// @Title getFederationResolverById
// @Description retrieves the federation_resolver information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    FederationResolver
// @Resource /api/2.0
// @Router /api/2.0/federation_resolver/{id} [get]
func getFederationResolverById(id int, db *sqlx.DB) (interface{}, error) {
	ret := []FederationResolver{}
	arg := FederationResolver{}
	arg.Id = int64(id)
	queryStr := "select *, concat('" + API_PATH + "federation_resolver/', id) as self "
	queryStr += ", concat('" + API_PATH + "type/', type) as type_id_ref"
	queryStr += " from federation_resolver where id=:id"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 27
0
// @Title getUsersById
// @Description retrieves the users information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Users
// @Resource /api/2.0
// @Router /api/2.0/users/{id} [get]
func GetUser(username string, db *sqlx.DB) (interface{}, error) {
	ret := []Users{}
	arg := Users{}
	arg.Username = username
	queryStr := "select *, concat('" + API_PATH + "users/', username) as self"
	queryStr += ", concat('" + API_PATH + "roles/', role) as roles_name_ref"
	queryStr += " from users WHERE username=:username"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
Exemplo n.º 28
0
// @Title getCachegroupsById
// @Description retrieves the cachegroups information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    Cachegroups
// @Resource /api/2.0
// @Router /api/2.0/cachegroups/{id} [get]
func getCachegroup(name string, db *sqlx.DB) (interface{}, error) {
	ret := []Cachegroups{}
	arg := Cachegroups{}
	arg.Name = name
	queryStr := "select *, concat('" + API_PATH + "cachegroups/', name) as self"
	queryStr += ", concat('" + API_PATH + "cachegroups/', parent_cachegroup) as cachegroups_name_ref"
	queryStr += ", concat('" + API_PATH + "cachegroups_types/', type) as cachegroups_types_name_ref"
	queryStr += " from cachegroups WHERE name=:name"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
// @Title getFederationDeliveryserviceById
// @Description retrieves the federation_deliveryservice information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    FederationDeliveryservice
// @Resource /api/2.0
// @Router /api/2.0/federation_deliveryservice/{id} [get]
func getFederationDeliveryserviceById(id int, db *sqlx.DB) (interface{}, error) {
	ret := []FederationDeliveryservice{}
	arg := FederationDeliveryservice{}
	arg.Links.FederationLink.ID = int64(id)
	queryStr := "select *, concat('" + API_PATH + "federation_deliveryservice/', id) as self "
	queryStr += ", concat('" + API_PATH + "federation/', federation) as federation_id_ref"
	queryStr += ", concat('" + API_PATH + "deliveryservice/', deliveryservice) as deliveryservice_id_ref"
	queryStr += " from federation_deliveryservice where Links.FederationLink.ID=:Links.FederationLink.ID"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}
// @Title getDeliveryserviceServerById
// @Description retrieves the deliveryservice_server information for a certain id
// @Accept  application/json
// @Param   id              path    int     false        "The row id"
// @Success 200 {array}    DeliveryserviceServer
// @Resource /api/2.0
// @Router /api/2.0/deliveryservice_server/{id} [get]
func getDeliveryserviceServerById(id int, db *sqlx.DB) (interface{}, error) {
	ret := []DeliveryserviceServer{}
	arg := DeliveryserviceServer{}
	arg.Links.DeliveryserviceLink.ID = int64(id)
	queryStr := "select *, concat('" + API_PATH + "deliveryservice_server/', id) as self "
	queryStr += ", concat('" + API_PATH + "deliveryservice/', deliveryservice) as deliveryservice_id_ref"
	queryStr += ", concat('" + API_PATH + "server/', server) as server_id_ref"
	queryStr += " from deliveryservice_server where Links.DeliveryserviceLink.ID=:Links.DeliveryserviceLink.ID"
	nstmt, err := db.PrepareNamed(queryStr)
	err = nstmt.Select(&ret, arg)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	nstmt.Close()
	return ret, nil
}