Пример #1
1
func PrintTable(db gorm.DB) {
	var users []User

	db.Find(&users)

	fmt.Printf("%+v\n", users)
}
Пример #2
1
func FacultiesList(db *gorm.DB) []*models.Faculties {
	var faculties []*models.Faculties
	err := db.Find(&faculties).Error
	if err != nil {
		panic(err)
	}
	return faculties
}
Пример #3
0
func importDoc(db gorm.DB, options Options, index, docID string) error {
	id, err := strconv.ParseInt(docID, 10, 64)
	if err != nil {
		return err
	}

	var doc interface{}
	switch index {
	case "jobs":
		job := application.Job{}
		if err := db.Find(&job, id).Error; err != nil {
			return err
		}
		doc = job
	case "freelancers":
		freelancer := application.Freelancer{}
		if err := db.Find(&freelancer, id).Error; err != nil {
			return err
		}
		doc = freelancer
	}
	if err := importDocument(options, index, docID, doc); err != nil {
		return err
	}
	return nil
}
Пример #4
0
/*
GetUsers returns collection of users
*/
func GetUsers(db *gorm.DB) (*[]User, error) {
	var users []User
	if err := db.Find(&users).Error; err != nil {
		return nil, err
	}
	return &users, nil
}
Пример #5
0
func getUsersPost(uid string, allUsers bool, category int64, published string, db *gorm.DB) (posts []models.Post, err error) {
	db = db.Preload("Author").Order("created_at desc")
	if !allUsers {
		db = db.Where("author_id = ?", uid)
	}

	if category != 0 {
		db = db.Joins(
			"join post_categories as pc on posts.id = pc.post_id " +
				"join categories as c on c.id = pc.category_id")

		db = db.Where("c.id = ?", category)
	}

	published = strings.ToLower(published)
	if published != "all" && (published == "true" || published == "false") {
		pub := published == "true"

		db = db.Where("published = ?", pub)
	}

	// the Select call is needed because of a bug.
	// TODO: remove this call when the bug is fixed
	db = db.Select("posts.id, posts.title, posts.content, posts.published, posts.created_at, posts.updated_at, posts.author_id")
	if err = db.Find(&posts).Error; err != nil {
		return nil, err
	}

	return posts, nil
}
Пример #6
0
func ClassifyPost(params martini.Params, res http.ResponseWriter, cls models.Classify, db *gorm.DB) string {
	db.Save(&cls)
	fi, err := os.Open("./jade/layout-tmpl.jade")
	if err != nil {
		panic(err)
	}
	defer fi.Close()
	fd, err2 := ioutil.ReadAll(fi)

	f, err2 := os.OpenFile("./jade/layout.jade", os.O_RDWR, 0755)
	if err2 != nil {
		panic(err)
	}

	css := []models.Classify{}
	db.Find(&css)
	var buf bytes.Buffer
	for _, v := range css {
		buf.WriteString("        a(href=\"/" + v.Url + ".html\") " + v.Title + "\n")
	}
	w := strings.Replace(string(fd), "####", buf.String(), -1)
	n, err1 := io.WriteString(f, w) //写入文件(字符串)
	if err1 != nil {
		panic(err1)
	}
	fmt.Printf("写入 %d 个字节n", n)
	return "1"
}
Пример #7
0
func GetAllVisitorPageRequests(db *gorm.DB) ([]VisitorPageRequest, error) {
	var prs []VisitorPageRequest
	err := db.Find(&prs).Error
	if err != nil {
		return nil, err
	}
	return prs, nil
}
Пример #8
0
func getAllUsers(db *gorm.DB) ([]MaillistUser, error) {
	var mus []MaillistUser
	err := db.Find(&mus).Error
	if err != nil {
		return nil, err
	}
	return mus, nil
}
Пример #9
0
// Returns a json list of all the users
func getAllUsersHandler(db *gorm.DB, ren render.Render) {
	users := make([]User, 0, 0)
	if err := db.Find(&users).Error; err != nil {
		ren.Text(http.StatusInternalServerError, err.Error())
		return
	}
	ren.JSON(http.StatusOK, users)
}
Пример #10
0
// GetArtifacts retrieves all the Artifacts created from buildID
func GetArtifacts(db *gorm.DB, sum *summary.Summary) ([]Artifact, int) {
	var arts []Artifact
	var count int
	db.Find(&arts, Artifact{
		Summary: *sum,
	}).Count(&count)
	return arts, count
}
Пример #11
0
func GetAllMessages(db *gorm.DB) ([]MaillistMessage, error) {
	var mms []MaillistMessage
	err := db.Find(&mms).Error
	if err != nil {
		return nil, err
	}
	return mms, nil
}
Пример #12
0
func DomainsIndex(w http.ResponseWriter, r *http.Request, db gorm.DB) {
	domains := []models.Domain{}
	db.Find(&domains)
	response := Response{"domains", domains}
	data, _ := json.Marshal(response)
	w.Header().Set("Content-Type", "application/json")
	w.Write(data)
}
Пример #13
0
// Same of ResourceGorm but for collection, see above
func (_ *CollectionGorm) Resource(h GormHandlers, db *gorm.DB, p gin.Params) (interface{}, error) {
	rtype, _ := h.ResourceClass()

	res := reflect.New(reflect.SliceOf(rtype)).Interface()
	if err := db.Find(res).Error; err != nil {
		return nil, err
	}
	return res, nil
}
Пример #14
0
func GetAllMigration(db gorm.DB, router *gin.Engine) {

	// GET /migration
	// GET all migration
	router.GET("/migration", func(c *gin.Context) {
		var migration []model.Migration
		db.Find(&migration)
		c.JSON(http.StatusOK, migration)
	})
}
Пример #15
0
func GetAllProfile(db gorm.DB, router *gin.Engine) {

	// GET /profile
	// GET all profile
	router.GET("/profile", func(c *gin.Context) {
		var profile []model.Profile
		db.Find(&profile)
		c.JSON(http.StatusOK, profile)
	})
}
Пример #16
0
func Create(rw http.ResponseWriter, jade *gojade.Engine, db *gorm.DB) {
	cls := []models.Classify{}
	db.Find(&cls)
	datas := &struct {
		Cls []models.Classify
	}{
		Cls: cls,
	}
	jade.RenderFileW(rw, "create", datas)
}
Пример #17
0
func Classify(rw http.ResponseWriter, jade *gojade.Engine, db *gorm.DB) {
	cls := []models.Classify{}
	db.Find(&cls)
	data := &struct {
		Data []models.Classify
	}{
		Data: cls,
	}
	jade.RenderFileW(rw, "class", data)
}
Пример #18
0
func GetAllLike(db gorm.DB, router *gin.Engine) {

	// GET /like
	// GET all like
	router.GET("/like", func(c *gin.Context) {
		var like []model.Like
		db.Find(&like)
		c.JSON(http.StatusOK, like)
	})
}
Пример #19
0
func GetAllUserSetting(db gorm.DB, router *gin.Engine) {

	// GET /user_setting
	// GET all user_setting
	router.GET("/user_setting", func(c *gin.Context) {
		var user_setting []model.UserSetting
		db.Find(&user_setting)
		c.JSON(http.StatusOK, user_setting)
	})
}
Пример #20
0
func GetAllLogging(db gorm.DB, router *gin.Engine) {

	// GET /logging
	// GET all logging
	router.GET("/logging", func(c *gin.Context) {
		var logging []model.Logging
		db.Find(&logging)
		c.JSON(http.StatusOK, logging)
	})
}
Пример #21
0
func GetAllWallEntry(db gorm.DB, router *gin.Engine) {

	// GET /wall_entry
	// GET all wall_entry
	router.GET("/wall_entry", func(c *gin.Context) {
		var wall_entry []model.WallEntry
		db.Find(&wall_entry)
		c.JSON(http.StatusOK, wall_entry)
	})
}
Пример #22
0
func GetAllSpaceSetting(db gorm.DB, router *gin.Engine) {

	// GET /space_setting
	// GET all space_setting
	router.GET("/space_setting", func(c *gin.Context) {
		var space_setting []model.SpaceSetting
		db.Find(&space_setting)
		c.JSON(http.StatusOK, space_setting)
	})
}
Пример #23
0
func GetAllGroupAdmin(db gorm.DB, router *gin.Engine) {

	// GET /group_admin
	// GET all group_admin
	router.GET("/group_admin", func(c *gin.Context) {
		var group_admin []model.GroupAdmin
		db.Find(&group_admin)
		c.JSON(http.StatusOK, group_admin)
	})
}
Пример #24
0
func GetAllActivity(db gorm.DB, router *gin.Engine) {

	// GET /activity
	// GET all activity
	router.GET("/activity", func(c *gin.Context) {
		var activity []model.Activity
		db.Find(&activity)
		c.JSON(http.StatusOK, activity)
	})
}
Пример #25
0
func GetAllUserFollow(db gorm.DB, router *gin.Engine) {

	// GET /user_follow
	// GET all user_follow
	router.GET("/user_follow", func(c *gin.Context) {
		var user_follow []model.UserFollow
		db.Find(&user_follow)
		c.JSON(http.StatusOK, user_follow)
	})
}
Пример #26
0
func GetAllModuleEnabled(db gorm.DB, router *gin.Engine) {

	// GET /module_enabled
	// GET all module_enabled
	router.GET("/module_enabled", func(c *gin.Context) {
		var module_enabled []model.ModuleEnabled
		db.Find(&module_enabled)
		c.JSON(http.StatusOK, module_enabled)
	})
}
Пример #27
0
func GetAllUserPassword(db gorm.DB, router *gin.Engine) {

	// GET /user_password
	// GET all user_password
	router.GET("/user_password", func(c *gin.Context) {
		var user_password []model.UserPassword
		db.Find(&user_password)
		c.JSON(http.StatusOK, user_password)
	})
}
Пример #28
0
func GetAllUserInvite(db gorm.DB, router *gin.Engine) {

	// GET /user_invite
	// GET all user_invite
	router.GET("/user_invite", func(c *gin.Context) {
		var user_invite []model.UserInvite
		db.Find(&user_invite)
		c.JSON(http.StatusOK, user_invite)
	})
}
Пример #29
0
func GetAllUserHttpSession(db gorm.DB, router *gin.Engine) {

	// GET /user_http_session
	// GET all user_http_session
	router.GET("/user_http_session", func(c *gin.Context) {
		var user_http_session []model.UserHttpSession
		db.Find(&user_http_session)
		c.JSON(http.StatusOK, user_http_session)
	})
}
Пример #30
0
func GetAllNotification(db gorm.DB, router *gin.Engine) {

	// GET /notification
	// GET all notification
	router.GET("/notification", func(c *gin.Context) {
		var notification []model.Notification
		db.Find(&notification)
		c.JSON(http.StatusOK, notification)
	})
}