sqlutil

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTransaction

func WithTransaction(db *sqlx.DB, fn func(txn *sqlx.Tx) error) (err error)

WithTransaction runs a block of code passing in an SQL transaction If the code returns an error or panics then the transactions is rolled back Otherwise the transaction is committed.

Types

type Chunker

type Chunker interface {
	Len() int
	Subslice(i, j int) Chunker
}

func Chunkify

func Chunkify(numParamsPerStmt, maxParamsPerCall int, entries Chunker) []Chunker

Chunkify will break up things to be inserted based on the number of params in the statement. It is required because postgres has a limit on the number of params in a single statement (65535). Inserting events using NamedExec involves 3n params (n=number of events), meaning it's easy to hit the limit in rooms like Matrix HQ. This function breaks up the events into chunks which can be batch inserted in multiple statements. Without this, you'll see errors like:

"pq: got 95331 parameters but PostgreSQL only supports 65535 parameters"

Jump to

Keyboard shortcuts

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