footrest

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultOperatorFormat = `$1 {OPERATOR} $2`

Variables

This section is empty.

Functions

func Columns

func Columns(cols ...string) []string

Columns is for FootREST.Get(ctx, "my_table", Columns("a", "b", "c"), ...)

func RegisterDialect

func RegisterDialect(name string, d *Dialect)

RegisterDialect add *Dialect d into a global map.

See doc about Dialect.

Types

type Config

type Config struct {
	Format ResponseFormat
	Params SpecialParams

	Timeout int64

	Addr string
	Root string
}

func DefaultConfig

func DefaultConfig() *Config

func (Config) Context

func (c Config) Context() (context.Context, context.CancelFunc)

type Dialect

type Dialect struct {
	Operators   map[string]Operator // key(Operator.Name) must be upper case.
	Placeholder func(int) string
	Arg         func(int, any) any

	IsValidName func(string) bool

	Paginate func(uint, uint) [2]string // (rows_per_page,page) -> stmt
}

The best way to define a dialect is use DefaultDialect() and tweek the returned dialect.

func DefaultDialect

func DefaultDialect() Dialect

func GetDialect

func GetDialect(name string) *Dialect

func (*Dialect) AddOperator

func (d *Dialect) AddOperator(name string, format string, f ...OperatorFormatter)

type FootREST

type FootREST struct {
	// contains filtered or unexported fields
}

func New

func New(conn *sql.DB, dialect string, enc encoding.Encoding, useSchema bool, config *Config) *FootREST

New creates new FootREST with already Opened connection(*sql.DB).

func NewConn

func NewConn(driverName, dataSourceName string, enc encoding.Encoding, useSchema bool, config *Config) (*FootREST, *sql.DB, error)

NewConn opens a connection and creates new FootREST with the conn.

func (*FootREST) BuildDeleteStmt

func (r *FootREST) BuildDeleteStmt(table string, whereSExpr string) (string, []any, error)

func (*FootREST) BuildGetStmt

func (r *FootREST) BuildGetStmt(table string, selColumns []string, whereSExpr string, orderColumns []string, rowsPerPage, page uint) (string, []any, error)

func (*FootREST) BuildPostStmt

func (r *FootREST) BuildPostStmt(table string, values any) (string, []any, error)

func (*FootREST) BuildPutStmt

func (r *FootREST) BuildPutStmt(table string, values map[string]any, whereSExpr string) (string, []any, error)

func (*FootREST) Bulk

func (r *FootREST) Bulk(ctx context.Context, b bulkReq) (int64, error)

func (*FootREST) BulkGet

func (r *FootREST) BulkGet(ctx context.Context, b bulkGetReq) (bulkRecordSet, error)

func (*FootREST) Delete

func (r *FootREST) Delete(ctx context.Context, table string, where string) (int64, error)

func (*FootREST) Get

func (r *FootREST) Get(ctx context.Context, table string, selColumns []string, whereSExpr string, orderColumns []string, rowsPerPage, page uint) (recordSet, error)

func (*FootREST) Post

func (r *FootREST) Post(ctx context.Context, table string, values any) (int64, error)

func (*FootREST) Put

func (r *FootREST) Put(ctx context.Context, table string, set map[string]any, where string) (int64, error)

func (*FootREST) Serve

func (r *FootREST) Serve()

type Operator

type Operator struct {
	Name      string
	Format    string            // "$1 == $2", "$1 BETWEEN $2 AND $3"
	Formatter OperatorFormatter // optional
}

func (Operator) ApplyFormat

func (o Operator) ApplyFormat(args ...string) (string, error)

type OperatorFormatter

type OperatorFormatter func(args ...string) (string, error)

type ResponseFormat

type ResponseFormat struct {
	QueryOK string
	ExecOK  string
	Error   string
}

type SPParam

type SPParam struct {
	Name      string `json:"name"`
	Direction string `json:"direction"` // in,out,inout,return
	Type      string `json:"type"`
	Value     any    `json:"value"`
}

type SpecialParams

type SpecialParams struct {
	Select string
	Where  string
	Upsert string
	Order  string
	Rows   string
	Page   string
}

Directories

Path Synopsis
dialect

Jump to

Keyboard shortcuts

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