本文整理匯總了Golang中github.com/hiroapp/cli/db.DB.Query方法的典型用法代碼示例。如果您正苦於以下問題:Golang DB.Query方法的具體用法?Golang DB.Query怎麽用?Golang DB.Query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hiroapp/cli/db.DB
的用法示例。
在下文中一共展示了DB.Query方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: active
func active(d db.DB) ([]*db.Entry, error) {
if itr, err := d.Query(db.Query{Active: true}); err != nil {
return nil, err
} else {
return db.IteratorEntries(itr)
}
}
示例2: cmdLs
func cmdLs(d db.DB, categoryS string, asc bool) {
if categories, err := d.Categories(); err != nil {
fatal(err)
} else if path, err := d.CategoryPath(ParseCategory(categoryS), false); err != nil {
fatal(err)
} else if itr, err := d.Query(db.Query{Asc: asc, CategoryID: path.CategoryID()}); err != nil {
fatal(err)
} else {
FprintIterator(os.Stdout, itr, categories, PrintDefault)
}
}
示例3: Last
// Last returns the last entry or an error.
func Last(d db.DB) (*db.Entry, error) {
itr, err := d.Query(db.Query{})
if err != nil {
return nil, err
}
defer itr.Close()
if entry, err := itr.Next(); err == io.EOF {
return nil, errors.New("db is empty")
} else {
return entry, err
}
}
示例4: ById
// ById returns the entry with the given id, or an error.
func ById(d db.DB, id string) (*db.Entry, error) {
itr, err := d.Query(db.Query{IDs: []string{id}})
if err != nil {
return nil, err
}
defer itr.Close()
if entry, err := itr.Next(); err == io.EOF {
return nil, fmt.Errorf("entry does not exist: %s", id)
} else {
return entry, err
}
}
示例5: NewSummaryIterator
// NewSummaryIterator returns a new summary iterator producing summaries for
// the given period and firstDay of the week. If the period is datetime.Day,
// it is is ignored. Callers are required to call Close once they are done
// with the iterator.
func NewSummaryIterator(d db.DB, period datetime.Period, firstDay time.Weekday, now time.Time) (*SummaryIterator, error) {
entries, err := d.Query(db.Query{})
if err != nil {
return nil, err
}
return &SummaryIterator{
now: now,
entries: entries,
period: period,
firstDay: firstDay,
}, nil
}
示例6: cmdReport
func cmdReport(d db.DB, categoryS, periodS, firstDayS string) {
period, err := datetime.ParsePeriod(periodS)
if err != nil {
fatal(err)
} else if period == datetime.Day {
fatal(errors.New("bad period: day"))
}
firstDay, err := datetime.ParseWeekday(firstDayS)
if err != nil {
fatal(err)
}
path, err := d.CategoryPath(ParseCategory(categoryS), false)
if err != nil {
fatal(err)
}
entryItr, err := d.Query(db.Query{CategoryID: path.CategoryID()})
if err != nil {
fatal(err)
}
defer entryItr.Close()
entry, err := entryItr.Next()
if err == io.EOF {
return
} else if err != nil {
fatal(err)
}
// @TODO move logic into separate function
now := time.Now()
reportItr := datetime.NewIterator(entry.Start, period, false, firstDay)
report := &Report{Duration: period}
report.From, report.To = reportItr.Next()
dayItr := datetime.NewIterator(report.To, datetime.Day, false, firstDay)
day := &ReportDay{}
day.From, day.To = dayItr.Next()
report.Days = append([]*ReportDay{day}, report.Days...)
noteAssigned := false
outer:
for {
var overlap time.Duration
for {
overlap = entry.PartialDuration(now, day.From, day.To)
if overlap > 0 {
day.Tracked += overlap
if !noteAssigned {
note := strings.Trim(entry.Note, "\n")
if note != "" {
day.Notes = append([]string{note}, day.Notes...)
}
noteAssigned = true
}
}
if !entry.Start.Before(day.From) {
entry, err = entryItr.Next()
if err == io.EOF {
fmt.Fprint(os.Stdout, FormatReport(report))
break outer
} else if err != nil {
fatal(err)
}
noteAssigned = false
continue
}
day = &ReportDay{}
day.From, day.To = dayItr.Next()
if day.To.Before(report.From) {
fmt.Fprint(os.Stdout, FormatReport(report))
report = &Report{Duration: period}
report.From, report.To = reportItr.Next()
}
report.Days = append([]*ReportDay{day}, report.Days...)
}
}
}