migrationutils

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

sanitize.go is taken from https://github.com/jackc/pgx/blob/v5.5.0/internal/sanitize/sanitize.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPostgresBatcher

func NewPostgresBatcher(tx *pachsql.Tx, action string, table string, columns []string, wColumns []string, batchSize int) (error, *postgresBatcher)

NewPostgresBatcher creates a new batcher.

func QuoteBytes

func QuoteBytes(buf []byte) string

func QuoteString

func QuoteString(str string) string

func SanitizeSQL

func SanitizeSQL(sql string, args ...any) (string, error)

SanitizeSQL replaces placeholder values with args. It quotes and escapes args as necessary. This function is only safe when standard_conforming_strings is on.

Types

type Part

type Part any

Part is either a string or an int. A string is raw SQL. An int is a argument placeholder.

type Query

type Query struct {
	Parts []Part
}

func NewQuery

func NewQuery(sql string) (*Query, error)

func (*Query) Sanitize

func (q *Query) Sanitize(args ...any) (string, error)

type SimplePostgresBatcher

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

SimplePostgresBatcher is an alternative batcher that buffers statements 'stmts' terminated by semicolons until it hits the max number of statements. The statements are then executed in one round-trip query to postgres.

func NewSimplePostgresBatcher

func NewSimplePostgresBatcher(tx *pachsql.Tx) *SimplePostgresBatcher

func (*SimplePostgresBatcher) Add

func (pb *SimplePostgresBatcher) Add(ctx context.Context, stmt string, args ...interface{}) error

Add inserts a statement to the SimplePostgresBatcher's internal buffer. If the number of statements exceeds the maximum after adding, the batcher executes the statements. SimplePostgresBatcher doesn't support buffering arguments, the arguments are sanitized then their values are inlined.

Add does not support SqlNull<X> structs like SqlNullString.

func (*SimplePostgresBatcher) Flush

func (pb *SimplePostgresBatcher) Flush(ctx context.Context) error

Flush triggers the SimplePostgresBatcher to execute any remaining buffered statements.

Jump to

Keyboard shortcuts

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