pgcall

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: MIT Imports: 8 Imported by: 0

README

English | Pусский


apisite/apicall

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

GoDoc codecov Build Status GoCard GitHub Release 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

Package pgcall implements a caller of postgresql stored functions, which intended to use via http and in templates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(input interface{}, output interface{}) error

Decode fills struct from map using ithub.com/mitchellh/mapstructure

Types

type Config

type Config struct {
	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"`
	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"`
}

Config defines local application flags

type DB

type DB interface {
	QueryProc(method string, args ...interface{}) ([]map[string]interface{}, error)
	Exec(sql string, arguments ...interface{}) (int64, error)
	QueryMaps(sql string, args ...interface{}) ([]map[string]interface{}, error)
	Query(sql string, args ...interface{}) ([]interface{}, error)
}

DB holda all of database methods used (see pgxpgcall)

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 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 OutDef

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

OutDef holds function result attributes

type Server

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

Server holds RPC methods

func New

func New(cfg Config, log loggers.Contextual, dbh DB) (*Server, error)

New returns pgcall server object

func (*Server) Call

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

Call postgresql stored function

func (*Server) LoadMethods

func (srv *Server) LoadMethods(nsp *string) error

LoadMethods load methods for nsp if given, all of methods otherwise

func (*Server) Method added in v0.2.2

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

Method returns method by name

Directories

Path Synopsis
gin-pgcall module
pgx-pgcall module

Jump to

Keyboard shortcuts

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