FB4D Reference IFirestoreDocuments - SchneiderInfosystems/FB4D GitHub Wiki
Interface IFirestoreDocuments
This interface is used to retrieve a collection of documents from the Firestore.
The interface offers the following functions:
IFirestoreDocuments = interface(IEnumerable<IFirestoreDocument>)
function Count: integer;
function Document(Ind: integer): IFirestoreDocument;
function ServerTimeStamp(TimeZone: TTimeZone): TDateTime;
function SkippedResults: integer;
function MorePagesToLoad: boolean;
function PageToken: string;
procedure AddPageTokenToNextQuery(Query: TQueryParams);
end;
While the first two functions allow access to the list of documents, the third function returns the timestamp as the document was read from the Firestore. This can be helpful in timestamp comparisons, where timestamps from the data must be compared to that of the read access, for example, to determine if a previous document write was done within the last minute or seconds.
Since IEnumerable was implemented, a for-each loop can quickly read all documents without having to worry about an index.
procedure TfmxMyForm.OnFirestoreGet(const Info: string; Docs: IFirestoreDocuments);
var
Doc: IFirestoreDocument;
begin
for Doc in Docs do
ShowDocument(Doc);
end;
If the document list was fetched with the method RunQuery by using an offset, the function SkippedResults returns the passed offset number to the query.
If IFirestoreDatabase.Get was used to retrieve all documents in a collection, the MorePagesToLoad function reports that not all documents fit into the returned page (set of documents). In this case, the PageToken must be passed in the next Get request, so that the next series of documents can be fetched.