Open yuanotes opened 6 years ago
Hi Yuan!
LiteTree was just made public and it was not yet included in the Aergo blockchain.
Normally we can use common SQLite wrappers, just replacing the libsqlite3 library. Only in some cases we need to rebuild the whole wrapper.
For Go we can use the go-sqlite3 wrapper but we need to download and build it with commands to link it to the installed libsqlite3:
go build --tags "libsqlite3 linux"
go build --tags "libsqlite3 darwin"
More info here
But I confess I have not done it yet. I will let this open so we can post updates. Keep an eye on it.
Thanks. I have tried to build litetree with mattn/go-sqlite3 but failed. AFAIK, mattn/go-sqlite3 has hard-coded the journal mode.
Could you inform the OS you tried, the commands/steps used, and the error message?
My OS is MacOS 10.13.6 and go version is go1.10.3 darwin/amd64
steps to reproduce this:
get go-sqlite3
:
go get github.com/mattn/go-sqlite3
build litetree
and copy libs to correct path:
# go-sqlite3 find libsqlite3 in the path blow
mkdir -p /usr/local/opt/sqlite/lib
cd
3. build `go-sqlite3`
```shell
go build --tags "libsqlite3 darwin" github.com/mattn/go-sqlite3
package main
import ( "database/sql" "fmt" "log" "os"
_ "github.com/mattn/go-sqlite3"
)
func main() { os.Remove("./foo.db") db, err := sql.Open("sqlite3", "file:./foo.db?branches=on") if err != nil { log.Fatal(err) } defer db.Close()
var rows *sql.Rows
rows, err = db.Query("PRAGMA journal_mode;")
if err != nil {
log.Fatal(err)
}
for rows.Next() {
var mode string
err = rows.Scan(&mode)
fmt.Println("result: ", mode, err)
}
rows.Close()
var values interface{}
rows, err = db.Query("PRAGMA branches;")
if err != nil {
log.Fatal(err)
}
for rows.Next() {
err = rows.Scan(&values)
fmt.Println("result: ", values, err)
}
rows.Close()
}
5. the output we got from step4 is
```shell
result: delete <nil>
Notice: we got nothing from PRAGMA branches;
It's obvious that by this way go-sqlite3
was built with normal version sqlite3
, instead of litetree
.
Hi Yuan!
Thank you for your collaboration!
I was having the same problem. After 2 hours trying I discovered a workaround made of 2 steps:
sqlite3_libsqlite3.go
file from this:#cgo darwin LDFLAGS: -L/usr/local/opt/sqlite/lib -lsqlite3
To this:
#cgo darwin LDFLAGS: -L/usr/local/lib/litetree -lsqlite3
go build --tags libsqlite3
instead of just go build
.@kroggen oh, thanks! It works for me.
The key point here is to run my own go project with argument --tags libsqlite3
.
Sorry for my poor undestanding of go build tools
You're welcome!
I am not a Go developer as well. Maybe there are other ways to do this. The site says about "building the library" and installing it using go install
. But I have not tried them yet.
Since aergo blockchain kernel is written in go, is there a golang wrapper for litetree?