Skip to content

Instantly share code, notes, and snippets.

@ryansgot
Last active December 27, 2017 08:32
Show Gist options
  • Save ryansgot/6171feccacf2f9ba61c9e0b9f67c447c to your computer and use it in GitHub Desktop.
Save ryansgot/6171feccacf2f9ba61c9e0b9f67c447c to your computer and use it in GitHub Desktop.
Basic Forsuredb Retrieval Query
MyTable myTableApi = ForSure.myTable().getApi(); // <-- get retrieval API that Forsuredb generated for you
Retriever r = ForSure.myTable() // <-- the generated ForSure class serves as your entrypoint
.find() // <-- start narrowing the number of records and columns to return
.byIntColumnBetween(3).andInclusive(10) // <-- set bounds (3, 10]
.and().byNotDeleted() // <-- add additional condition that the record must not be "soft deleted"
.then() // <-- end narrowing number of records and columns to return
.get(); // <-- execute the query and return a Retriever (a Cursor/ResultSet)
if (r.moveToFirst()) { // <-- Retrievers get iterated just like Cursors or ResultSets
do {
String stringColumn = myTableApi.stringColumn(r);
int intColumn = myTableApi.intColumn(r);
System.out.println("found record: string_column=" + stringColumn + ", int_column=" + intColumn);
} while (r.moveToNext());
}
r.close(); // <-- Retrievers must be closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment