clickhouse_go_rows_utils

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 1 Imported by: 0

README

clickhouse-go-rows-utils Go Reference Lint Test

Library that simplify working with rows in clickhouse-go.

Install

go get github.com/EpicStep/clickhouse-go-rows-utils

Documentation

Documentation for all functions available at pkg.go.dev

Usage example

package main

import (
	"context"
	
	rowsutils "github.com/EpicStep/clickhouse-go-rows-utils"
)

func main() {
	// connect to database.
	rows, err := db.Query(context.Background(), "SELECT 1")
	if err != nil {
		panic(err)
	}
	
	err = rowsutils.ForEachRow(rows, func(row rowsutils.CollectableRow) error {
		// scan your rows or do other work.
		return nil
	})
	if err != nil {
		panic(err)
	}
}

Documentation

Overview

Package clickhouse_go_rows_utils implement utils for working with rows at clickhouse-go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendRows

func AppendRows[T any, S ~[]T](slice S, rows driver.Rows, fn RowToFunc[T]) (S, error)

AppendRows iterates through rows, calling fn for each row, and appending the results into a slice of T.

func CollectRows

func CollectRows[T any](rows driver.Rows, fn RowToFunc[T]) ([]T, error)

CollectRows iterates through rows, calling fn for each row, and collecting the results into a slice of T.

func ForEachRow

func ForEachRow(rows driver.Rows, fn ForEachRowFunc) error

ForEachRow iterates through rows, calling fn for each row.

Types

type CollectableRow

type CollectableRow interface {
	Scan(dest ...any) error
	ScanStruct(dest any) error
	ColumnTypes() []driver.ColumnType
	Totals(dest ...any) error
	Columns() []string
}

CollectableRow is the subset of Rows methods that a RowToFunc is allowed to call.

type ForEachRowFunc

type ForEachRowFunc func(row CollectableRow) error

ForEachRowFunc calls at each row.

type RowToFunc

type RowToFunc[T any] func(row CollectableRow) (T, error)

RowToFunc is a function that scans or otherwise converts row to a T.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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