pgrest

package module
v0.0.0-...-48b859a Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int

Action type

const (
	// Get action
	Get Action = 1 << iota
	// Post action
	Post
	// Put action
	Put
	// Patch action
	Patch
	// Delete action
	Delete
)
const All Action = Get + Post + Put + Patch + Delete

All actions

const None Action = 0

None action

func (Action) String

func (a Action) String() string

type BytesReader

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

BytesReader is reader implementation

func NewBytesReader

func NewBytesReader(b []byte) *BytesReader

NewBytesReader creates new instance

func (*BytesReader) Buffered

func (r *BytesReader) Buffered() int

Buffered executes buffered

func (*BytesReader) Bytes

func (r *BytesReader) Bytes() []byte

Bytes gets bytes

func (*BytesReader) Discard

func (r *BytesReader) Discard(n int) (int, error)

Discard discards

func (*BytesReader) Read

func (r *BytesReader) Read(b []byte) (n int, err error)

Read reads

func (*BytesReader) ReadByte

func (r *BytesReader) ReadByte() (byte, error)

ReadByte reads byte

func (*BytesReader) ReadBytes

func (r *BytesReader) ReadBytes(fn func(byte) bool) ([]byte, error)

ReadBytes reads bytes

func (*BytesReader) ReadFull

func (r *BytesReader) ReadFull() ([]byte, error)

ReadFull reads full

func (*BytesReader) ReadFullTemp

func (r *BytesReader) ReadFullTemp() ([]byte, error)

ReadFullTemp reads full temp

func (*BytesReader) ReadN

func (r *BytesReader) ReadN(n int) ([]byte, error)

ReadN reads int

func (*BytesReader) ReadSlice

func (r *BytesReader) ReadSlice(delim byte) ([]byte, error)

ReadSlice reads slice

func (*BytesReader) Reset

func (r *BytesReader) Reset(b []byte)

Reset resets

func (*BytesReader) UnreadByte

func (r *BytesReader) UnreadByte() error

UnreadByte undreads byte

type Config

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

Config structure

func NewConfig

func NewConfig(prefix string, db *pg.DB) *Config

NewConfig constructs Config

func (*Config) AddResource

func (c *Config) AddResource(resource *Resource)

AddResource adds resource

func (*Config) DB

func (c *Config) DB() *pg.DB

DB gets db

func (*Config) DefaultAccept

func (c *Config) DefaultAccept() string

DefaultAccept gets defaultAccept

func (*Config) DefaultContentType

func (c *Config) DefaultContentType() string

DefaultContentType gets defaultContentType

func (*Config) ErrorLogger

func (c *Config) ErrorLogger() *log.Logger

ErrorLogger gets error logger

func (*Config) GetResource

func (c *Config) GetResource(resourceName string) *Resource

GetResource gets resource

func (*Config) InfoLogger

func (c *Config) InfoLogger() *log.Logger

InfoLogger gets info logger

func (*Config) Prefix

func (c *Config) Prefix() string

Prefix gets prefix

func (*Config) SetDefaultAccept

func (c *Config) SetDefaultAccept(defaultAccept string)

SetDefaultAccept sets defaultAccept

func (*Config) SetDefaultContentType

func (c *Config) SetDefaultContentType(defaultContentType string)

SetDefaultContentType sets defaultContentType

func (*Config) SetErrorLogger

func (c *Config) SetErrorLogger(logger *log.Logger)

SetErrorLogger sets error logger

func (*Config) SetInfoLogger

func (c *Config) SetInfoLogger(logger *log.Logger)

SetInfoLogger sets info logger

func (*Config) SetPrefix

func (c *Config) SetPrefix(prefix string)

SetPrefix sets prefix

func (*Config) String

func (c *Config) String() string

type Engine

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

Engine structure

func NewEngine

func NewEngine(config *Config) *Engine

NewEngine constructs Engine

func (*Engine) Config

func (e *Engine) Config() *Config

Config gets config

func (*Engine) Deserialize

func (e *Engine) Deserialize(restQuery *RestQuery, resource *Resource, entity interface{}) error

Deserialize deserializes data into entity

func (*Engine) Execute

func (e *Engine) Execute(restQuery *RestQuery) (interface{}, error)

Execute executes a rest query

type Error

type Error struct {
	Message string
	Cause   error
	Code    int
}

Error struct

func NewErrorBadRequest

func NewErrorBadRequest(message string) *Error

NewErrorBadRequest constructs Error with bad request code

func NewErrorForbbiden

func NewErrorForbbiden(message string) *Error

NewErrorForbbiden constructs Error with forbidden code

func NewErrorFromCause

func NewErrorFromCause(restQuery *RestQuery, cause error) *Error

NewErrorFromCause constructs Error from cause error

func (Error) Error

func (e Error) Error() string

Error implements the error interface

func (Error) StatusCode

func (e Error) StatusCode() int

StatusCode returns code

type Executor

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

Executor structure

func NewExecutor

func NewExecutor(restQuery *RestQuery, entity interface{}) *Executor

NewExecutor constructs Executor

func (*Executor) DeleteExecFunc

func (e *Executor) DeleteExecFunc() transactional.ExecFunc

DeleteExecFunc deletes execution function

