Implementations
Implementations of the concept can be found in various frameworks for many programming environments. For example, if in a database there is a table parts
with columns name
(string type) and price
(number type), and the Active Record pattern is implemented in the class Part
, the pseudo-code
will create a new row in the parts
table with the given values, and is roughly equivalent to the SQL command
Conversely, the class can be used to query the database:
b = Part.find_first("name", "gearbox")This will find a new Part
object based on the first matching row from the parts
table whose name
column has the value "gearbox". The SQL command used might be similar to the following, depending on the SQL implementation details of the database:
Read more about this topic: Active Record Pattern