Last active
May 11, 2018 07:02
-
-
Save ryansgot/977e1d1859940cb5e02dcaee6b3cc553 to your computer and use it in GitHub Desktop.
Forsure DB Method Chaining
This file contains hidden or 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
Retriever r = ForSure.employeesTable() // <-- enter the employees table Resolver context | |
.find().byNotDeleted() // <-- enter the employees table Finder context | |
.and().byIdBetweenInclusive(2).and(10) | |
.then() // <-- exit the employees table Finder context | |
.joinPositionsTable(FSJoin.Type.INNER) // <-- enter positions table Resolver context | |
.order().byTitle(OrderBy.ORDER_ASC) // <-- enter positions table OrderBy context | |
.then() // <-- exit positions table OrderBy context | |
.find().byNotDeleted() // <-- enter positions table Finder context | |
.and().byNot("President") | |
.then() // <-- exit positions table Finder context | |
.then() // <-- exit positions table Resolver context | |
.order().byLastName(OrderBy.ORDER_ASC) // <-- enter employees table OrderBy context | |
.then() // <-- exit employees table OrderBy context | |
.get(); // <-- execute the query, exiting the employees table Resolver context | |
// results in SQL like the following: | |
// SELECT * FROM employees | |
// INNER JOIN positions | |
// ON employees.position_id = positions._id | |
// WHERE employees.deleted != '1' | |
// AND employees._id >= '2' | |
// AND employees._id < '10' | |
// AND positions.deleted != 1 | |
// AND positions.title != 'President' | |
// ORDER BY positions.title ASC | |
// AND employees.last_name ASC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment