Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/steadylearner/go-sqlite-example
- Owner: steadylearner
- Created: 2020-03-22T11:23:47.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T08:54:55.000Z (over 2 years ago)
- Last Synced: 2024-04-14T13:09:41.424Z (7 months ago)
- Topics: go, go-cli, go-cli-demo, go-cli-example, golang, golang-database, sqlite, steadylearner
- Language: Go
- Homepage: https://www.steadylearner.com/blog
- Size: 64.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
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
```