godbf

package
v0.0.0-...-de9c804 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveToFile

func SaveToFile(data []byte, filename string) (err error)

func UseFilter

func UseFilter(table *DbfTable, f DbfFilters)

Types

type DbaseDataType

type DbaseDataType byte

A dBase data type, as per https://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm, under heading "Storage of dBASE Data Types".

const (
	Character DbaseDataType = 'C'
	Logical   DbaseDataType = 'L'
	Date      DbaseDataType = 'D'
	Numeric   DbaseDataType = 'N'
	Float     DbaseDataType = 'F'
)

type DbfFilters

type DbfFilters struct {
	Repls []struct {
		Name string `json:"name"`
		F    string `json:"f"`
		R    string `json:"r"`
	} `json:"repls"`
	File string `json:"file"`
}

type DbfSchema

type DbfSchema struct {
	FieldName     string `json:"name"`
	Alias         string `json:"alias"`
	Header        bool   `json:"header"`
	DataType      string `json:"type"`
	FieldLength   byte   `json:"length"`
	DecimalPlaces uint8  `json:"decimal"`
	Format        string `json:"format"`
	Default       string `json:"default"`
	Expr          string `json:"expr"`
}

DbfSchema describe table fields

func JoinSchemas

func JoinSchemas(base, detail []DbfSchema) (res []DbfSchema)

type DbfTable

type DbfTable struct {
	// contains filtered or unexported fields
}

DbfTable describe dbf file

func New

func New(encoding string) (table *DbfTable)

New creates a new dbase table from scratch for the given character encoding

func NewFromByteArray

func NewFromByteArray(data []byte, codepage string) (table *DbfTable, err error)

NewFromByteArray create dbf from byte array

func NewFromCSV

func NewFromCSV(filename string, codepageFrom string, headers bool, skip int, comma rune, schema []DbfSchema, codepageTo string) (DbfTable, error)

NewFromCSV create schema-based dbf and fill it from csv file

func NewFromCSVReader

func NewFromCSVReader(src io.Reader, codepageFrom string, headers bool, skip int, comma rune, schema []DbfSchema, codepageTo string) (table DbfTable, e error)

func NewFromDBF

func NewFromDBF(ctx context.Context, filename string, codepageFrom string, schema []DbfSchema, codepageTo string) (DbfTable, error)

NewFromDBF recreate dbf, aliases and field restrictions are supported

func NewFromDBFReader

func NewFromDBFReader(ctx context.Context, src io.Reader, codepageFrom string, schema []DbfSchema, codepageTo string) (table DbfTable, e error)

func NewFromFile

func NewFromFile(fileName string, codepage string) (table *DbfTable, err error)

NewFromFile create in-memory dbf from file on disk

func NewFromJSON

func NewFromJSON(ctx context.Context, filename string, codepageFrom string, schema []DbfSchema, codepageTo string) ([]DbfTable, error)

func NewFromJSONReader

func NewFromJSONReader(ctx context.Context, src io.Reader, codepageFrom string, schema []DbfSchema, codepageTo string) (tables []DbfTable, e error)

func NewFromSchema

func NewFromSchema(schema []DbfSchema, codepage string) (DbfTable, error)

NewFromSchema create schema-based dbf

func NewFromXLS

func NewFromXLS(filename string, codepageFrom string, sheet string, keycolumn, skip int, schema []DbfSchema, codepageTo string) (table DbfTable, e error)

NewFromXLS create schema-based dbf from excel file ошибка форматирования ячеек, закомментировал проблемную часть xls/col.go:

func (c *NumberCol) String(wb *WorkBook) []string {
	//if fNo := wb.Xfs[c.Index].formatNo(); fNo != 0 {
	//	t := timeFromExcelTime(c.Float, wb.dateMode == 1)
	//	log.Println(t)
	//	return []string{yymmdd.Format(t, wb.Formats[fNo].str)}
	//}
	return []string{strconv.FormatFloat(c.Float, 'f', -1, 64)}
}

func NewFromXML

func NewFromXML(ctx context.Context, filename string, codepageFrom string, schema []DbfSchema, codepageTo string) ([]DbfTable, error)

func NewFromXMLReader

func NewFromXMLReader(ctx context.Context, src io.Reader, codepageFrom string, schema []DbfSchema, codepageTo string) (tables []DbfTable, e error)

NewFromXMLReader create dbf from XML

func (*DbfTable) AddBooleanField

func (dt *DbfTable) AddBooleanField(fieldName string) (err error)

func (*DbfTable) AddDateField

func (dt *DbfTable) AddDateField(fieldName string, format string) (err error)

func (*DbfTable) AddFieldAs

func (dt *DbfTable) AddFieldAs(src *FieldDescriptor, name string) (err error)

AddFieldAs add field to dst like another from src

func (*DbfTable) AddFloatField

func (dt *DbfTable) AddFloatField(fieldName string, length byte, decimalPlaces uint8) (err error)

func (*DbfTable) AddNewRecord

func (dt *DbfTable) AddNewRecord() (newRecordNumber int)

AddNewRecord adds a new empty record to the table, and returns the index number of the record.

func (*DbfTable) AddNumberField

func (dt *DbfTable) AddNumberField(fieldName string, length byte, decimalPlaces uint8) (err error)

func (*DbfTable) AddSchema

