sql

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package sql provides bulk insert and upsert SQL query builders with retry helpers.

Index

Constants

View Source
const PQParamPlaceholder = "$"

Variables

This section is empty.

Functions

func GenerateBulkInsertSQL

func GenerateBulkInsertSQL[T any](
	tableName string,
	paramPlaceholder string,
	entityList []T,
	entityProcessor func(entity T) map[string]any,
) (sql string, params []any)

func GenerateBulkUpsertSQL

func GenerateBulkUpsertSQL(
	tableName string,
	columns, conflictColumns, updateColumns []string,
	rowCount int,
	rowValues func(i int) []any,
) (query string, args []any, err error)

GenerateBulkUpsertSQL requires non-empty conflictColumns. Empty updateColumns => DO NOTHING on that conflict.

func GenerateInsertSQL

func GenerateInsertSQL(tableName string, fieldsValuesMapping map[string]any) (sql string, params []any)

func GenerateUpsertSQL

func GenerateUpsertSQL(tableName string, fieldsValuesMapping map[string]any, conflictColumns []string) (sql string, params []any)

GenerateUpsertSQL appends ON CONFLICT only when conflictColumns is non-empty.

func QueryRowToStruct

func QueryRowToStruct[T any](ctx context.Context, conn sqlscan.Querier, query string, args ...any) (*T, error)

func QueryRowsPrimitive

func QueryRowsPrimitive[T any](ctx context.Context, conn sqlscan.Querier, query string, args ...any) ([]T, error)

func QueryRowsPrimitiveWithRetry

func QueryRowsPrimitiveWithRetry[T any](ctx context.Context, conn sqlscan.Querier, query string, args ...any) ([]T, error)

QueryRowsPrimitiveWithRetry is QueryRowsPrimitive wrapped for read-replica conflict retry.

func QueryRowsToStruct

func QueryRowsToStruct[T any](ctx context.Context, conn sqlscan.Querier, query string, args ...any) ([]*T, error)

func QueryRowsToStructWithRetry

func QueryRowsToStructWithRetry[T any](ctx context.Context, conn sqlscan.Querier, query string, args ...any) ([]*T, error)

QueryRowsToStructWithRetry is QueryRowsToStruct wrapped for read-replica conflict retry.

Types

This section is empty.

Jump to

Keyboard shortcuts

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