GithubHelp home page GithubHelp logo

xbase's Introduction

xbase

Go Reference

A pure Go library for working with DBF files. The main purpose of the library is to organize export-import of data from files in DBF format.

The XBase type is used to work with DBF files. In addition to working with existing files, the XBase object allows you to create a new file of the given structure. Each XBase object can be linked with only one file.

Writing changes to a file

The XBase object contains data for one current record. Changing field values ​​does not cause an immediate change to the file. Changes are saved when the Save() method is called.

Deleting records

Deleting a record does not physically destroy it on disk. The deletion mark is put in a special field of the record.

Error processing

If an error occurs when calling the method, use the Error() method to get its value. By default, methods don't panic. This behavior can be changed. If you call SetPanic(true), then when an error occurs, the methods will cause a panic. Use whichever is more convenient for you.

Limitations

The following field types are supported: C, N, L, D. Memo fields are not supported. Index files are not supported.

Examples

File creation.

// Create file
db := xbase.New()
db.AddField("NAME", "C", 30)
db.AddField("SALARY", "N", 9, 2)
db.AddField("BDATE", "D")
db.SetCodePage(1251)
db.CreateFile("persons.dbf")
if db.Error() != nil {
    return db.Error()
}
defer db.CloseFile()

// Add record
db.Add()
db.SetFieldValue(1, "John Smith")
db.SetFieldValue(2, 1234.56)
db.SetFieldValue(3, time.Date(1998, 2, 20, 0, 0, 0, 0, time.UTC))
db.Save()
if db.Error() != nil {
    return db.Error()
}

Reading file.

db := xbase.New()
db.SetPanic(true)

db.OpenFile("persons.dbf", true)
defer db.CloseFile()

db.First()
for !db.EOF() {
    name := db.FieldValueAsString(1)
    salary := db.FieldValueAsFloat(2)
    bDate := db.FieldValueAsDate(3)
    fmt.Println(name, salary, bDate)
    db.Next()
}

File information.

db := xbase.New()
db.SetPanic(true)

db.OpenFile("persons.dbf", true)
defer db.CloseFile()

fmt.Println("Record count:", db.RecCount())
fmt.Println("Field count:", db.FieldCount())
fmt.Println("Code page:", db.CodePage())

// File structure
for n := 1; n <= db.FieldCount(); n++ {
    name, typ, length, dec := db.FieldInfo(n)
    fmt.Println(name, typ, length, dec)
}

License

Copyright (C) Sergey Volodeev. Released under MIT license.

xbase's People

Contributors

svolodeev avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

diassyes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.