Home

Awesome

SimpleSqlite

GoDoc

An easy way to use a SQLite database from Go.

Online API Documentation

godoc.org

Features and limitations

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