本文整理汇总了Golang中github.com/js-arias/jdh/pkg/jdh.DB.List方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.List方法的具体用法?Golang DB.List怎么用?Golang DB.List使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/js-arias/jdh/pkg/jdh.DB
的用法示例。
在下文中一共展示了DB.List方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: taxInDB
// TaxInDB returns true if a taxon is in the database.
func taxInDB(c *cmdapp.Command, db jdh.DB, name, parent string, rank jdh.Rank, valid bool) *jdh.Taxon {
args := new(jdh.Values)
args.Add(jdh.TaxName, name)
if len(parent) != 0 {
args.Add(jdh.TaxParent, parent)
}
if rank != jdh.Unranked {
args.Add(jdh.TaxRank, rank.String())
}
l, err := db.List(jdh.Taxonomy, args)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
defer l.Close()
for {
tax := &jdh.Taxon{}
if err := l.Scan(tax); err != nil {
if err == io.EOF {
return nil
}
}
if len(tax.Id) > 0 {
if tax.IsValid == valid {
return tax
}
}
}
}
示例2: isInParentList
// IsInParentList search an id in the list of parents of the taxon.
func isInParentList(c *cmdapp.Command, db jdh.DB, id string, pIds []string) bool {
args := new(jdh.Values)
args.Add(jdh.TaxParents, id)
pl, err := db.List(jdh.Taxonomy, args)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
defer pl.Close()
for {
p := &jdh.Taxon{}
if err := pl.Scan(p); err != nil {
if err == io.EOF {
break
}
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
for _, pid := range pIds {
if p.Id == pid {
return true
}
}
}
return false
}
示例3: speList
// SpeList returns an specimen list scanner.
func speList(c *cmdapp.Command, db jdh.DB, vals *jdh.Values) jdh.ListScanner {
l, err := db.List(jdh.Specimens, vals)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
return l
}
示例4: getTaxDesc
// GetTaxDesc return the list of descendants of a taxon.
func getTaxDesc(c *cmdapp.Command, db jdh.DB, id string, valid bool) jdh.ListScanner {
args := new(jdh.Values)
if valid {
args.Add(jdh.TaxChildren, id)
} else {
args.Add(jdh.TaxSynonyms, id)
}
l, err := db.List(jdh.Taxonomy, args)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
return l
}
示例5: newTxList
func newTxList(tax *jdh.Taxon, db jdh.DB, syns bool) *txList {
ls := &txList{
db: db,
tax: tax,
syns: syns,
}
id := ""
if tax == nil {
ls.tax = &jdh.Taxon{
Id: "0",
Name: "root",
}
} else {
id = tax.Id
}
vals := new(jdh.Values)
vals.Add(jdh.TaxChildren, id)
pl, err := db.List(jdh.Taxonomy, vals)
if err != nil {
return ls
}
for {
d := &jdh.Taxon{}
if err := pl.Scan(d); err != nil {
break
}
ls.desc = append(ls.desc, d)
}
if !syns {
return ls
}
vals.Reset()
vals.Add(jdh.TaxSynonyms, id)
pl, err = db.List(jdh.Taxonomy, vals)
if err != nil {
return ls
}
for {
s := &jdh.Taxon{}
if err := pl.Scan(s); err != nil {
break
}
ls.desc = append(ls.desc, s)
}
return ls
}
示例6: dsLsRun
func dsLsRun(c *cmdapp.Command, args []string) {
var db jdh.DB
if len(extDBFlag) != 0 {
openExt(c, extDBFlag, "")
db = extDB
} else {
openLocal(c)
db = localDB
}
l, err := db.List(jdh.Datasets, new(jdh.Values))
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
for {
set := &jdh.Dataset{}
if err := l.Scan(set); err != nil {
if err == io.EOF {
break
}
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
if machineFlag {
fmt.Fprintf(os.Stdout, "%s\n", set.Id)
continue
}
if verboseFlag {
fmt.Fprintf(os.Stdout, "%s\t%s\t%sn", set.Id, set.Title, set.Url)
continue
}
fmt.Fprintf(os.Stdout, "%s", set.Title)
if urlFlag {
fmt.Fprintf(os.Stdout, "\t%s", set.Url)
}
if citFlag {
fmt.Fprintf(os.Stdout, "\t%s", set.Citation)
}
if licFlag {
fmt.Fprintf(os.Stdout, "\t%s", set.License)
}
fmt.Fprintf(os.Stdout, "\n")
}
}
示例7: pickTaxName
// PickTaxName search for a unique taxon name. If there are more taxons
// fullfilling the name, then it will print a list of the potential
// names and finish the program.
func pickTaxName(c *cmdapp.Command, db jdh.DB, name, parent string) *jdh.Taxon {
args := new(jdh.Values)
args.Add(jdh.TaxName, name)
if len(parent) != 0 {
args.Add(jdh.TaxParentName, parent)
}
l, err := db.List(jdh.Taxonomy, args)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
var tax *jdh.Taxon
mult := false
for {
ot := &jdh.Taxon{}
if err := l.Scan(ot); err != nil {
if err == io.EOF {
break
}
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
if tax == nil {
tax = ot
continue
}
if !mult {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("ambiguos taxon name"))
fmt.Fprintf(os.Stderr, "%s\t%s\n", tax.Id, tax.Name)
mult = true
}
fmt.Fprintf(os.Stderr, "%s\t%s\n", ot.Id, ot.Name)
}
if mult {
os.Exit(0)
}
if tax == nil {
return &jdh.Taxon{}
}
return tax
}
示例8: txLsRankNav
func txLsRankNav(c *cmdapp.Command, db jdh.DB, id string, rank jdh.Rank) {
args := new(jdh.Values)
args.Add(jdh.TaxChildren, id)
l, err := db.List(jdh.Taxonomy, args)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
for {
desc := &jdh.Taxon{}
if err := l.Scan(desc); err != nil {
if err == io.EOF {
break
}
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
if len(desc.Id) == 0 {
continue
}
txLsRank(c, db, desc, rank)
}
}
示例9: newSpList
func newSpList(tax *jdh.Taxon, db jdh.DB) *spList {
ls := &spList{
db: db,
sel: -1,
tax: tax,
}
if taxonRank(cmd, db, tax) < jdh.Species {
return ls
}
vals := new(jdh.Values)
vals.Add(jdh.SpeTaxon, tax.Id)
l, err := db.List(jdh.Specimens, vals)
if err != nil {
return ls
}
for {
spe := &jdh.Specimen{}
if err := l.Scan(spe); err != nil {
break
}
ls.spe = append(ls.spe, spe)
}
return ls
}
示例10: txLsRun
func txLsRun(c *cmdapp.Command, args []string) {
var db jdh.DB
if len(extDBFlag) != 0 {
openExt(c, extDBFlag, "")
db = extDB
} else {
openLocal(c)
db = localDB
}
var tax *jdh.Taxon
if len(idFlag) > 0 {
tax = taxon(c, db, idFlag)
if len(tax.Id) == 0 {
return
}
} else if len(args) > 0 {
if len(args) > 2 {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("too many arguments"))
os.Exit(1)
}
pName := ""
if len(args) > 1 {
pName = args[1]
}
tax = pickTaxName(c, db, args[0], pName)
if len(tax.Id) == 0 {
return
}
}
if ancsFlag {
if tax == nil {
os.Exit(0)
}
vals := new(jdh.Values)
vals.Add(jdh.TaxParents, tax.Id)
l, err := db.List(jdh.Taxonomy, vals)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
txLsProc(c, l)
return
}
if len(rankFlag) > 0 {
rank := jdh.GetRank(rankFlag)
if (rank == jdh.Unranked) && (strings.ToLower(rankFlag) != rank.String()) {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("unknown rank"))
os.Exit(1)
}
txLsRank(c, db, tax, rank)
return
}
if synonymFlag {
if tax == nil {
os.Exit(0)
}
l := getTaxDesc(c, db, tax.Id, false)
txLsProc(c, l)
return
}
id := ""
if tax != nil {
id = tax.Id
}
l := getTaxDesc(c, db, id, true)
txLsProc(c, l)
}