• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang levigo.DB类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/jmhodges/levigo.DB的典型用法代码示例。如果您正苦于以下问题:Golang DB类的具体用法?Golang DB怎么用?Golang DB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DB类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: getPlaylistFromDB

func getPlaylistFromDB(db *levigo.DB) []playListItem {
	log.Println("Loading Playlist from file...")

	ro := levigo.NewReadOptions()

	data, err := db.Get(ro, []byte("playlist"))
	if err != nil {
		log.Fatal(err)
	}

	p := bytes.NewBuffer(data)

	dec := gob.NewDecoder(p)

	var playlist []playListItem
	//we must decode into a pointer, so we'll take the address of e
	err = dec.Decode(&playlist)
	if err != nil {
		log.Print(err)
		playlist = []playListItem{}
	}

	log.Println("Loaded ", len(playlist), " items into playlist")
	log.Println(playlist)
	return playlist

}
开发者ID:egelmex,项目名称:hgd2,代码行数:27,代码来源:playlist.go


示例2: AddProc

func AddProc(procID int, db *levigo.DB) error {
	ro := levigo.NewReadOptions()
	wo := levigo.NewWriteOptions()

	data, err := db.Get(ro, []byte("procs"))
	spdata := bytes.Split(data, []byte(":"))

	for i, e := range spdata {

		if string(e) != "" {
			fmt.Println("ProcID: #", i, string(e))
			pid, err := strconv.Atoi(string(e))
			if err != nil {
				return err
			}
			if pid == procID {
				return errors.New("Process already exists")
			}
			if isProcAlive(pid) == false {
				removeProc(pid, db)
			}
		}

		if err != nil {
			return err
		}
	}

	strdata := string(data)
	strdata = strdata + ":" + strconv.Itoa(procID)

	err = db.Put(wo, []byte("procs"), []byte(strdata))
	return err
}
开发者ID:jdpaton,项目名称:Overseer,代码行数:34,代码来源:overseerdb.go


示例3: loadUsers

func loadUsers(db *levigo.DB) map[string]User {
	log.Println("Loading Users from file...")

	ro := levigo.NewReadOptions()

	data, err := db.Get(ro, []byte("Users"))
	if err != nil {
		log.Fatal(err)
	}

	p := bytes.NewBuffer(data)

	dec := gob.NewDecoder(p)

	var users map[string]User
	//we must decode into a pointer, so we'll take the address of e
	err = dec.Decode(&users)
	if err != nil {
		log.Print(err)
		users = map[string]User{}
	}

	log.Println("Loaded ", len(users), " users")
	log.Printf("%+v", users)
	return users

}
开发者ID:egelmex,项目名称:hgd2,代码行数:27,代码来源:usermanger.go


示例4: Execute

func (ahr AddHashRequest) Execute(database *levigo.DB, ro *levigo.ReadOptions, wo *levigo.WriteOptions) (*kminvalues.KMinValues, error) {
	if ahr.Key == "" {
		return nil, NoKeySpecified
	}

	keyBytes := []byte(ahr.Key)

	data, err := database.Get(ro, keyBytes)
	if err != nil {
		return nil, err
	}

	kmv, err := kminvalues.KMinValuesFromBytes(data)
	if err != nil {
		if len(data) == 0 {
			kmv = kminvalues.NewKMinValues(*defaultSize)
		} else {
			return nil, err
		}
	}
	kmv.AddHash(ahr.Hash)

	err = database.Put(wo, keyBytes, kmv.Bytes())
	return kmv, err
}
开发者ID:darkseed,项目名称:gocountme,代码行数:25,代码来源:db.go


示例5: GetTx

// Fetch a Tx by hash
func GetTx(db *levigo.DB, txHash string) (tx *Tx, err error) {
	ro := levigo.NewReadOptions()
	defer ro.Close()
	txKey, blockErr := db.Get(ro, []byte(fmt.Sprintf("tx!%s", txHash)))
	if blockErr != nil {
		err = errors.New("Tx not found")
		return
	}

	txData, blockErr := db.Get(ro, txKey)
	if blockErr != nil {
		err = errors.New("Tx not found")
		return
	}

	tx = new(Tx)
	err = json.Unmarshal(txData, tx)
	if err != nil {
		return
	}

	for txo_index, txo := range tx.TxOuts {
		txo.Spent, _ = GetTxoSpent(db, txo.Addr, tx.Hash, txo_index)
	}

	return
}
开发者ID:pombredanne,项目名称:btcplex,代码行数:28,代码来源:tx.go


