###Reader usage
You can create Reader instance using constructor method. If all of your Views that uses reader are initialized by calling
View#Init method, or by using View loaded by NewResourceFromUrl method, you can pass emptry Resource:
emptyResource := data.EmptyResource()
service := reader.New(emptyResource)Resource is needed only to try to initialize View unless View was initialized earlier.
In order to read data you need data.Session:
var fooView *data.View
session := &data.Session{
Dest: new(interface{}),
View: fooView,
AllowUnmapped: true,
Selectors: Selectors{},
Subject: "",
HttpRequest: *http.Request{},
MatchedPath: "",
}Destis required. It has to be a pointer tointerface{}or pointer to slice ofTor*TViewis required. Due to optimization reasons it is important to create one instance, share it across the system and provide fully initializedView. ForViewcreation see: create programmatically or load from fileSelectorsare not used when datly is used only to communicate with database, but may be used when datly is configured also as request handler (see TODO)AllowUnmappedis optional, by default is set to false. It is being used when some database table columns doesn't matchView.Schematype.Subjectis optional. It is being used to build criteria and represents logged user.HttpRequestis optional, needed only if any ofParameterlocation ispath,query,cookie,headeror if datly is used as request handler.MatchedPathis optional, needed only if any ofParameterlocation ispathor if datly is used as request handler. You can now read data from database using the reader instance.
You should let reader initialize the session. New session has to be created for each time you call reader.Read. Having reader and session you can fetch data from database:
err := service.Read(context.TODO(), session)
if err != nil {
// ... handle error
}
toolbox.DumpIndent(session.Dest, false) //prints view fetched from database