Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/steadylearner/go-sqlite-example

Golang CLI example with SQLite.
https://github.com/steadylearner/go-sqlite-example

go go-cli go-cli-demo go-cli-example golang golang-database sqlite steadylearner

Last synced: 5 days ago
JSON representation

Golang CLI example with SQLite.

Awesome Lists containing this project

README

        

# 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.

```console
$mv models && go build
```

## How to setup SQLite database

You can manually handle SQLite database. [Refer to the documenation for the SQLite CLI.](https://sqlite.org/cli.html)

```console
$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

```console
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.

```console
$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
```