func LoadActualScreeningForWalkthrough(db ab.DB, ec *ab.EntityController, wid string) (*Screening, error) { screeningFields := ec.FieldList("screening") screenings, err := ec.LoadFromQuery(db, "screening", "SELECT "+screeningFields+" FROM screening s WHERE wid = $1 AND published = true ORDER BY created DESC LIMIT 1", wid) if err != nil { return nil, err } if len(screenings) != 1 { return nil, nil } return screenings[0].(*Screening), nil }
func LoadActualRevision(db ab.DB, ec *ab.EntityController, UUID string) (*Walkthrough, error) { walkthroughFields := ec.FieldList("walkthrough") entities, err := ec.LoadFromQuery(db, "walkthrough", "SELECT "+walkthroughFields+" FROM walkthrough w WHERE UUID = $1 AND published = true ORDER BY Updated DESC LIMIT 1", UUID) if err != nil { return nil, err } if len(entities) != 1 { return nil, nil } return entities[0].(*Walkthrough), nil }
func LoadAllActualWalkthroughs(db ab.DB, ec *ab.EntityController, start, limit int) ([]*Walkthrough, error) { walkthroughFields := ec.FieldList("walkthrough") entities, err := ec.LoadFromQuery(db, "walkthrough", `WITH latestwt AS (SELECT uuid, MAX(updated) u FROM walkthrough WHERE published = true GROUP BY uuid ORDER BY u DESC), latestuuid AS (SELECT w.revision FROM latestwt l JOIN walkthrough w ON l.uuid = w.uuid AND l.u = w.updated) SELECT `+walkthroughFields+` FROM walkthrough w JOIN latestuuid l ON l.revision = w.revision ORDER BY updated DESC`) if err != nil { return []*Walkthrough{}, err } wts := make([]*Walkthrough, len(entities)) for i, e := range entities { wts[i] = e.(*Walkthrough) } return wts, nil }
func LoadActualRevisions(db ab.DB, ec *ab.EntityController, uuids []string) ([]*Walkthrough, error) { walkthroughFields := ec.FieldList("walkthrough") placeholders := util.GeneratePlaceholders(1, uint(len(uuids))+1) entities, err := ec.LoadFromQuery(db, "walkthrough", `WITH latestwt AS (SELECT uuid, MAX(updated) u FROM walkthrough WHERE published = true GROUP BY uuid ORDER BY u DESC), latestuuid AS (SELECT w.revision FROM latestwt l JOIN walkthrough w ON l.uuid = w.uuid AND l.u = w.updated) SELECT `+walkthroughFields+` FROM walkthrough w JOIN latestuuid l ON l.revision = w.revision WHERE w.uuid IN (`+placeholders+`) `, util.StringSliceToInterfaceSlice(uuids)...) if err != nil { return []*Walkthrough{}, err } wts := make([]*Walkthrough, len(entities)) for i, e := range entities { wts[i] = e.(*Walkthrough) } return wts, nil }