An HTTP client package for directly interacting with the NSQLite database engine over HTTP/HTTPS.
Use this if you want a lower-level approach than the
database/sql
interface provided by
nsqlitego
.
- Issue raw JSON-based requests to an NSQLite server.
- Customizable headers, request methods, and endpoints.
- Handle responses as JSON or plain text.
- Zero dependencies outside the standard library.
go get github.com/nsqlite/nsqlitego
Note: This package is part of the
nsqlitego
repository.
Import it as:import "github.com/nsqlite/nsqlitego/nsqlitehttp"
client, err := nsqlitehttp.NewClient("http://localhost:9876?authToken=myToken")
if err != nil {
panic(err)
}
resp, err := client.SendQuery(context.TODO(), nsqlitehttp.Query{
Query: "SELECT id, name FROM users WHERE id > :id",
Params: []nsqlitehttp.QueryParam{{Name: "id", Value: 100}},
// TxId can be optionally set if you are managing transactions at this level
})
if err != nil {
panic(err)
}
fmt.Printf("Response Type: %s\n", resp.Type)
if resp.Type == nsqlitehttp.QueryResponseRead {
// Access resp.Columns, resp.Rows, etc.
}
You can also send multiple queries in a single request using
client.SendQueries(ctx, queries)
.
if err := client.SendPing(context.TODO()); err != nil {
fmt.Println("Server is not healthy:", err)
} else {
fmt.Println("Server is up and running.")
}
Please refer to the nsqlitehttp Go Reference for more details.