示例6: GetLastHeight

// Return the last height processed
func GetLastHeight(db *levigo.DB) (lastHeight uint, err error) {
	ro := levigo.NewReadOptions()
	defer ro.Close()
	lastHeightRaw, _ := db.Get(ro, []byte("last-height"))
	lastHeightInt, _ := strconv.Atoi(string(lastHeightRaw[:]))
	lastHeight = uint(lastHeightInt)
	return
}
开发者ID:pombredanne,项目名称:btcplex,代码行数:9,代码来源:blockchain.go


示例7: removeProc

func removeProc(pid int, db *levigo.DB) error {
	wo := levigo.NewWriteOptions()
	err := db.Delete(wo, []byte(strconv.Itoa(pid)))
	if err != nil {
		return err
	}
	return killProc(pid)

}
开发者ID:jdpaton,项目名称:Overseer,代码行数:9,代码来源:overseerdb.go


示例8: writeDataStoreVersion

// Write the datastore version to a shard.
func writeDataStoreVersion(store *dataStore, ldb *levigo.DB, v uint32) error {
	w := new(bytes.Buffer)
	encoder := gob.NewEncoder(w)
	err := encoder.Encode(&v)
	if err != nil {
		return err
	}
	return ldb.Put(store.writeOpts, []byte{VERSION_KEY}, w.Bytes())
}
开发者ID:clehene,项目名称:incubator-htrace,代码行数:10,代码来源:datastore.go


示例9: Execute

func (sr SetRequest) Execute(database *levigo.DB, ro *levigo.ReadOptions, wo *levigo.WriteOptions) (*KMinValues, error) {
	if sr.Key == "" {
		return nil, NoKeySpecified
	}

	keyBytes := []byte(sr.Key)
	err := database.Put(wo, keyBytes, sr.Kmv.Bytes())

	return sr.Kmv, err
}
开发者ID:jehiah,项目名称:gocountme,代码行数:10,代码来源:db.go


示例10: AddIndex

func AddIndex(index [2]string, key []byte, indexDb *levigo.DB, wb *levigo.WriteBatch) error {
	searchKey := []byte(index[0] + "~" + index[1])
	keys, err := indexDb.Get(LReadOptions, searchKey)
	if err != nil {
		return err
	}
	keys = appendDataKey(keys, key)
	wb.Put(searchKey, keys)
	return nil
}
开发者ID:shyrobbiani,项目名称:levelupdb,代码行数:10,代码来源:index.go


示例11: DelKey

/*
DelKey deletes key from provided DB handle.
*/
func DelKey(key string, db *levigo.DB) bool {
	writer := levigo.NewWriteOptions()
	defer writer.Close()

	err := db.Delete(writer, []byte(key))
	if err != nil {
		golerror.Boohoo("Key "+key+" query failed.", false)
		return false
	}
	return true
}
开发者ID:carriercomm,项目名称:levigoNS,代码行数:14,代码来源:leveldb.go


示例12: GetVal

/*
GetVal gets value of Key from provided db handle.
*/
func GetVal(key string, db *levigo.DB) string {
	reader := levigo.NewReadOptions()
	defer reader.Close()

	data, err := db.Get(reader, []byte(key))
	if err != nil {
		golerror.Boohoo("Key "+key+" query failed.", false)
		return ""
	}
	return string(data)
}
开发者ID:carriercomm,项目名称:levigoNS,代码行数:14,代码来源:leveldb.go


示例13: writeUsersToDB

func writeUsersToDB(db *levigo.DB, users map[string]User) {
	wo := levigo.NewWriteOptions()
	m := new(bytes.Buffer)
	enc := gob.NewEncoder(m)
	enc.Encode(users)

	err := db.Put(wo, []byte("Users"), m.Bytes())
	if err != nil {
		log.Fatal(err)
	}
	wo.Close()
}
开发者ID:egelmex,项目名称:hgd2,代码行数:12,代码来源:usermanger.go


示例14: writePlaylistToDB

func writePlaylistToDB(db *levigo.DB, playlist []playListItem) {
	wo := levigo.NewWriteOptions()
	m := new(bytes.Buffer)
	enc := gob.NewEncoder(m)
	enc.Encode(playlist)

	err := db.Put(wo, []byte("playlist"), m.Bytes())
	if err != nil {
		log.Fatal(err)
	}
	wo.Close()
}
开发者ID:egelmex,项目名称:hgd2,代码行数:12,代码来源:playlist.go


