pgfc

package module
v0.0.0-...-7d90f5b Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2019 License: MIT Imports: 9 Imported by: 1

README

English | Pусский


pgfc

golang package for postgresql functions calling

GoCard GitHub Release GitHub code size in bytes GitHub license

Project status: PoC is ready

License

The MIT License (MIT), see LICENSE.

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

Documentation

Overview

Package pgfc holds pg functions call methods

Index

Constants

View Source
const (
	// SQLMethod is the SQL query for fetching method list
	// Results: err = rows.Scan(&r.Name, &r.Class, &r.Func, &r.Anno, &r.Sample, &r.Result, &r.IsRO, &r.IsSet, &r.IsStruct)
	SQLMethod = "select code, nspname, proname, anno, sample, result, is_ro, is_set, is_struct from %s($1)"
	// SQLInArgs is the SQL query for fetching method arguments definition
	// Results: err = rows.Scan(&r.Name, &r.Type, &r.Required, &r.Default, &r.Anno)
	SQLInArgs = "select arg, type, required, def_val, anno from %s($1)"
	// SQLOutArgs is the SQL query for fetching method results definition
	// Results: err = rows.Scan(&r.Name, &r.Type, &r.Anno)
	SQLOutArgs = "select arg, type, anno from %s($1)"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Schema string `long:"db_schema" default:"" description:"Database functions schema name or comma delimited list"`
	Debug  bool   `long:"db_debug" description:"Debug DB operations"`

	InDefFunc     string `long:"db_indef" default:"func_args" description:"Argument definition function"`
	OutDefFunc    string `long:"db_outdef" default:"func_result" description:"Result row definition function"`
	IndexFunc     string `long:"db_index" default:"index" description:"Available functions list"`
	ArgSyntax     string `long:"db_arg_syntax" default:":=" description:"Default named args syntax (:= or =>)"`
	ArgTrimPrefix string `long:"db_arg_prefix" default:"a_" description:"Trim prefix from arg name"`
}

Config defines local application flags

type InDef

type InDef struct {
	Name     string
	Type     string
	Required bool
	// Check    string `json:"check,omitempty" sql:"-"` // validate argument
	Default *string `json:",omitempty"`
	Anno    *string `json:",omitempty"`
}

InDef holds function argument attributes

type Logger

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

Logger holds database logging via given logger

func (Logger) Log

func (l Logger) Log(level pgx.LogLevel, msg string, data map[string]interface{})

Log message via logger

type Method

type Method struct {
	Name     string
	Class    string
	Func     string
	Anno     string
	IsRO     bool
	IsSet    bool
	IsStruct bool
	Sample   *string           `json:",omitempty"`
	Result   *string           `json:",omitempty"`
	In       *map[string]InDef `json:",omitempty"`
	Out      *[]OutDef         `json:",omitempty"`
}

Method holds method attributes

type OutDef

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

OutDef holds function result attributes

type Server

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

Server holds RPC methods

func NewServer

func NewServer(cfg Config, log loggers.Contextual, uri string, dbh *pgx.ConnPool) (*Server, error)

NewServer returns pgfc 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) MethodIsRO

func (srv *Server) MethodIsRO(method string) bool

MethodIsRO returns true if method exists and read-only

func (*Server) Methods

func (srv *Server) Methods() map[string]Method

Methods returns methods map

Jump to

Keyboard shortcuts

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