csv_to_gorm

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: MIT Imports: 11 Imported by: 1

README

csv_to_gorm

A utility to read a csv file into a gorm managed database or, more generally, into a slice of structs.

usage

Acknowledgements

This module was developed as part of a section of work undertaken for Emerald Operating Partners LLC, who have kindly agreed to its release as open source under the MIT licence.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CsvToSlice

func CsvToSlice(file *os.File, colSep rune, model interface{}, params Params) (dataSlice interface{}, err error)

converts the content of a CSV file to a slice of 'models' colMap maps the feldnames of the model to the column numbers (beginning at 1) of the CSV file the result is an interface, which will need to be typecast by the caller

func ExcelColIdToColNo

func ExcelColIdToColNo(colID string) (int, error)

func ExcelColNoToColId

func ExcelColNoToColId(colNo int) (string, error)

func GetDbFields

func GetDbFields(model interface{}) ([]string, error)

func GetHeadings

func GetHeadings(file *os.File, colSep rune) ([]string, error)

func GuessSeparator

func GuessSeparator(file *os.File) (rune, error)

inputReader would normally be the file or stream to read

func StringToType

func StringToType(input string, outType reflect.Type, params Params) reflect.Value

takes the text string of a CSV field and converts it to a reflect.Value of a given type (supplied as a reflect.Type) used internally, but exposed as it may have uses elsewhere

Types

type Params

type Params struct {
	ColMap          map[string]int    // maps fieldnames to column numbers(starting at 1).  Overrides tagnames if mapping present
	ConstMap        map[string]string // maps from tagname mapConst:Mapfrom to a string constant to be parsed into the field
	FirstRowHasData bool
	ErrorOnNaN      bool
}

type Tag

type Tag struct {
	HasTag         bool
	HasColanme     bool
	Colname        string
	IsIntColsHead  bool
	IsIntColsValue bool
	IsMapConst     bool
	ConstMapKey    string
	IsMeltHead     bool
	IsMeltValue    bool
	Ignore         []string
}

func ParseTag

func ParseTag(field reflect.StructField) (Tag, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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