-
-
Notifications
You must be signed in to change notification settings - Fork 29
How does it work
Each table you want to use should be mapped using a model
. On that, you define each column and the relationship between models.
Every model's meta-class has a method called all
(or aliased to rs
) that represents a ResultSeq
of all rows on the table that the model represents. You can treat it as a usual Seq
and call methods like map
, grep
, classify
, head
, pick
, etc. most of them will return new ResultSeq
s without going to the database. When you try to iterate over it (explicitly or implicitly calling .Seq
) that it creates the AST
that represents that "intention" of a query.
Then Red gets this AST
that represents the query and ask to the driver
you are using to run that. The driver
has a method called translate
that receives an AST
and returns as SQL
string and a list of binds. Each driver
can do the translation the way it wants. Then it sends the query to the connected database and gets its response. It's from the driver
's responsibility to transform the return into a lazy list of hashes where each key is the name of the attribute's names of the model.
Than Red creates an object for each returned value (lazily) and returns it as a "real" Seq.