sqlstmt

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package sqlstmt holds a statement compiled on first use and reused thereafter (mache-3063fb).

It is its own package because two readers need it and neither may import the other: graph's NodesTableReader, and lloschema's projection-v6 path addressing, which graph imports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lazy

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

Lazy is a statement compiled on first use and reused thereafter.

The direct read path used to hand database/sql a query STRING on every call, so modernc compiled the same SQL from scratch and discarded it each time — about half of a warm point read once page I/O was out of the way. TestNodesTableReader_CompilesEachStatementOnce pins the fix as a count.

LAZY, deliberately. A reader is constructed against dbs that do not carry every table it can query — a standalone mache projection has no node_refs — and preparing eagerly would fail the constructor where today's code only errors when GetCallers is actually called. Preparing on first use keeps that behaviour exactly: the same call fails, at the same moment, with the same error.

A FAILED prepare is not cached. sync.Once would make one transient failure permanent for the life of the reader; here the next call simply tries again. The fast path is a single atomic load, so the lock is only ever taken by callers racing to compile the statement the first time.

func NewLazy

func NewLazy(query string) *Lazy

NewLazy returns a statement for query, not yet compiled.

func (*Lazy) Close

func (p *Lazy) Close()

Close releases the statement if one was compiled. Safe to call on a statement that was never used.

func (*Lazy) Get

func (p *Lazy) Get(db *sql.DB) (*sql.Stmt, error)

Get returns the compiled statement, compiling it on first use.

Jump to

Keyboard shortcuts

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