本文整理汇总了Golang中github.com/js-arias/jdh/pkg/jdh.DB类的典型用法代码示例。如果您正苦于以下问题:Golang DB类的具体用法?Golang DB怎么用?Golang DB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DB类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例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: specimen
// Specimen gets an specimen.
func specimen(c *cmdapp.Command, db jdh.DB, id string) *jdh.Specimen {
sc, err := db.Get(jdh.Specimens, id)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
spe := &jdh.Specimen{}
if err := sc.Scan(spe); err != nil {
if err == io.EOF {
return &jdh.Specimen{}
}
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
return spe
}
开发者ID:js-arias,项目名称:jdh,代码行数:17,代码来源:specimens.go
示例6: taxon
// Taxon gets a taxon.
func taxon(c *cmdapp.Command, db jdh.DB, id string) *jdh.Taxon {
sc, err := db.Get(jdh.Taxonomy, id)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
tax := &jdh.Taxon{}
if err := sc.Scan(tax); err != nil {
if err == io.EOF {
return &jdh.Taxon{}
}
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
return tax
}
开发者ID:js-arias,项目名称:jdh,代码行数:17,代码来源:taxonomy.go
示例7: phylogeny
// Phylogeny gets a phylogeny.
func phylogeny(c *cmdapp.Command, db jdh.DB, id string) *jdh.Phylogeny {
sc, err := db.Get(jdh.Trees, id)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
phy := &jdh.Phylogeny{}
if err := sc.Scan(phy); err != nil {
if err == io.EOF {
return &jdh.Phylogeny{}
}
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
return phy
}
开发者ID:js-arias,项目名称:jdh,代码行数:17,代码来源:phylogeny.go
示例8: dataset
// Dataset gets a dataset.
func dataset(c *cmdapp.Command, db jdh.DB, id string) *jdh.Dataset {
sc, err := db.Get(jdh.Datasets, id)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
set := &jdh.Dataset{}
if err := sc.Scan(set); err != nil {
if err == io.EOF {
return &jdh.Dataset{}
}
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
return set
}
开发者ID:js-arias,项目名称:jdh,代码行数:17,代码来源:datasets.go
示例9: phyloNode
// PhyloNode gets a node.
func phyloNode(c *cmdapp.Command, db jdh.DB, id string) *jdh.Node {
sc, err := db.Get(jdh.Nodes, id)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
nod := &jdh.Node{}
if err := sc.Scan(nod); err != nil {
if err == io.EOF {
return &jdh.Node{}
}
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
return nod
}
开发者ID:js-arias,项目名称:jdh,代码行数:17,代码来源:phylogeny.go
示例10: raster
// Raster gets the raster distribution.
func raster(c *cmdapp.Command, db jdh.DB, id string) *jdh.Raster {
sc, err := db.Get(jdh.RasDistros, id)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
ras := &jdh.Raster{}
if err := sc.Scan(ras); err != nil {
if err == io.EOF {
return &jdh.Raster{}
}
fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
os.Exit(1)
}
return ras
}
开发者ID:js-arias,项目名称:jdh,代码行数:17,代码来源:distros.go
示例11: 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
示例12: 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
示例13: 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
示例14: 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
示例15: 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
示例16: 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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论