当前位置: 首页>>代码示例>>Golang>>正文


Golang DB.List方法代码示例

本文整理汇总了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
			}
		}
	}
}
开发者ID:js-arias,项目名称:jdh,代码行数:30,代码来源:taxonomy.go

示例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
}
开发者ID:js-arias,项目名称:jdh,代码行数:27,代码来源:taxonomy.go

示例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
}
开发者ID:js-arias,项目名称:jdh,代码行数:9,代码来源:specimens.go

示例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
}
开发者ID:js-arias,项目名称:jdh,代码行数:15,代码来源:taxonomy.go

示例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
}
开发者ID:js-arias,项目名称:jdh,代码行数:46,代码来源:taxonomy.go

示例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")
	}
}
开发者ID:js-arias,项目名称:jdh,代码行数:44,代码来源:ds.ls.go

示例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
}
开发者ID:js-arias,项目名称:jdh,代码行数:44,代码来源:taxonomy.go

示例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)
	}
}
开发者ID:js-arias,项目名称:jdh,代码行数:23,代码来源:tx.ls.go

示例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
}
开发者ID:js-arias,项目名称:jdh,代码行数:24,代码来源:specimens.go

示例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)
}
开发者ID:js-arias,项目名称:jdh,代码行数:67,代码来源:tx.ls.go


注:本文中的github.com/js-arias/jdh/pkg/jdh.DB.List方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。