func (*Executor) ExecuteWithSearchPath

func (e *Executor) ExecuteWithSearchPath(ctx context.Context, searchPath string, execFunc transactional.ExecFunc) error

ExecuteWithSearchPath executes with search path

func (*Executor) GetOneExecFunc

func (e *Executor) GetOneExecFunc() transactional.ExecFunc

GetOneExecFunc gets one execution function

func (*Executor) GetSearchPath

func (e *Executor) GetSearchPath(ctx context.Context) (string, error)

GetSearchPath gets search path

func (*Executor) GetSliceExecFunc

func (e *Executor) GetSliceExecFunc() transactional.ExecFunc

GetSliceExecFunc gets slice execution function

func (*Executor) InsertExecFunc

func (e *Executor) InsertExecFunc() transactional.ExecFunc

InsertExecFunc inserts execution function

func (*Executor) UpdateExecFunc

func (e *Executor) UpdateExecFunc() transactional.ExecFunc

UpdateExecFunc updates execution function

type Field

type Field struct {
	Name string
}

Field structure

func (*Field) String

func (f *Field) String() string

type Filter

type Filter struct {
	Op      Op          // operation
	Attr    string      // attribute name
	Value   interface{} // attribute value
	Filters []*Filter   // sub filters for 'and' and 'or' operations
}

Filter structure

func (*Filter) String

func (f *Filter) String() string

type Op

type Op string

Op operation filter type

const (
	// And operation for group
	And Op = "and"
	// Or operation for group
	Or Op = "or"
	// Eq operation for attribute (? = ?)
	Eq Op = "eq"
	// Neq operation for attribute (? != ?)
	Neq Op = "neq"
	// In operation for attribute (? IN ?)
	In Op = "in"
	// Nin operation for attribute (? NOT IN ?)
	Nin Op = "nin"
	// Gt operation for attribute (? > ?)
	Gt Op = "gt"
	// Gte operation for attribute (? >= ?)
	Gte Op = "gte"
	// Lt operation for attribute (? < ?)
	Lt Op = "lt"
	// Lte operation for attribute (? <= ?)
	Lte Op = "lte"
	// Lk operation for attribute (? LIKE ?)
	Lk Op = "lk"
	// Nlk operation for attribute (? NOT LIKE ?)
	Nlk Op = "nlk"
	// Ilk operation for attribute (? ILIKE ?)
	Ilk Op = "ilk"
	// Nilk operation for attribute (? NOT ILIKE ?)
	Nilk Op = "nilk"
	// Sim operation for attribute (? SIMILAR TO ?)
	Sim Op = "sim"
	// Nsim operation for attribute (? NOT SIMILAR TO ?)
	Nsim Op = "nsim"
	// Ilkua operation for attribute (? ILIKE ? WITH UNACCENT)
	Ilkua Op = "ilkua"
	// Nilkua operation for attribute (? NOT ILIKE ? WITH UNACCENT)
	Nilkua Op = "nilkua"
	// Null operation for attribute (? IS NULL)
	Null Op = "null"
	// Nnull operation for attribute (? IS NOT NULL)
	Nnull Op = "nnull"
)

func (Op) String

func (o Op) String() string

type Page

type Page struct {
	Slice  interface{} `json:"slice"`
	Offset int         `json:"offset"`
	Limit  int         `json:"limit"`
	Count  int         `json:"count"`
}

Page structure

func NewPage

func NewPage(slice interface{}, count int, restQuery *RestQuery) *Page

NewPage constructs Page

type Relation

type Relation struct {
	Name string
}

Relation structure

func (*Relation) String

func (r *Relation) String() string

type Resource

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

Resource structure

func NewResource

func NewResource(name string, entity interface{}, action Action) *Resource

NewResource constructs Resource

func (*Resource) Action

func (r *Resource) Action() Action

Action returns action

func (*Resource) Name

func (r *Resource) Name() string

Name returns name

func (*Resource) ResourceType

func (r *Resource) ResourceType() reflect.Type

ResourceType returns resourceType

func (*Resource) String

func (r *Resource) String() string

type RestQuery

type RestQuery struct {
	Request     *http.Request
	Action      Action
	Resource    string
	Key         string
	ContentType string
	Accept      string
	Content     []byte
	Offset      int
	Limit       int
	Fields      []*Field
	Relations   []*Relation
	Sorts       []*Sort
	Filter      *Filter
	SearchPath  string
	Debug       bool
}

RestQuery structure

func RequestDecoder

func RequestDecoder(request *http.Request, config *Config) *RestQuery

RequestDecoder decodes rest parameters from request

func (*RestQuery) String

func (q *RestQuery) String() string

type Server

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

Server structure

func NewServer

func NewServer(config *Config) *Server

NewServer constructs Server

func (*Server) Serialize

func (s *Server) Serialize(restQuery *RestQuery, entity interface{}) ([]byte, string, error)

Serialize serializes data into entity

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request)

ServeHTTP serves rest request

func (*Server) SetNextHandler

func (s *Server) SetNextHandler(next http.Handler)

SetNextHandler sets next handler for middleware use

type Sort

type Sort struct {
	Name string
	Asc  bool
}

Sort structure

func (*Sort) String

func (s *Sort) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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