Пример #1
5
func GetApps(txn gorp.SqlExecutor, fileIds []string) ([]*App, error) {
	if len(fileIds) <= 0 {
		return []*App{}, nil
	}

	args := make([]interface{}, len(fileIds))
	quarks := make([]string, len(fileIds))
	for i, fileId := range fileIds {
		args[i] = fileId
		quarks[i] = "?"
	}

	var apps []*App
	_, err := txn.Select(&apps, fmt.Sprintf("SELECT * FROM app WHERE file_id in (%s) ORDER BY id DESC", strings.Join(quarks, ",")), args...)
	if err != nil {
		return nil, err
	}

	return apps, nil
}
Пример #2
0
func (app *App) BundlesByPlatformType(txn gorp.SqlExecutor, platformType BundlePlatformType) ([]*Bundle, error) {
	var bundles []*Bundle
	_, err := txn.Select(&bundles, "SELECT * FROM bundle WHERE app_id = ? AND platform_type = ? ORDER BY id DESC", app.Id, platformType)
	if err != nil {
		return nil, err
	}
	return bundles, nil
}
Пример #3
0
func (app *App) Authorities(txn gorp.SqlExecutor) ([]*Authority, error) {
	var authorities []*Authority
	_, err := txn.Select(&authorities, "SELECT * FROM authority WHERE app_id = ? ORDER BY id ASC", app.Id)
	if err != nil {
		return nil, err
	}
	return authorities, nil
}
Пример #4
0
func (app *App) Bundles(txn gorp.SqlExecutor) ([]*Bundle, error) {
	var bundles []*Bundle
	_, err := txn.Select(&bundles, "SELECT * FROM bundle WHERE app_id = ? ORDER BY id DESC", app.Id)
	if err != nil {
		return nil, err
	}
	return bundles, nil
}
Пример #5
0
func Select(s gorp.SqlExecutor, builder squirrel.SelectBuilder, src interface{}) error {
	sql, args, err := builder.ToSql()
	if err != nil {
		return err
	}
	_, err = s.Select(src, sql, args...)
	return err
}
Пример #6
0
func GetSubjects(enc Encoder, db gorp.SqlExecutor) (int, string) {
	var subjects []models.DefaultStruct
	_, err := db.Select(&subjects, SQL_SELECT_SUBJECTS_BY_ID)
	if err != nil {
		checkErr(err, "SELECT SUBJECTS FAILED")
		return http.StatusInternalServerError, ""
	}
	return http.StatusOK, Must(enc.Encode(subjectsToIface(subjects)...))
}
func GetContact_types(enc Encoder, db gorp.SqlExecutor) (int, string) {
	var contact_types []models.DefaultStruct
	_, err := db.Select(&contact_types, SQL_CONTACT_TYPES_BY_ID)
	if err != nil {
		checkErr(err, "SELECT CONTACT TYPES FAILED")
		return http.StatusBadRequest, ""
	}
	return http.StatusOK, Must(enc.Encode(contact_typesToIface(contact_types)...))
}
Пример #8
0
func GetWarnings(enc Encoder, db gorp.SqlExecutor) (int, string) {

	var warnings []models.Warning
	_, err := db.Select(&warnings, SQL_WARNING_BYID)
	checkErr(err, "LIST ALL WARNINGS ERROR")

	if err != nil {
		return http.StatusInternalServerError, ""
	}
	return http.StatusOK, Must(enc.Encode(warningsToIface(warnings)...))
}
Пример #9
0
func GetMessages(enc Encoder, db gorp.SqlExecutor, parms martini.Params) (int, string) {
	var messages []models.DefaultStruct
	lang_key := parms["lang_key"]

	_, err := db.Select(&messages, SQL_MESSAGES_BY_LANG_KEY, lang_key)
	if err != nil {
		checkErr(err, "select failed")
		return http.StatusBadRequest, ""
	}

	return http.StatusOK, Must(enc.Encode(messagesToIface(messages)...))
}
Пример #10
0
func (i *Invite) RefreshMessages(s *gorp.SqlExecutor) error {
	var db gorp.SqlExecutor
	if s == nil {
		db = dbmap
	} else {
		db = *s
	}
	i.Messages = []Message{}
	query := "select * from message where invite = $1 order by id asc"
	_, err := db.Select(&i.Messages, query, i.Id)
	return err
}
Пример #11
0
func (device *NetworkDevice) PostGet(s gorp.SqlExecutor) error {
	device.Network = GetNetwork(map[string]interface{}{"sqlexecutor": s}, map[string]interface{}{"uuid": device.NetworkUUID})

	if _, err := s.Select(&device.Options, "select * from DeviceOption where DeviceUUID = ?", device.UUID); err != nil {
		panic(err)
	}

	if _, err := s.Select(&device.Addresses, "select * from DeviceAddress where DeviceUUID = ?", device.UUID); err != nil {
		panic(err)
	}

	return nil
}
Пример #12
0
// PostGet sets Utype and Flag information on the newly instantiated Profile.
func (p *Profile) PostGet(s gorp.SqlExecutor) error {
	var err error
	fq := "select flag.* from flag inner join profile_flag on (flag = id) where profile = $1"
	_, err = s.Select(&p.Flags, fq, p.Id)
	if err != nil {
		return err
	}

	tq := "select utype.* from utype inner join profile_utype on (utype = id) where profile = $1"
	_, err = s.Select(&p.Utypes, tq, p.Id)
	if err != nil {
		return err
	}

	return nil
}
Пример #13
0
func GetMessagesStats(enc Encoder, db gorp.SqlExecutor, user sessionauth.User) (int, string) {

	u := UserById(user.UniqueId().(int), db)

	if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {
		var messages []models.Messages

		_, err := db.Select(&messages, SQL_MESSAGES_ALL)
		if err != nil {
			checkErr(err, "select failed")
			return http.StatusBadRequest, ""
		}

		return http.StatusOK, Must(enc.Encode(messagesToIfaceM(messages)...))
	}

	return http.StatusUnauthorized, ""
}
Пример #14
0
func (i *Invite) RefreshAttendees(s *gorp.SqlExecutor) error {
	var db gorp.SqlExecutor
	if s == nil {
		db = dbmap
	} else {
		db = *s
	}
	i.Attendees = []Attendee{}
	query := "select profile.*, status from profile inner join profile_invite on (profile = id) where invite = $1"
	_, err := db.Select(&i.Attendees, query, i.Id)
	if err != nil {
		return err
	}
	for j := range i.Attendees {
		err := i.Attendees[j].Profile.PostGet(dbmap) // not done in this case by gorp, sigh
		if err != nil {
			return err
		}
	}
	return err
}
Пример #15
0
func (jail *Jail) PostGet(s gorp.SqlExecutor) error {
	jail.NetworkDevices = network.GetNetworkDevices(map[string]interface{}{"sqlexecutor": s}, jail)

	s.Select(&jail.Mounts, "select * from MountPoint where JailUUID = ? order by MountOrder", jail.UUID)
	s.Select(&jail.Options, "select * from JailOption where JailUUID = ?", jail.UUID)
	s.Select(&jail.Routes, "select * from Route WHERE VmUUID = ?", jail.UUID)
	if len(jail.HostName) == 0 {
		jail.HostName = jail.Name
	}

	jail.BootEnvironments = make(map[string]bool)

	jail.ZFSDatasetObj = zfs.GetDataset(jail.ZFSDataset)
	for _, rootDataset := range jail.ZFSDatasetObj.Children {
		if strings.HasPrefix(rootDataset.DatasetPath, jail.ZFSDataset+"/ROOT") {
			for _, dataset := range rootDataset.Children {
				if _, ok := dataset.Options["jailadmin:be_active"]; ok == true {
					jail.BootEnvironments[dataset.DatasetPath], _ = strconv.ParseBool(dataset.Options["jailadmin:be_active"])
				}
			}

			break
		}
	}

	return nil
}
Пример #16
0
func ListWarnings(entity models.Warn, enc Encoder, user sessionauth.User, db gorp.SqlExecutor) (int, string) {

	u := UserById(user.UniqueId().(int), db)

	if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {
		sql := "SELECT w.id, msg.name AS message, ct.name AS contact_type, w.contact, w.sent, w.created_date FROM warnings AS w "
		sql += "INNER JOIN messages AS msg ON (msg.id = w.id_message) "
		sql += "INNER JOIN contact_types AS ct ON (ct.id = w.id_contact_type) "
		sql += "ORDER BY w.created_date DESC "

		var warns []models.Warn
		_, err := db.Select(&warns, sql)
		checkErr(err, "SELECT ALL WARNINGS ERROR")

		if err != nil {
			return http.StatusBadRequest, ""
		}
		return http.StatusOK, Must(enc.Encode(warnsToIface(warns)...))

	}

	return http.StatusUnauthorized, ""

}
Пример #17
0
func (app *App) BundlesWithPager(txn gorp.SqlExecutor, page, limit int) (Bundles, int, error) {
	if page < 1 {
		page = 1
	}

	count, err := txn.SelectInt("SELECT COUNT(*) FROM bundle WHERE app_id = ?", app.Id)
	if err != nil {
		return nil, 0, err
	}

	offset := (page - 1) * limit
	if int(count) <= offset {
		// 空であることが明らかなのでそのまま返す
		return Bundles([]*Bundle{}), int(count), nil
	}

	var bundles []*Bundle
	_, err = txn.Select(&bundles, "SELECT * FROM bundle WHERE app_id = ? ORDER BY id DESC LIMIT ? OFFSET ?", app.Id, limit, offset)
	if err != nil {
		return nil, 0, err
	}

	return Bundles(bundles), int(count), nil
}
Пример #18
0
func (network *Network) PostGet(s gorp.SqlExecutor) error {
	_, err := s.Select(&network.Physicals, "select * from NetworkPhysical where NetworkUUID = ?", network.UUID)
	if err != nil {
		panic(err)
	}

	_, err = s.Select(&network.Options, "select * from DeviceOption where DeviceUUID = ?", network.UUID)
	if err != nil {
		panic(err)
	}

	_, err = s.Select(&network.Addresses, "select * from DeviceAddress where DeviceUUID = ?", network.UUID)
	if err != nil {
		panic(err)
	}

	return nil
}