sqlutil

package
v0.0.0-...-30c4fd9 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sqlutil provides some helpers for SQL databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool bool

Bool add the capability to handle more column types than the usual sql driver. The following types are supported when reading the data:

  • int64 and float64 - 0 for false, true otherwise
  • bool
  • []byte and string - "1" or "true" for true, and "0" or "false" for false. Also handles the 1 bit cases.
  • nil - defaults to false

It is also prepared to be encoded and decoded to a human readable format.

func (Bool) MarshalText

func (b Bool) MarshalText() ([]byte, error)

MarshalText converts the bool to a human readable representation, that is also compatible with the JSON format.

func (*Bool) Scan

func (b *Bool) Scan(src interface{}) error

Scan converts the different types of representation of a boolean in the database into a bool type.

func (*Bool) UnmarshalText

func (b *Bool) UnmarshalText(text []byte) error

UnmarshalText parse different types of human representation of the boolean and convert it to the bool type. It is also compatible with the JSON format.

func (Bool) Value

func (b Bool) Value() (driver.Value, error)

Value converts a bool type into a number to persist it in the database.

type HTML

type HTML template.HTML

HTML is a string which indicates that the string has been HTML-escaped.

func (*HTML) Scan

func (h *HTML) Scan(v interface{}) error

Scan converts the data returned from the DB into the struct.

func (HTML) Value

func (h HTML) Value() (driver.Value, error)

Value implements the SQL Value function to determine what to store in the DB.

type IntList

type IntList []int64

IntList expands comma-separated values from a column to []int64, and stores []int64 as a comma-separated string.

This is safe for NULL values, in which case it will scan in to IntList(nil).

func (*IntList) Scan

func (l *IntList) Scan(v interface{}) error

Scan converts the data returned from the DB into the struct.

func (IntList) Value

func (l IntList) Value() (driver.Value, error)

Value implements the SQL Value function to determine what to store in the DB.

type StringList

type StringList []string

StringList expands comma-separated values from a column to []string, and stores []string as a comma-separated string.

Note that this only works for simple strings (e.g. enums), we DO NOT escape commas in strings and you will run in to problems.

This is safe for NULL values, in which case it will scan in to StringList(nil).

func (*StringList) Scan

func (l *StringList) Scan(v interface{}) error

Scan converts the data returned from the DB into the struct.

func (StringList) Value

func (l StringList) Value() (driver.Value, error)

Value implements the SQL Value function to determine what to store in the DB.

Jump to

Keyboard shortcuts

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