In a previous post we illustrated how to use the ORM to populate a simple data store. Now, we’ll look how to retrieve the data.
If you have the ID of the record / instance you’re after, you can simply call:
Note := TNote.Create(Client,ID);
for mORMot to fetch and populate Note.
Being an implementation of the Active Record Pattern, basic operations, such as Update, Retrieve and Delete are part of the basic implementation. TSQLRecord also provides list retrieval methods and lazy loading to all it’s descendants.
procedure TestIt(rest:TSQLRest); var Note : NoteORM.TNote; begin Note := TNote.CreateAndFillPrepare( rest, 'Body LIKE ?',['Sample 2%']); try while Note.FillOne do begin writeln( 'Note ID: ', Note.ID ); writeln( 'Note Title: ', Note.Title ); writeln( 'Note Body: ', Note.Body ); end; finally Note.Free; end; end;
Note ID: 3 Note Title: This is the title! Note Body: Sample 2. This is a sample note.