dapgx

package module
v0.0.0-...-ebfb46d Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: BSD-2-Clause Imports: 26 Imported by: 2

README

dapgx

dapgx provides PostgreSQL backends for the daql project.

This project implements a custom set of decoder and encoders for xelf literals.

License

Copyright (c) Martin Schnabel. All rights reserved. Use of the source code is governed by a BSD-style license that can found in the LICENSE file.

Credit

The encoder, decoder and text array details were strictly rewritten based on pgtype. The original pgtype code uses the MIT LICENSE and the Copyright (c) 2013-2021 Jack Christensen

Documentation

Overview

The text array details were mostly rewritten based on pgtype. pgtype uses the MIT LICENSE and the Copyright (c) 2013-2021 Jack Christensen

Index

Constants

View Source
const (
	PrecOr
	PrecAnd
	PrecNot
	PrecIs  // , is null, is not null, …
	PrecCmp // <, >, =, <=, >=, <>, !=
	PrecIn  // , between, like, ilike, similar
	PrecDef
	PrecAdd // +, -
	PrecMul // *, /, %
)

Variables

View Source
var External = fmt.Errorf("external symbol")

Functions

func ColKey

func ColKey(key string, t typ.Type) (string, error)

func Exec

func Exec(ctx context.Context, pc PC, sql string, args []lit.Val) error

func FieldEncoder

func FieldEncoder(oid uint32, arg lit.Val) (encoder, error)

func Open

func Open(ctx context.Context, dsn string, logger pgx.Logger) (*pgxpool.Pool, error)

func Query

func Query(ctx context.Context, pc PC, sql string, args []lit.Val) (pgx.Rows, error)

func Quote

func Quote(text string) string

func ScanMany

func ScanMany(reg lit.Regs, scal bool, mut lit.Mut, rows pgx.Rows) (err error)

func ScanOne

func ScanOne(reg lit.Regs, scal bool, mut lit.Mut, rows pgx.Rows) error

func TypString

func TypString(t typ.Type) (string, error)

func Unreserved

func Unreserved(name string) (string, bool)

Unreserved returns the lowercase key and whether it is an unreserved identifier. If unreserved returns false the key must be escaped with double quotes.

func WithTx

func WithTx(ctx context.Context, db DB, f func(PC) error) error

func WriteCall

func WriteCall(w *Writer, env exp.Env, e *exp.Call) error

WriteCall writes the expression e to w using env or returns an error. Most xelf expressions with resolvers from the core or lib built-ins have a corresponding expression in postgresql. Custom resolvers can be rendered to sql by detecting and handling them before calling this function.

func WriteExp

func WriteExp(w *Writer, env exp.Env, e exp.Exp) error

WriteExp writes the element e to w or returns an error. This is used for explicit selectors for example.

func WriteIdent

func WriteIdent(w bfr.Writer, name string) (err error)

func WriteLit

func WriteLit(b *Writer, l *exp.Lit) error

WriteLit renders the literal l to b or returns an error.

func WriteQuote

func WriteQuote(w *Writer, text string) error

WriteQuote quotes a string as a postgres string, all single quotes are use sql escaping.

func WriteVal

func WriteVal(b *Writer, t typ.Type, l lit.Val) error

Types

type C

type C interface {
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	CopyFrom(context.Context, pgx.Identifier, []string, pgx.CopyFromSource) (int64, error)
}

type DB

type DB interface {
	Begin(context.Context) (pgx.Tx, error)
}

type Decoder

type Decoder func([]byte) (lit.Val, error)

Decoder is a function to decode either a text or binary postgres result to a literal.

func FieldDecoder

func FieldDecoder(oid uint32, bin bool) (res Decoder)

FieldDecoder returns a decoder for the given field description fd.

type DecoderPair

type DecoderPair struct{ Text, Binary Decoder }

func FieldDecoders

func FieldDecoders(oid uint32) DecoderPair

type ExpEnv

type ExpEnv struct{}

func (ExpEnv) Translate

func (ee ExpEnv) Translate(p *exp.Prog, env exp.Env, s *exp.Sym) (n string, v lit.Val, err error)

type PC

type PC interface {
	C
	Prepare(context.Context, string, string) (*pgconn.StatementDescription, error)
}

type Param

type Param struct {
	Name  string
	Type  typ.Type
	Value lit.Val
}

