Skip to content

Latest commit

 

History

History
81 lines (62 loc) · 1.96 KB

README.md

File metadata and controls

81 lines (62 loc) · 1.96 KB

nsqlitehttp

Go Reference

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.

Features

  • 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.

Installation

go get github.com/nsqlite/nsqlitego

Note: This package is part of the nsqlitego repository.
Import it as:

import "github.com/nsqlite/nsqlitego/nsqlitehttp"

Usage

Creating a Client

client, err := nsqlitehttp.NewClient("http://localhost:9876?authToken=myToken")
if err != nil {
  panic(err)
}

Sending Queries

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).

Ping / Health Check

if err := client.SendPing(context.TODO()); err != nil {
  fmt.Println("Server is not healthy:", err)
} else {
  fmt.Println("Server is up and running.")
}

Advanced Usage

Please refer to the nsqlitehttp Go Reference for more details.