func (dt *DbfTable) AddSchema(sch []DbfSchema) (err error)

AddSchema add fields to new dbf

func (*DbfTable) AddTextField

func (dt *DbfTable) AddTextField(fieldName string, length byte) (err error)

func (*DbfTable) CopySchema

func (dt *DbfTable) CopySchema() *DbfTable

func (*DbfTable) Data

func (dt *DbfTable) Data() []byte

func (*DbfTable) Dbase

func (dt *DbfTable) Dbase() []byte

func (*DbfTable) DecimalPlacesInField

func (dt *DbfTable) DecimalPlacesInField(fieldName string) (uint8, error)

DecimalPlacesInField returns the number of decimal places for the field with the given name. If the field does not exist, or does not use decimal places, an error is returned.

func (*DbfTable) DeleteRow

func (dt *DbfTable) DeleteRow(row int) error

DeleteRow deleted row by num

func (*DbfTable) FieldByName

func (dt *DbfTable) FieldByName(fieldName string) FieldDescriptor

FieldByName return the field descriptor of the table

func (*DbfTable) FieldIdx

func (dt *DbfTable) FieldIdx(fieldName string) (int, error)

FieldIdx returns field index if the table has a field with the given name If the field does not exist an error is returned.

func (*DbfTable) FieldNames

func (dt *DbfTable) FieldNames() []string

FieldNames return the names of fields in the table as a slice

func (*DbfTable) FieldValue

func (dt *DbfTable) FieldValue(row int, fieldIndex int) (value string)

FieldValue returns the content for the record at the given row and field index as a string If the row or field index is invalid, an error is returned .

func (*DbfTable) FieldValueByName

func (dt *DbfTable) FieldValueByName(row int, fieldName string) (value string, err error)

FieldValueByName returns the value of a field given row number and name provided

func (*DbfTable) Fields

func (dt *DbfTable) Fields() []FieldDescriptor

Fields return the fields of the table as a slice

func (*DbfTable) Float64FieldValueByName

func (dt *DbfTable) Float64FieldValueByName(row int, fieldName string) (value float64, err error)

Float64FieldValueByName returns the value of a field given row number and name provided as a float64

func (*DbfTable) FormatValue

func (dt *DbfTable) FormatValue(fieldName, value string) string

func (*DbfTable) GetRowAsSlice

func (dt *DbfTable) GetRowAsSlice(row int) []string

GetRowAsSlice return the record values for the row specified as a string slice

func (*DbfTable) HasField

func (dt *DbfTable) HasField(fieldName string) bool

HasField returns true if the table has a field with the given name If the field does not exist an error is returned.

func (*DbfTable) Int64FieldValueByName

func (dt *DbfTable) Int64FieldValueByName(row int, fieldName string) (value int64, err error)

Int64FieldValueByName returns the value of a field given row number and name provided as an int64

func (*DbfTable) NumberOfRecords

func (dt *DbfTable) NumberOfRecords() (ret int)

NumberOfRecords returns the number of records in the table

func (*DbfTable) RowIsDeleted

func (dt *DbfTable) RowIsDeleted(row int) bool

RowIsDeleted returns whether a row has marked as deleted

func (*DbfTable) SaveCSV

func (dt *DbfTable) SaveCSV(filename string, codepage string, comma rune, headers bool) (e error)

SaveCSV translate dbf to csv format

func (*DbfTable) SaveFile

func (dt *DbfTable) SaveFile(filename string) (err error)

SaveFile save file on disk

func (*DbfTable) SetFieldValue

func (dt *DbfTable) SetFieldValue(row int, fieldIndex int, value string) (err error)

SetFieldValue sets the value for the given row and field index as specified If the field index is invalid, or the value is incompatible with the field's type, an error is returned.

func (*DbfTable) SetFieldValueByName

func (dt *DbfTable) SetFieldValueByName(row int, fieldName string, value string) (err error)

SetFieldValueByName sets the value for the given row and field name as specified If the field name does not exist, or the value is incompatible with the field's type, an error is returned.

type FieldDescriptor

type FieldDescriptor struct {
	// contains filtered or unexported fields
}

FieldDescriptor describes one field/column in a DbfTable as per https://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm, Heading 1.2.

func (*FieldDescriptor) DecimalCount

func (fd *FieldDescriptor) DecimalCount() byte

DecimalCount returns the count of decimal places for the field

func (*FieldDescriptor) FieldType

func (fd *FieldDescriptor) FieldType() DbaseDataType

FieldType returns the type of data stored for the field as a DbaseDataType

func (*FieldDescriptor) Format

func (fd *FieldDescriptor) Format() string

Format returns the format of data stored for the field

func (*FieldDescriptor) Length

func (fd *FieldDescriptor) Length() byte

Length returns the fixedFieldLength of data stored for the field

func (*FieldDescriptor) Name

func (fd *FieldDescriptor) Name() string

Name returns the column name of the field

type Fltrs

type Fltrs struct {
	// contains filtered or unexported fields
}

func NewFltrs

func NewFltrs(cfg DbfFilters) *Fltrs

func (*Fltrs) Clear

func (f *Fltrs) Clear()

func (*Fltrs) Empty

func (f *Fltrs) Empty() bool

func (*Fltrs) Replace

func (f *Fltrs) Replace(key, value string) string

Jump to

Keyboard shortcuts

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