type Scanner

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

Scanner is a simplified xelf-aware Scanner for pgx rows. it avoids some hacks on my end, alleviate many extra type checks and has better null handling for my use-case.

func NewScanner

func NewScanner(scal bool, rows pgx.Rows) (*Scanner, error)

func (*Scanner) Scan

func (s *Scanner) Scan(m lit.Mut) (err error)

type Translator

type Translator interface {
	Translate(*exp.Prog, exp.Env, *exp.Sym) (string, lit.Val, error)
}

type WrapBool

type WrapBool lit.Bool

func (WrapBool) EncodeBinary

func (w WrapBool) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapBool) EncodeText

func (w WrapBool) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapIdxr

type WrapIdxr struct {
	lit.Idxr
	Oid int32
}

func (WrapIdxr) EncodeBinary

func (w WrapIdxr) EncodeBinary(ci *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapIdxr) EncodeText

func (w WrapIdxr) EncodeText(ci *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapInt2

type WrapInt2 lit.Int

func (WrapInt2) EncodeBinary

func (w WrapInt2) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapInt2) EncodeText

func (w WrapInt2) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapInt4

type WrapInt4 lit.Int

func (WrapInt4) EncodeBinary

func (w WrapInt4) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapInt4) EncodeText

func (w WrapInt4) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapInt8

type WrapInt8 lit.Int

func (WrapInt8) EncodeBinary

func (w WrapInt8) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapInt8) EncodeText

func (w WrapInt8) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapJSON

type WrapJSON struct{ lit.Val }

func (WrapJSON) EncodeBinary

func (w WrapJSON) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapJSON) EncodeText

func (w WrapJSON) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapJSONB

type WrapJSONB struct{ lit.Val }

func (WrapJSONB) EncodeBinary

func (w WrapJSONB) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapJSONB) EncodeText

func (w WrapJSONB) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapNull

type WrapNull lit.Null

func (WrapNull) EncodeBinary

func (w WrapNull) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapNull) EncodeText

func (w WrapNull) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapRaw

type WrapRaw lit.Raw

func (WrapRaw) EncodeBinary

func (w WrapRaw) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapRaw) EncodeText

func (w WrapRaw) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapReal4

type WrapReal4 lit.Real

func (WrapReal4) EncodeBinary

func (w WrapReal4) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapReal4) EncodeText

func (w WrapReal4) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapReal8

type WrapReal8 lit.Real

func (WrapReal8) EncodeBinary

func (w WrapReal8) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapReal8) EncodeText

func (w WrapReal8) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapSpan

type WrapSpan lit.Span

func (WrapSpan) EncodeBinary

func (w WrapSpan) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapSpan) EncodeText

func (w WrapSpan) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapSpanTime

type WrapSpanTime lit.Span

func (WrapSpanTime) EncodeBinary

func (w WrapSpanTime) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapSpanTime) EncodeText

func (w WrapSpanTime) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapStr

type WrapStr lit.Str

func (WrapStr) EncodeBinary

func (w WrapStr) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapStr) EncodeText

func (w WrapStr) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapTime

type WrapTime lit.Time

func (WrapTime) EncodeBinary

func (w WrapTime) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapTime) EncodeText

func (w WrapTime) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapTimeDate

type WrapTimeDate lit.Time

func (WrapTimeDate) EncodeBinary

func (w WrapTimeDate) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapTimeDate) EncodeText

func (w WrapTimeDate) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapTimestamp

type WrapTimestamp lit.Time

func (WrapTimestamp) EncodeBinary

func (w WrapTimestamp) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapTimestamp) EncodeText

func (w WrapTimestamp) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type WrapUUID

type WrapUUID lit.UUID

func (WrapUUID) EncodeBinary

func (w WrapUUID) EncodeBinary(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

func (WrapUUID) EncodeText

func (w WrapUUID) EncodeText(_ *pgtype.ConnInfo, b []byte) ([]byte, error)

type Writer

type Writer struct {
	gen.Gen
	Prog *exp.Prog
	Translator
	Params []Param
}

func NewWriter

func NewWriter(b bfr.Writer, pr *dom.Project, p *exp.Prog, t Translator) *Writer

func (*Writer) Translate

func (w *Writer) Translate(p *exp.Prog, env exp.Env, s *exp.Sym) (string, lit.Val, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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