示例15: PushKeyVal

/*
PushKeyVal push KeyVal in provided DB handle.
*/
func PushKeyVal(key string, val string, db *levigo.DB) bool {
	writer := levigo.NewWriteOptions()
	defer writer.Close()

	keyname := []byte(key)
	value := []byte(val)
	err := db.Put(writer, keyname, value)
	if err != nil {
		golerror.Boohoo("Key "+key+" insertion failed. It's value was "+val, false)
		return false
	}
	return true
}
开发者ID:carriercomm,项目名称:levigoNS,代码行数:16,代码来源:leveldb.go


示例16: write_data

func write_data(data []byte, db *levigo.DB, nitems int, keysize int, valsize int) {
	defer un(trace("write data"))
	wo := levigo.NewWriteOptions()
	keystart := 0
	valstart := 0
	for i := 0; i < nitems; i++ {
		db.Put(wo,
			data[keystart:keystart+keysize],
			data[valstart:valstart+valsize])
		keystart %= (len(data) - keysize)
		valstart %= (len(data) - valsize)
	}
	fmt.Println("Wrote ", nitems, "items with key size", keysize, "and value size", valsize)
}
开发者ID:salibrandi,项目名称:mexos,代码行数:14,代码来源:levigo-ex.go


示例17: RemoveIndex

// TODO: refactor with above.
func RemoveIndex(index [2]string, key []byte, indexDb *levigo.DB, wb *levigo.WriteBatch) error {
	searchKey := []byte(index[0] + "~" + index[1])
	keys, err := indexDb.Get(LReadOptions, searchKey)
	if err != nil {
		return err
	}
	keys = removeDataKey(keys, key)
	if len(keys) > 0 {
		wb.Put(searchKey, keys)
	} else {
		wb.Delete(searchKey)
	}
	return nil
}
开发者ID:shyrobbiani,项目名称:levelupdb,代码行数:15,代码来源:index.go


示例18: GetBlockHashByHeight

// Return block hash in the main chain given the height
func GetBlockHashByHeight(db *levigo.DB, blockHeight uint) (hash string, err error) {
	ro := levigo.NewReadOptions()
	defer ro.Close()
	blocks, _ := GetRange(db, []byte(fmt.Sprintf("bl!height!%v!", blockHeight)), []byte(fmt.Sprintf("bl!height!%v!\xff", blockHeight)))
	for _, bl := range blocks {
		blStatus, _ := db.Get(ro, []byte(fmt.Sprintf("bl!%v!main", bl.Value)))
		blStatus2, _ := strconv.Atoi(string(blStatus[:]))
		if blStatus2 == 1 {
			hash = bl.Value
			return
		}
	}
	err = errors.New("Block not found")
	return
}
开发者ID:pombredanne,项目名称:btcplex,代码行数:16,代码来源:block.go


示例19: readLayoutVersion

// Read the datastore version of a leveldb instance.
func readLayoutVersion(store *dataStore, ldb *levigo.DB) (uint32, error) {
	buf, err := ldb.Get(store.readOpts, []byte{VERSION_KEY})
	if err != nil {
		return 0, err
	}
	if len(buf) == 0 {
		return 0, nil
	}
	r := bytes.NewBuffer(buf)
	decoder := gob.NewDecoder(r)
	var v uint32
	err = decoder.Decode(&v)
	if err != nil {
		return 0, err
	}
	return v, nil
}
开发者ID:clehene,项目名称:incubator-htrace,代码行数:18,代码来源:datastore.go


示例20: GetSentByAddress

func GetSentByAddress(db *levigo.DB, addr string) (total uint, err error) {
	total = uint(0)
	ro := levigo.NewReadOptions()
	defer ro.Close()
	start := []byte(fmt.Sprintf("%s-txo!", addr))
	end := []byte(fmt.Sprintf("%s-txo!\xff", addr))
	txos, _ := GetRange(db, start, end)
	for _, txo := range txos {
		log.Println(txo.Key)
		new_key := strings.Replace(txo.Key, "-txo", "-txo-spent", 1)
		log.Println(new_key)
		r, _ := db.Get(ro, []byte(new_key))
		log.Println(string(r[:]))
		val, _ := strconv.Atoi(txo.Value)
		total += uint(val)
	}
	return
}
开发者ID:pombredanne,项目名称:btcplex,代码行数:18,代码来源:address.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang levigo.WriteBatch类代码示例发布时间:2022-05-23
下一篇:
Golang levigo.Open函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap