-
Notifications
You must be signed in to change notification settings - Fork 1
Selector class
A selector is a class which builds a query to get instances of a class.
Selector is a sub class of the Object class
Any method on a selector which modifies the query will return the selector, so they can be chained.
Creates a new instance of a selector for instances of the targetClass, prefered alias is
TargetClass:select()
Adds a where clause to the selector, the ammount of arguments are variable, if two variables are passed then they are compared using the "=" comparator. Otherwise the second parameter would be the comparator Examples:
selector:where("x",5)
is the same as
selector:where("x","=",5)
But the second syntax also allows for
selector:where("x",">",4)
Same as where()
but will use an OR statement in the query instead.
Adds an order by statement to the query, the first parameter is the key, and second should be ASC
or DESC
Limits the ammount of instances in the result to the limit parameter
Internal function to generate the mysql query
Returns the instances of the class to the callback in a table
Returns a single instance of the class to the callback
Internal function to handle the result of a first call, do not call manually.
Internal function to handle the result of a get call, do not call manually
Player:select():where("name",getPlayerName(playerElement)):get(callback)
The resulting query of the example would be:
SELECT * FROM `player` WHERE `name` = ?
The resulting rows will then be used to create instances of the class the select()
method was called on, in this example the Player
class. And these would be returned to the callback function as table of the instances.