Skip to content

steadylearner/go-SQLite-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test SQLite with Go

Use this CLI example to learn how to use Golang with SQLite. Modify and reuse some parts of this to make a web app etc.

How to prepare the project before you test it

First, help the models packages ready to work with main package.

$mv models && go build

How to setup SQLite database

You can manually handle SQLite database. Refer to the documenation for the SQLite CLI.

$touch users.db && sqlite3 users.db
$CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL UNIQUE)

You can also uncomment the code similar to this in main.go

db.Exec("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL UNIQUE)")

How to test it

Use one of commands below to test CRULD(Create, Read, Update, List, Delete) users.

$go run main.go -action=create
$go run main.go -action=get
$go run main.go -action=update
$go run main.go -action=list
$go run main.go -action=delete