Skip to content

Navigation Menu

Sign in
Sign up

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"
)
func main() {
 // Check if the simplesqlite is working
 if err := db.TestConnection(); err != nil {
 log.Fatalln("Could not open database file.")
 }
 // Create a new File
 file := db.New()
 // Use another filename
 //file := db.NewFile("sqlite.db")
 // Close the connection when the function returns
 defer file.Close()
 // Create a list named "greetings"
 list, err := db.NewList(file, "greetings")
 if err != nil {
 log.Fatalln("Could not create list!")
 }
 // Add "hello" to the list, check if there are errors
 if list.Add("hello") != nil {
 log.Fatalln("Could not add an item to list!")
 }
 // Get the last item of the list
 if item, 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 list
 if list.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

AltStyle によって変換されたページ (->オリジナル) /