在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:go-dqlite开源软件地址:https://gitee.com/mirrors/go-dqlite开源软件介绍:go-dqliteThis repository provides the UsageThe best way to understand how to use the In general your application will use code such as: dir := "/path/to/data/directory"address := "1.2.3.4:666" // Unique node addresscluster := []string{...} // Optional list of existing nodes, when starting a new nodeapp, err := app.New(dir, app.WithAddress(address), app.WithCluster(cluster))if err != nil { // ...}db, err := app.Open(context.Background(), "my-database")if err != nil { // ...}// db is a *sql.DB objectif _, err := db.Exec("CREATE TABLE my_table (n INT)"); err != nil // ...} BuildIn order to use the go-dqlite package in your application, you'll need to havethe dqlite C library installed on yoursystem, along with its dependencies. You then need to pass the export CGO_LDFLAGS_ALLOW="-Wl,-z,now"go build -tags libsqlite3go test -tags libsqlite3 DocumentationThe documentation for this package can be found on Godoc. DemoTo see dqlite in action, either install the Debian package from the PPA: sudo add-apt-repository -y ppa:dqlite/devsudo apt install dqlite-tools libdqlite-dev or build the dqlite C library and its dependencies from source, as describedhere, and then run: go install -tags libsqlite3 ./cmd/dqlite-demo from the top-level directory of this repository. This builds a demo dqlite application, which exposes a simple key/value storeover an HTTP API. Once the dqlite-demo --api 127.0.0.1:8001 --db 127.0.0.1:9001 &dqlite-demo --api 127.0.0.1:8002 --db 127.0.0.1:9002 --join 127.0.0.1:9001 &dqlite-demo --api 127.0.0.1:8003 --db 127.0.0.1:9003 --join 127.0.0.1:9001 & The The The Now we can start using the cluster. Let's insert a key pair: curl -X PUT -d my-value http://127.0.0.1:8001/my-key and then retrive it from the database: curl http://127.0.0.1:8001/my-key Currently the first node is the leader. If we stop it and then try to query thekey again curl will fail, but we can simply change the endpoint to another nodeand things will work since an automatic failover has taken place: kill -TERM %1; curl http://127.0.0.1:8002/my-key ShellA basic SQLite-like dqlite shell is available in the go install -tags libsqlite3 ./cmd/dqlite You can test it with the dqlite -s 127.0.0.1:9001 It supports normal SQL queries plus the special |
请发表评论