sql

package
v0.0.0-...-755224a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2023 License: BSD-3-Clause Imports: 3 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const (
	QueryNSS  = "query"
	InsertNSS = "insert"
	UpdateNSS = "update"
	DeleteNSS = "delete"
	PingNSS   = "ping"
	StatNSS   = "stat"

	SelectCmd = 0
	InsertCmd = 1
	UpdateCmd = 2
	DeleteCmd = 3

	NullExpectedCount = int64(-1)
)

Variables

This section is empty.

Functions

func BuildDeleteUri

func BuildDeleteUri(nid, region, zone, resource string) string

BuildDeleteUri - build an uri with the Delete NSS

func BuildInsertUri

func BuildInsertUri(nid, region, zone, resource string) string

BuildInsertUri - build an uri with the Insert NSS

func BuildQueryUri

func BuildQueryUri(nid, region, zone, resource string) string

BuildQueryUri - build an uri with the Query NSS

func BuildUpdateUri

func BuildUpdateUri(nid, region, zone, resource string) string

BuildUpdateUri - build an uri with the Update NSS

func BuildUri

func BuildUri(nid, region, zone, nss, resource string) string

func BuildWhere

func BuildWhere(values map[string][]string) []runtime.Attr

BuildWhere - build the []Attr based on the URL query parameters

Types

type Request

type Request struct {
	ExpectedCount int64
	Cmd           int
	Uri           string
	Template      string
	Values        [][]any
	Attrs         []runtime.Attr
	Where         []runtime.Attr
	Args          []any
	Error         error
}

Request - contains data needed to build the SQL statement related to the uri

func NewDeleteRequest

func NewDeleteRequest(uri, template string, where []runtime.Attr, args ...any) *Request

func NewInsertRequest

func NewInsertRequest(uri, template string, values [][]any, args ...any) *Request

func NewQueryRequest

func NewQueryRequest(uri, template string, where []runtime.Attr, args ...any) *Request

func NewQueryRequestFromValues

func NewQueryRequestFromValues(uri, template string, values map[string][]string, args ...any) *Request

func NewUpdateRequest

func NewUpdateRequest(uri, template string, attrs []runtime.Attr, where []runtime.Attr, args ...any) *Request

func (*Request) String

func (r *Request) String() string

func (*Request) Validate

func (r *Request) Validate() error
Example
uri := "urn:postgres:query.resource"
sql := "select * from table"
req := Request{}

err := req.Validate()
fmt.Printf("test: Validate(empty) -> %v\n", err)

req.Uri = uri
err = req.Validate()
fmt.Printf("test: Validate(%v) -> %v\n", uri, err)

req.Uri = ""
req.Template = sql
err = req.Validate()
fmt.Printf("test: Validate(%v) -> %v\n", sql, err)

req.Uri = uri
req.Template = sql
err = req.Validate()
fmt.Printf("test: Validate(all) -> %v\n", err)

//rsc := "access-log"
//t := "delete from access_log"
//req1 := NewDeleteRequest(rsc, t, nil)
//err = req1.Validate()
//fmt.Printf("test: Validate(%v) -> %v\n", t, err)

//t = "update access_log"
//req1 = NewUpdateRequest(rsc, t, nil, nil)
//err = req1.Validate()
//fmt.Printf("test: Validate(%v) -> %v\n", t, err)

//t = "update access_log"
//req1 = NewUpdateRequest(rsc, t, []pgxdml.Attr{{Name: "test", Val: "test"}}, nil)
//err = req1.Validate()
//fmt.Printf("test: Validate(%v) -> %v\n", t, err)
Output:

test: Validate(empty) -> invalid argument: request Uri is empty
test: Validate(urn:postgres:query.resource) -> invalid argument: request template is empty
test: Validate(select * from table) -> invalid argument: request Uri is empty
test: Validate(all) -> <nil>

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL