Skip to content

Instantly share code, notes, and snippets.

@juliuscanute
Created July 4, 2019 06:57
Show Gist options
  • Save juliuscanute/17b0133f1f2481dad1dd9c1ca82aff36 to your computer and use it in GitHub Desktop.
Save juliuscanute/17b0133f1f2481dad1dd9c1ca82aff36 to your computer and use it in GitHub Desktop.
Search For Word in Dictionary
val findSpec = SqlQuerySpec().apply {
queryText = "SELECT Dictionary.word AS word, Dictionary.meaning AS meaning FROM Dictionary WHERE Dictionary.partition = @tag AND contains(Dictionary.search, @query) OFFSET @offset LIMIT @records_per_page"
parameters = SqlParameterCollection().apply {
add(SqlParameter("@tag", query.first().toUpperCase().toString()))
add(SqlParameter("@query", query.toLowerCase()))
add(SqlParameter("@offset", offset))
add(SqlParameter("@records_per_page", RECORDS_PER_PAGE))
}
}
val countSpec = SqlQuerySpec().apply {
queryText = "SELECT COUNT(1) AS TotalRecords FROM Dictionary WHERE Dictionary.partition = @tag AND contains(Dictionary.search, @query)"
parameters = SqlParameterCollection().apply {
add(SqlParameter("@tag", query.first().toUpperCase().toString()))
add(SqlParameter("@query", query.toLowerCase()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment