// GetLastNMessages ...
// should return empty slice even on error
GetLastNMessages
should return empty slice even on error
// GetLastNMessages ... // should return empty slice even on error
func (d *MessageDB) GetLastNMessages(chatname string, n int) ([]*models.Message, error) {
	res := []*models.Message{}
	rows, err := d.p.pool.Query(d.p.ctx, `SELECT *
	FROM (SELECT id, "user", text, time, verified, bot
		FROM messages
		WHERE chat=$1
		ORDER BY id DESC
		LIMIT $2) AS q1
	ORDER BY q1.id ASC;`, chatname, n)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	for rows.Next() {
		m := models.NewMessage("", "", "")
		var t time.Time
		err := rows.Scan(&m.ID, &m.UserName, &m.Text, &t, &m.Verified, &m.Bot)
		if err != nil {
			return nil, err
		}
		m = m.WithTime(t)
		m.ChatName = chatname
		res = append(res, m)
	}
	return res, nil
}
func ( d * MessageDB ) GetLastNMessages ( chatname string , n int ) ( [ ] * models . Message , error ) { res := [ ] * models . Message { } rows , err := d . p . pool . Query ( d . p . ctx , `SELECT *
	FROM (SELECT id, "user", text, time, verified, bot
		FROM messages
		WHERE chat=$1
		ORDER BY id DESC
		LIMIT $2) AS q1
	ORDER BY q1.id ASC;` , chatname , n ) if err != nil { return nil , err } defer rows . Close ( ) for rows . Next ( ) { m := models . NewMessage ( " " , " " , " " ) var t time . Time err := rows . Scan ( & m . ID , & m . UserName , & m . Text , & t , & m . Verified , & m . Bot ) if err != nil { return nil , err } m = m . WithTime ( t ) m . ChatName = chatname res = append ( res , m ) } return res , nil }
GetLastNMessages
should return empty slice even on error
GetLastNMessages should return empty slice even on error