示例#1
0
// Find 查找单条数据
// colFieldMap 数据库表中列对应go中对象的字段
func (this *Dao) Find(colFieldMap map[string]interface{}, selectCol ...string) error {
	colNum := len(selectCol)
	if colNum == 0 || (colNum == 1 && selectCol[0] == "*") {
		selectCol = util.MapKeys(colFieldMap)
	}
	sort.Sort(sort.StringSlice(selectCol))
	this.selectCols = "`" + strings.Join(selectCol, "`,`") + "`"
	strSql := util.SelectSql(this)
	logger.Debugln("Find sql:", strSql)
	err := this.Open()
	if err != nil {
		return err
	}
	defer this.Close()
	row := this.QueryRow(strSql, this.whereVal...)
	scanInterface := make([]interface{}, 0, colNum)
	for _, column := range selectCol {
		scanInterface = append(scanInterface, colFieldMap[column])
	}
	err = row.Scan(scanInterface...)
	if err == sql.ErrNoRows {
		logger.Infoln("Find", strSql, ":no result ret")
		return nil
	}
	return err
}
示例#2
0
func (this *TopicNode) FindAll(selectCol ...string) ([]*TopicNode, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	nodeList := make([]*TopicNode, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		node := NewTopicNode()
		colFieldMap := node.colFieldMap()
		scanInterface := make([]interface{}, 0, colNum)
		for _, column := range selectCol {
			scanInterface = append(scanInterface, colFieldMap[column])
		}
		err = rows.Scan(scanInterface...)
		if err != nil {
			logger.Errorln("TopicNode FindAll Scan Error:", err)
			continue
		}
		nodeList = append(nodeList, node)
	}
	return nodeList, nil
}
示例#3
0
func (this *MorningReading) FindAll(selectCol ...string) ([]*MorningReading, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	readingList := make([]*MorningReading, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		reading := NewMorningReading()
		err = this.Scan(rows, colNum, reading.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("MorningReading FindAll Scan Error:", err)
			continue
		}
		reading.Rdate = reading.Ctime[:10]
		if reading.Moreurls != "" {
			reading.Urls = strings.Split(reading.Moreurls, ",")
		}
		readingList = append(readingList, reading)
	}
	return readingList, nil
}
示例#4
0
func (this *UserRole) FindAll(selectCol ...string) ([]*UserRole, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		logger.Errorln("[UserRole.FindAll] error:", err)
		return nil, err
	}
	// TODO:
	userRoleList := make([]*UserRole, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		userRole := NewUserRole()
		colFieldMap := userRole.colFieldMap()
		scanInterface := make([]interface{}, 0, colNum)
		for _, column := range selectCol {
			scanInterface = append(scanInterface, colFieldMap[column])
		}
		err = rows.Scan(scanInterface...)
		if err != nil {
			logger.Errorln("[UserRole.FindAll Rows] error:", err)
		}
		userRoleList = append(userRoleList, userRole)
	}
	return userRoleList, nil
}
示例#5
0
func (this *Comment) FindAll(selectCol ...string) ([]*Comment, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	commentList := make([]*Comment, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		comment := NewComment()
		colFieldMap := comment.colFieldMap()
		scanInterface := make([]interface{}, 0, colNum)
		for _, column := range selectCol {
			scanInterface = append(scanInterface, colFieldMap[column])
		}
		err = rows.Scan(scanInterface...)
		if err != nil {
			logger.Errorln("Comment FindAll Scan Error:", err)
			continue
		}
		commentList = append(commentList, comment)
	}
	return commentList, nil
}
示例#6
0
func (this *Comment) FindAll(selectCol ...string) ([]*Comment, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	commentList := make([]*Comment, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		comment := NewComment()
		err = this.Scan(rows, colNum, comment.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Comment FindAll Scan Error:", err)
			continue
		}
		commentList = append(commentList, comment)
	}
	return commentList, nil
}
示例#7
0
func (this *Message) FindAll(selectCol ...string) ([]*Message, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	messageList := make([]*Message, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		message := NewMessage()
		err = this.Scan(rows, colNum, message.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Message FindAll Scan Error:", err)
			continue
		}
		messageList = append(messageList, message)
	}
	return messageList, nil
}
示例#8
0
func (this *Like) FindAll(selectCol ...string) ([]*Like, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	likeList := make([]*Like, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		like := NewLike()
		err = this.Scan(rows, colNum, like.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Like FindAll Scan Error:", err)
			continue
		}
		likeList = append(likeList, like)
	}
	return likeList, nil
}
示例#9
0
func (this *TopicNode) FindAll(selectCol ...string) ([]*TopicNode, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	nodeList := make([]*TopicNode, 0, 10)
	//logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		node := NewTopicNode()
		err = this.Scan(rows, colNum, node.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("TopicNode FindAll Scan Error:", err)
			continue
		}
		nodeList = append(nodeList, node)
	}
	return nodeList, nil
}
示例#10
0
func (this *Favorite) FindAll(selectCol ...string) ([]*Favorite, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	favoriteList := make([]*Favorite, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		favorite := NewFavorite()
		err = this.Scan(rows, colNum, favorite.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Favorite FindAll Scan Error:", err)
			continue
		}
		favoriteList = append(favoriteList, favorite)
	}
	return favoriteList, nil
}
示例#11
0
func (this *RoleAuthority) FindAll(selectCol ...string) ([]*RoleAuthority, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	roleAuthList := make([]*RoleAuthority, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		roleAuth := NewRoleAuthority()
		err = this.Scan(rows, colNum, roleAuth.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("RoleAuthority FindAll Scan Error:", err)
			continue
		}
		roleAuthList = append(roleAuthList, roleAuth)
	}
	return roleAuthList, nil
}
示例#12
0
func (this *OpenProject) FindAll(selectCol ...string) ([]*OpenProject, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	projectList := make([]*OpenProject, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		project := NewOpenProject()
		err = this.Scan(rows, colNum, project.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("OpenProject FindAll Scan Error:", err)
			continue
		}
		projectList = append(projectList, project)
	}
	return projectList, nil
}
示例#13
0
func (this *UserRole) FindAll(selectCol ...string) ([]*UserRole, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		logger.Errorln("[UserRole.FindAll] error:", err)
		return nil, err
	}
	// TODO:
	userRoleList := make([]*UserRole, 0, 10)
	colNum := len(selectCol)
	for rows.Next() {
		userRole := NewUserRole()
		err = this.Scan(rows, colNum, userRole.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("UserRole FindAll Scan Error:", err)
			continue
		}
		userRoleList = append(userRoleList, userRole)
	}
	return userRoleList, nil
}
示例#14
0
func (this *Wiki) FindAll(selectCol ...string) ([]*Wiki, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	wikiList := make([]*Wiki, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		wiki := NewWiki()
		err = this.Scan(rows, colNum, wiki.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Wiki FindAll Scan Error:", err)
			continue
		}
		wikiList = append(wikiList, wiki)
	}
	return wikiList, nil
}
示例#15
0
func (this *Resource) FindAll(selectCol ...string) ([]*Resource, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	resourceList := make([]*Resource, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		resource := NewResource()
		err = this.Scan(rows, colNum, resource.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Resource FindAll Scan Error:", err)
			continue
		}
		resourceList = append(resourceList, resource)
	}
	return resourceList, nil
}
示例#16
0
func (this *ResourceCat) FindAll(selectCol ...string) ([]*ResourceCat, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	catList := make([]*ResourceCat, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		category := NewResourceCat()
		err = this.Scan(rows, colNum, category.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("TopicNode FindAll Scan Error:", err)
			continue
		}
		catList = append(catList, category)
	}
	return catList, nil
}
示例#17
0
func (this *Article) FindAll(selectCol ...string) ([]*Article, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	articleList := make([]*Article, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		article := NewArticle()
		err = this.Scan(rows, colNum, article.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Article FindAll Scan Error:", err)
			continue
		}
		articleList = append(articleList, article)
	}
	return articleList, nil
}
示例#18
0
func (this *Blog) FindAll(selectCol ...string) ([]*Blog, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	blogList := make([]*Blog, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		blog := NewBlog()
		err = this.Scan(rows, colNum, blog.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Blog FindAll Scan Error:", err)
			continue
		}
		blogList = append(blogList, blog)
	}
	return blogList, nil
}
示例#19
0
func (this *UserLogin) FindAll(selectCol ...string) ([]*UserLogin, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	userList := make([]*UserLogin, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		user := NewUserLogin()
		err = this.Scan(rows, colNum, user.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("UserLogin FindAll Scan Error:", err)
			continue
		}
		userList = append(userList, user)
	}
	return userList, nil
}
示例#20
0
func (this *Topic) FindAll(selectCol ...string) ([]*Topic, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	topicList := make([]*Topic, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		topic := NewTopic()
		err = this.Scan(rows, colNum, topic.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("Topic FindAll Scan Error:", err)
			continue
		}
		topicList = append(topicList, topic)
	}
	return topicList, nil
}
示例#21
0
func (this *WechatPlayer) FindAll(selectCol ...string) ([]*WechatPlayer, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	playerList := make([]*WechatPlayer, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		player := NewWechatPlayer()
		err = this.Scan(rows, colNum, player.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("WechatPlayer FindAll Scan Error:", err)
			continue
		}
		playerList = append(playerList, player)
	}
	return playerList, nil
}
示例#22
0
func (this *SearchStat) FindAll(selectCol ...string) ([]*SearchStat, error) {
	if len(selectCol) == 0 {
		selectCol = util.MapKeys(this.colFieldMap())
	}
	rows, err := this.Dao.FindAll(selectCol...)
	if err != nil {
		return nil, err
	}
	// TODO:
	searchStatList := make([]*SearchStat, 0, 10)
	logger.Debugln("selectCol", selectCol)
	colNum := len(selectCol)
	for rows.Next() {
		searchStat := NewSearchStat()
		err = this.Scan(rows, colNum, searchStat.colFieldMap(), selectCol...)
		if err != nil {
			logger.Errorln("SearchStat FindAll Scan Error:", err)
			continue
		}
		searchStatList = append(searchStatList, searchStat)
	}
	return searchStatList, nil
}