Commit a6c4521f authored by Anders Mundt Due's avatar Anders Mundt Due
Browse files

sqlite1 typeup, requires gcc, untested..

parent bd9c99ab
// sqlite play
// https://www.thepolyglotdeveloper.com/2017/04/using-sqlite-database-golang-application/
package main
import (
"database/sql"
"fmt"
"strconv"
_ "github.com/mattn/go-sqlite3"
)
func main() {
database, _ := sql.Open("sqlite3", "./nraboy.db")
statement, _ := database.Prepare("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT)")
statement.Exec()
statement, _ := database.Prepare("INSERT INTO people (firstname, lastname) values (?, ?)")
statement.Exec("Nic", "Raboy")
rows, _ := database.Query("SELECT id, firstname, lastname FROM people")
var id int
var firstname string
var lastname string
for rows.Next() {
rows.Scan(&id, &firstname, &lastname)
fmt.Println(strconv.Itoa(id) + ": " + firstname + " " + lastname)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment