Skip to content

Instantly share code, notes, and snippets.

@feifanzhou
Created February 17, 2018 04:16
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 feifanzhou/cc97abcfcc3a4206caa2e740c6b2864f to your computer and use it in GitHub Desktop.
Save feifanzhou/cc97abcfcc3a4206caa2e740c6b2864f to your computer and use it in GitHub Desktop.
module Queries
struct AllChats
# Table aliases:
# C => chat
# CHJ => chat_handle_join
# H => handle
def sql
"#{select_clause} #{from_clause};"
end
def read_types
{
row_id: Int32,
chat_identifier: String,
service_name: String,
handle_id: String,
}
end
private def fields
%w[
C.ROWID
C.chat_identifier
C.service_name
H.id
]
end
private def select_clause
"SELECT #{fields.join(", ")}"
end
private def from_clause
"FROM chat C " \
"JOIN chat_handle_join CHJ ON C.ROWID = CHJ.chat_id " \
"JOIN handle H ON CHJ.handle_id = H.ROWID"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment