Skip to content

Commit

Permalink
Add quickstart to the readme (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ders authored May 20, 2022
1 parent 24d4e3c commit ac9c71d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.13
- image: cimg/go:1.17

steps:
- checkout
Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@

This library is actively maintained. Contributions are welcome.

## Quickstart

This is what application code typically looks like. The example here is for fetching multiple database rows into a
slice of structs. Note that the order of exported struct fields needs to match the columns in the SQL result set.

```go
type exam struct {
ID int64
Name string
Score float64
}

db, err := sql.Open(...)
if err != nil {
...
}

var scores []exam
err = sx.Do(db, func(tx *sx.Tx) {
tx.MustQuery("SELECT id, name, score FROM exam_scores ORDER BY name").Each(func(r *sx.Rows) {
var e exam
r.MustScans(&e)
scores = append(scores, e)
})
})
if err != nil {
...
}
```

For more in-depth details, please keep reading!

## Goals

The primary goal of **go-sx** is to eliminate boilerplate code. Specifically, **go-sx** attempts to address the following pain points:
Expand Down

0 comments on commit ac9c71d

Please sign in to comment.