sqlconv

package module
v0.0.0-...-d45eeab Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

README

sqlconv

CI CircleCI codecov Go Reference

sqlconv is a Go library converts between Go values and SQL values.

Installation

go get github.com/dochang/sqlconv

Usage

Currently, sqlconv provides a interface ScannerConverter, which is used to convert SQL values to Go values.

type ScannerConverter interface {
	ScanConvert(dest, src any) error
}

ScanConvert converts SQL value src to Go value, then writes the Go value into dest.

A predefined variable DefaultScannerConverter converts SQL values based on the rules defined by the function "database/sql".convertAssign.

Documentation

Overview

Package sqlconv converts between Go values and SQL values.

Currently, sqlconv provides a interface ScannerConverter, which is used to convert SQL values to Go values:

type ScannerConverter interface {
  ScanConvert(dest, src any) error
}

sqlconv.ScannerConverter.ScanConvert converts SQL value src to Go value, then writes the Go value into dest.

A predefined variable DefaultScannerConverter converts SQL values based on the rules defined by the function database/sql.convertAssign.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultScannerConverter defaultScannerConverter

DefaultScannerConverter is the default implementation of ScannerConverter.

DefaultScannerConverter converts value by calling convertAssign.

Functions

This section is empty.

Types

type RawBytes

type RawBytes = sql.RawBytes

type Rows

type Rows = sql.Rows

type Scanner

type Scanner = sql.Scanner

type ScannerConverter

type ScannerConverter interface {
	// ScanConvert converts a SQL value src to a Go value dest.
	ScanConvert(dest, src any) error
}

ScannerConverter is the interface providing the ScanConvert method.

ScannerConverter converts SQL value to Go value.

Example
var deststr string
srctime := time.Unix(1, 0).UTC()
err := DefaultScannerConverter.ScanConvert(&deststr, srctime)
fmt.Println(err)
fmt.Println(deststr)
Output:

<nil>
1970-01-01T00:00:01Z

Jump to

Keyboard shortcuts

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