Documentation
¶
Overview ¶
Example ¶
db := New() defer db.Close() // Table with all data in memory already db.AddSlice("planets", []string{"name", "moons"}, [][]any{ {"Mercury", 0}, {"Venus", 0}, {"Earth", 1}, {"Mars", 2}, {"Jupiter", 80}, {"Saturn", 83}, {"Uranus", 27}, {"Neptune", 4}, }) // Table with all data from a channel stars := make(chan []any, 10) stars <- []any{"Alpha Centauri", "4"} stars <- []any{"Barnard's Star", "6"} stars <- []any{"Luhman 16", "6"} stars <- []any{"WISE 0855−0714", "7"} stars <- []any{"Wolf 359", "7"} db.AddChan("stars", []string{"name", "lightyears"}, stars) b := &bytes.Buffer{} err := db.WriteTo(b) _ = err // .. err = os.WriteFile("/tmp/universe.sqlite", b.Bytes(), 0600) _ = err // ..
Index ¶
Examples ¶
Constants ¶
const (
// database file page size
PageSize = 1 << 12
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func NewTmp ¶
Create a new db, with a tmp file stored in `dir`. See os.CreateTemp: if dir is empty this uses the default directory for temporary files. Unlinks the file on db.Close()
func (*DB) AddChan ¶
Add a new table with the given columns and rows. Table and column names should probably be lowercase simple strings. The number of items in every row is allowed to be shorter than the number of columns, according to the sqlite docs. What happens when there are more is not defined. Don't add the same table twice. Don't use this from multiple Go routines at the same time.
Supported Go datatypes:
- int
- float64
- string
- []byte
- nil
(yup, that's all for now)
This returns an error if any value is of an unsupported type. From then on any other call to AddChan() will return the same error, and so will WriteTo(). If there is an error we will drain the rows channel.