seq

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(processor func(iter.Seq[[]sqlite3.Value]) any) func() sqlite3.AggregateFunction
Example
db, err := sqlite3.Open(":memory:")
if err != nil {
	log.Fatal(err)
}
defer db.Close()

err = db.Exec(`CREATE TABLE test (col)`)
if err != nil {
	log.Fatal(err)
}

err = db.Exec(`INSERT INTO test VALUES (1), (2), (3)`)
if err != nil {
	log.Fatal(err)
}

err = db.CreateWindowFunction("seq_avg", 1, sqlite3.DETERMINISTIC|sqlite3.INNOCUOUS, Aggregate(
	func(seq iter.Seq[[]sqlite3.Value]) any {
		count := 0
		total := 0.0
		for arg := range seq {
			total += arg[0].Float()
			count++
		}
		return total / float64(count)
	}))
if err != nil {
	log.Fatal(err)
}

stmt, _, err := db.Prepare(`SELECT seq_avg(col) FROM test`)
if err != nil {
	log.Fatal(err)
}
defer stmt.Close()

for stmt.Step() {
	fmt.Println(stmt.ColumnFloat(0))
}
if err := stmt.Err(); err != nil {
	log.Fatal(err)
}
Output:

2

Types

This section is empty.

Jump to

Keyboard shortcuts

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