Created
November 1, 2017 07:08
-
-
Save MaxMEllon/9a6be5caad4d192f8d882932cd7f0c4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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