Skip to content

Repository files navigation

SimpleSqlite

GoDoc

An easy way to use a SQLite database from Go.

Online API Documentation

godoc.org

Features and limitations

  • Supports simple use of lists, hashmaps, sets and key/values.
  • Deals mainly with strings.
  • Uses the sqlite package.
  • Modeled after simplemaria.
  • The hash maps behaves like hash maps, but are not backed by actual hashmaps, unlike with simpleredis. This is for keeping compatibility with simpleredis. If performance when scaling up is a concern, simpleredis backed by redis might be a better choice.

Sample usage

package main
import (
"log""github.com/terminar/simplesqlite"
)
funcmain() {
// Check if the simplesqlite is workingiferr:=db.TestConnection(); err!=nil {
log.Fatalln("Could not open database file.")
}
// Create a new Filefile:=db.New()
// Use another filename//file := db.NewFile("sqlite.db")// Close the connection when the function returnsdeferfile.Close()
// Create a list named "greetings"list, err:=db.NewList(file, "greetings")
iferr!=nil {
log.Fatalln("Could not create list!")
}
// Add "hello" to the list, check if there are errorsiflist.Add("hello") !=nil {
log.Fatalln("Could not add an item to list!")
}
// Get the last item of the listifitem, err:=list.GetLast(); err!=nil {
log.Fatalln("Could not fetch the last item from the list!")
} else {
log.Println("The value of the stored item is:", item)
}
// Remove the listiflist.Remove() !=nil {
log.Fatalln("Could not remove the list!")
}
}

Testing

The tests will create a file (sqlite.db) for go test to work.

Version, license and author

About

🍡 Easy way to use a SQLite database from Go

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages