Categorygithub.com/Valentin-Kaiser/go-dbase
module
1.12.2
Repository: https://github.com/valentin-kaiser/go-dbase.git
Documentation: pkg.go.dev

# README

Microsoft Visual FoxPro / dbase library for Go

GoDoc License Linters CodeQL Examples Go Report

Golang package for reading and writing FoxPro dBase table and memo files.

This go-dbase package offers tools for managing dBase-format database files. It supports tailored I/O operations for Unix and Windows platforms, provides flexible data representations like maps, JSON, and Go structs, and ensures safe concurrent operations with built-in mutex locks.

The package facilitates defining, manipulating, and querying columns and rows in dBase tables, converting between dBase-specific data types and Go data types, and performing systematic error handling.

Typical use cases include data retrieval from legacy dBase systems, conversion of dBase files to modern formats, and building applications that interface with dBase databases.

Features

There are several similar packages but they are not suited for our use case, this package implements the following features:

Featurego-dbasego-dbfgo-foxpro-dbf
Encoding support ¹*
Read
Write
FPT (memo) file support
Struct, json, map conversion
IO efficiency ²
Full data type support
Exclusive Read/Write³
Search
Create new tables, including schema
Open database

¹ This package currently supports 13 of the 25 possible encodings, but a universal encoder will be provided for other code pages that can be extended at will. A list of supported encodings can be found here. The conversion in the go-foxpro-dbf package is extensible, but only Windows-1250 as default and the code page is not interpreted.

² IO efficiency is achieved by using one file handle for the DBF file and one file handle for the FPT file. This allows for non blocking IO and the ability to read files while other processes are accessing these. In addition, only the required positions in the file are read instead of keeping a copy of the entire file in memory.

³ The files can be opened completely exclusively and when writing a file, the data block to be written can be locked during the process. This is done to prevent other processes from writing the same data block. When reading, this is not a concern as the data is not changed.

Disclaimer: This library should never be used to develop new software solutions with dbase tables. The creation of new tables only serves to transfer old databases or to remove faulty data.

Supported column types

At this moment not all FoxPro column types are supported. When reading column values, the value returned by this package is always interface{}. If you need to cast this to the correct value, helper functions are provided.

The supported column types with their return Go types are:

Column TypeColumn Type NameGolang type
CCharacterstring
YCurrencyfloat64
BDoublefloat64
DDatetime.Time
TDateTimetime.Time
FFloatfloat64
IIntegerint32
LLogicalbool
MMemostring
MMemo (Binary)[]byte
NNumeric (0 decimals)int64
NNumeric (with decimals)float64
QVarbinary[]byte
VVarchar[]byte
WBlob[]byte
GGeneral[]byte
PPicture[]byte

You can find more information about dbase data types here: Microsoft Visual Studio Foxpro

If you need additional column types, feel free to open an issue and I will add them. Or you can add them yourself and create a pull request.

Supported encodings

The following encodings are supported by this package:

Code pagePlatformCode page identifier
437U.S. MS-DOSx01
850International MS-DOSx02
852Eastern European MS-DOSx64
865Nordic MS-DOSx66
866Russian MS-DOSx65
874Thai Windowsx7C
1250Central European WindowsxC8
1251Russian WindowsxC9
1252Windows ANSIx03
1253Greek WindowsxCB
1254Turkish WindowsxCA
1255Hebrew Windowsx7D
1256Arabic Windowsx7E

All encodings are converted from and to UTF-8.

If you need additional encodings, feel free to open an issue and I will add them. Or you can add them yourself and create a pull request.

Installation

go get github.com/Valentin-Kaiser/go-dbase@latest

Examples

These examples can be found in the examples directory:

# Packages

This go-dbase package offers tools for managing dBase-format database files.
No description provided by the author