Skip to content

Instantly share code, notes, and snippets.

@MaxMEllon
Created November 1, 2017 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxMEllon/9a6be5caad4d192f8d882932cd7f0c4c to your computer and use it in GitHub Desktop.
Save MaxMEllon/9a6be5caad4d192f8d882932cd7f0c4c to your computer and use it in GitHub Desktop.
statement = db.prepare('SELECT m.id, m.created_at, m.content,' <<
'u.id as uid, u.avatar_icon, u.display_name, u.name' <<
'FROM message m LEFT JOIN user u ON u.id = m.user_id' <<
'WHERE m.id > ? AND channel_id = ? ORDER BY m.id DESC LIMIT 100')
rows = statement.execute(last_message_id, channel_id).to_a
response = rows.map do |row|
{
id: row['id'],
date: row['created_at'].strftime("%Y/%m/%d %H:%M:%S"),
content: row['content'],
user: {
id: row['uid'],
display_name: row['display_name'],
name: row['name'],
avatar_icon: row['avatar_icon'],
}
}
end.reverse!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment