sqlutil

package
v0.99.16 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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