procapi

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: MIT Imports: 13 Imported by: 1

README

English | Pусский


apisite/procapi

Caller of postgresql stored functions, which intended to use via http and in templates

GoDoc codecov Build Status GoCard GitHub Release LoC GitHub code size in bytes GitHub license

Project status: WIP

License

The MIT License (MIT), see LICENSE.

Copyright (c) 2018 Aleksei Kovrizhkin lekovr+apisite@gmail.com

Documentation

Overview

callError usage:

type callError interface {
	IsNotFound() bool
	IsBadRequest() bool
	Code() string
	Error() string
	Data() map[string]interface{}
}
perr, ok := err.(callError)
if ok {
	if perr.IsNotFound() {
		status = http.StatusNotFound
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldNames added in v0.3.3

func FieldNames(rows pgx.Rows) []string

func ScanMap added in v0.3.3

func ScanMap(rows pgx.Rows, dest *map[string]interface{}) error

func ScanStruct added in v0.3.3

func ScanStruct(rows pgx.Rows, dest interface{}) error

Types

type Config

type Config struct {
	DSN           string    `long:"dsn" default:"postgres://?sslmode=disable" description:"Database connect string"`
	Driver        string    `long:"driver" default:"postgres" description:"Database driver"`
	InDefFunc     string    `long:"indef" default:"func_args" description:"Argument definition function"`
	OutDefFunc    string    `long:"outdef" default:"func_result" description:"Result row definition function"`
	IndexFunc     string    `long:"index" default:"index" description:"Available functions list"`
	FuncSchema    string    `long:"schema" default:"rpc" description:"Definition functions schema"`
	ArgSyntax     string    `long:"arg_syntax" default:":=" description:"Default named args syntax (:= or =>)"`
	ArgTrimPrefix string    `long:"arg_prefix" default:"a_" description:"Trim prefix from arg name"`
	NameSpaces    *[]string `long:"nsp" description:"Proc namespace(s)"`
}

Config defines local application flags

type InDef

type InDef struct {
	Name     string  `db:"arg"`
	Type     string  `db:"type"`
	Required bool    `db:"required"` // TODO: is_required
	Default  *string `db:"def_val" json:",omitempty"`
	Anno     *string `db:"anno" json:",omitempty"`
}

InDef holds function argument attributes

type Marshaller

type Marshaller interface {
	Marshal(typ string, v interface{}) (interface{}, error)
	Unmarshal(typ string, data interface{}) (rv interface{}, err error)
}

Marshaller holds methods for database values marshalling

type Method

type Method struct {
	Name     string           `db:"code"`
	Class    string           `db:"nspname"`
	Func     string           `db:"proname"`
	Anno     string           `db:"anno"`
	IsRO     bool             `db:"is_ro"`
	IsSet    bool             `db:"is_set"`
	IsStruct bool             `db:"is_struct"`
	Sample   *string          `db:"sample" json:",omitempty"`
	Result   *string          `db:"result" json:",omitempty"`
	In       map[string]InDef //`json:",omitempty"`
	Out      []OutDef         //`json:",omitempty"`
}

Method holds method attributes

type Option added in v0.3.3

type Option func(*Service)

Option is a functional options return type

func Marshall added in v0.3.3

func Marshall(m Marshaller) Option

Marshall allows to change default marshaller

type OutDef

type OutDef struct {
	Name string  `db:"arg"`
	Type string  `db:"type"`
	Anno *string `db:"anno" json:",omitempty"`
}

OutDef holds function result attributes

type PGType added in v0.3.3

type PGType struct{}

PGType implements marshalling between API and nonstandart postgresql types

func (PGType) Marshal added in v0.3.3

func (t PGType) Marshal(typ string, val interface{}) (rv interface{}, err error)

func (PGType) Unmarshal added in v0.3.3

func (t PGType) Unmarshal(typ string, val interface{}) (rv interface{}, err error)

type Service

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

Service holds API service methods

func New

func New(cfg Config, log loggers.Contextual, dbh *pgx.Conn, options ...Option) *Service

New returns procapi service

func (*Service) Call

func (srv *Service) Call(
	r *http.Request,
	method string,
	args map[string]interface{},
) (interface{}, error)

Call calls postgresql stored function

func (*Service) CallTx

func (srv *Service) CallTx(
	tx pgx.Tx,
	method string,
	args map[string]interface{},
) (interface{}, error)

CallTx calls postgresql stored function within given transaction

func (*Service) FetchMethods

func (srv *Service) FetchMethods(tx pgx.Tx, nsp *[]string) (map[string]Method, error)

FetchMethods fetches from DB methods definition for given namespaces

func (*Service) LoadMethodsTx

func (srv *Service) LoadMethodsTx(tx pgx.Tx) error

LoadMethodsTx load methods within given transaction for nsp if given, all of methods otherwise

func (*Service) Method

func (srv *Service) Method(name string) (Method, bool)

Method returns method by name

Directories

Path Synopsis
Package ginproc implements a gin frontend for procapi.
Package ginproc implements a gin frontend for procapi.
pgtype module

Jump to

Keyboard shortcuts

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