Comments (3)
The possible solution is build go library that connect and manage boltdb and build this library with c-shared mode (see go help buildmode
for more details). That is an idea.
from bolt.
Hi @wingyplus, Do you want that FastoNoSQL support boltdb? I found that boltdb have many users, but i nothing know about it, this is something like investigation, need or not needed GUI for db?
from bolt.
Hi all, i am wrote something like this in go:
package main
import (
"C"
"github.com/boltdb/bolt"
"fmt"
)
//export open_boltdb
func open_boltdb(path string) (interface{}, error) {
db, err := bolt.Open(path, 0600, nil)
if err != nil {
return nil, err
}
return db, nil
}
//export close_boltdb
func close_boltdb(db interface{}) {
ldb := db.(*bolt.DB)
ldb.Close()
}
//export get_value
func get_value(db interface{}, backet_name []byte, key_name []byte) ([]byte, error) {
ldb := db.(*bolt.DB)
var value []byte
fn := func(tx *bolt.Tx) error {
value = tx.Bucket(backet_name).Get(key_name)
return nil
}
return value, ldb.View(fn)
}
//export set_value
func set_value(db interface{}, backet_name []byte, key_name []byte, value []byte) error {
ldb := db.(*bolt.DB)
fn := func(tx *bolt.Tx) error {
tx.Bucket(backet_name).Put(key_name, value)
return nil
}
return ldb.Update(fn)
}
//export boltdb_strerror
func boltdb_strerror(err error) *C.char {
if err == nil {
return nil
}
return C.CString(err.Error())
}
func main() {
db, err := open_boltdb("my.db")
if err != nil {
boltdb_strerror(err)
return
}
v11, _ := get_value(db, []byte("DB"), []byte("CONFIG"))
fmt.Print(v11)
set_value(db, []byte("DB"), []byte("CONFIG"), []byte("12"))
v12, _ := get_value(db, []byte("DB"), []byte("CONFIG"))
fmt.Print(v12)
set_value(db, []byte("DB"), []byte("CONFIG"), []byte("11"))
close_boltdb(db)
}
and next in C:
#include "test.h"
int main() {
GoString db_path = {"my.db", 4};
struct open_boltdb_return db_ptr = open_boltdb(db_path);
/*if (db_ptr.r1) {
boltdb_strerror(db_ptr.r1);
return 1;
}*/
GoSlice backet = {"DB", 2, 2};
GoSlice key = {"CONFIG", 6, 6};
struct get_value_return val = get_value(db_ptr.r0, backet, key);
close_boltdb(db_ptr.r0);
return 0;
}
and compile all it via:
go build -buildmode=c-archive test.go
gcc -g -pthread main.c test.a -o main
I'am not super developer on Go, this is my first attempt to write something on it, what you think is it possible to use GO pointers in C code, now i have crash message:
panic: runtime error: cgo result has Go pointer
goroutine 17 [running, locked to thread]:
main._cgoexpwrap_e77067eccaa8_open_boltdb.func1(0xc420044e98, 0xc420044ea8)
command-line-arguments/_obj/_cgo_gotypes.go:56 +0x39
main._cgoexpwrap_e77067eccaa8_open_boltdb(0x4af5a4, 0x4, 0x70aca0, 0xc420090000, 0x0, 0x0)
command-line-arguments/_obj/_cgo_gotypes.go:59 +0xb8
Aborted
from bolt.
Related Issues (20)
- Security at rest HOT 1
- Can I use the same key for nested bucket and filed in a bucket/ HOT 1
- Document for New Contributors?
- page already freed HOT 5
- How to check if a file is a valid boltdb database without panicing HOT 2
- Check is a database open HOT 1
- what kind fo key can enhance write speed HOT 1
- concurrent writes and deadlocks HOT 2
- [RFE] change sequence number HOT 2
- [RFE] Database Generation ID HOT 7
- Database file size not updating after reaching 1GB HOT 3
- Meta2 make DBFile invalid HOT 1
- how to get the value that the current cursor points to HOT 3
- how to use boltdb for multiple files HOT 2
- page already freed on certain builds
- Not able to create subbucket inside loop
- Tons of compilation errors HOT 1
- permission denied in user home directory when open boltdb path HOT 1
- Cursor.Last() returns nil for non-empty bucket
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bolt.