ws4sqlite_client package - github.com/proofrock/ws4sqlite-client-go - Go Packages

This section is empty.

This section is empty.

This section is empty.

Authentication mode for the database remote.

const (
	
	AUTH_MODE_HTTP AuthMode = "HTTP"
	
	AUTH_MODE_INLINE AuthMode = "INLINE"
	
	AUTH_MODE_NONE AuthMode = "NONE"
)
type Client struct {
	ClientBuilder
}

This struct represent a client for ws4sqlite. It can be constructed using the ClientBuilder struct, that configures it with the URL to contact and the authorization (if any). Once instantiated, it can be used to send Requests to the server.

Example:

cli, err := ws4.NewClientBuilder().
               WithURL("http://localhost:12321/db2").
               WithInlineAuth("myUser1", "myHotPassword").
               Build()

cli.Send(...)

Sends a set of requests to the remote, wrapped in a Request struct. Returns a matching set of responses, wrapped in a Response struct.

Returns a WsError if the remote service returns a processing error. If the communication fails, it returns the "naked" error, so check for cast-ability.

SendWithContext sends a set of requests to the remote with context, wrapped in a Request. Returns a matching set of responses, wrapped in a Response struct.

Returns a WsError if the remote service returns a processing error. If the communication fails, it returns the "naked" error, so check for cast-ability.

type ClientBuilder struct {
	
}

This class is a builder for Client instances. Once configured with the URL to contact and the authorization (if any), it can be used to instantiate a Client.

Example:

cli, err := ws4.NewClientBuilder().
               WithURL("http://localhost:12321/db2").
               WithInlineAuth("myUser1", "myHotPassword").
               Build()

cli.Send(...)
func NewClientBuilder() *ClientBuilder

First step when building. Generates a new ClientBuilder instance.

Returns the Client that was built.

func (cb *ClientBuilder) WithHTTPAuth(user, password string) *ClientBuilder

Builder methods that configures HTTP Basic Authentication; the remote must be configured accordingly.

func (cb *ClientBuilder) WithInlineAuth(user, password string) *ClientBuilder

Builder methods that configures INLINE authentication; the remote must be configured accordingly.

Builder methods that adds a "raw" URL for contacting the ws4sqlite remote.

Builder methods that adds an URL for contacting the ws4sqlite remote, given its components.

func (cb *ClientBuilder) WithURLComponentsNoPort(protocol Protocol, host string, databaseId string) *ClientBuilder

Builder methods that adds an URL for contacting the ws4sqlite remote, given its components but with an implicit port.

Used in URL composition

const (
	
	PROTOCOL_HTTP Protocol = "http"
	
	PROTOCOL_HTTPS Protocol = "https"
)

Container class for a request to ws4sqlite. Built with RequestBuilder.

type RequestBuilder struct {
	
}

A builder class to build a Request to send to the ws4sqlite server with the <Client>.Send(Request) method.

If an error is encountered during built, it's returned at Build() time, to be able to chain.

func NewRequestBuilder() *RequestBuilder

First step when building. Generates a new RequestBuilder instance.

Adds a new request to the list, for a query. It must be configured later on with the proper methods.

func (rb *RequestBuilder) AddStatement(statement string) *RequestBuilder

Adds a new request to the list, for a statement. It must be configured later on with the proper methods.

Returns the Request that was built, returning also any error that was encountered during build.

Add a decoder to the request. Allowed only for queries.

Add an encoder to the request. Allowed only for statements.

func (*RequestBuilder) WithEncoderAndCompression ΒΆ

func (rb *RequestBuilder) WithEncoderAndCompression(password string, compressionLevel int, fields ...string) *RequestBuilder

Add an encoder to the request, with compression. Allowed only for statements.

func (rb *RequestBuilder) WithNoFail() *RequestBuilder

Specify that the request must not cause a general failure.

func (rb *RequestBuilder) WithValues(values map[string]interface{}) *RequestBuilder

Adds a list of values (ok, amap) for the request. If there's already one, it creates a batch.

type Response struct {
	
	Results []ResponseItem
}

Response coming from the endpoint, that is a list of single responses matching the list of request that were submitted. The single responses are of type ResponseItem.

type ResponseItem struct {
	
	Success bool
	
	
	RowsUpdated *int64
	
	
	RowsUpdatedBatch []int64
	
	
	ResultSet []map[string]interface{}
	
	Error string
}

Single response coming from ws4sqlite. Every ResponseItem matches a node of the request, and each one has exactly one of the following fields populated/not null:

- Error: reason for the error, if it wasn't successful;

- RowsUpdated: if the node was a statement and no batching was involved; it's the number of updated rows;

- RowsUpdatedBatch: if the node was a statement and a batch of values was provided; it's a slice of the numbers of updated row for each batch item;

- ResultSet: if the node was a query; it's a slice of maps with an item per returned record, and each map has the name of the filed as a key of each entry, and the value as a value.