scan alternatives and similar packages
Based on the "Utilities" category.
Alternatively, view scan alternatives based on common mentions on social networks and blogs.
-
项目文档
基于vite+vue3+gin搭建的开发基础平台(支持TS,JS混用),集成jwt鉴权,权限管理,动态路由,显隐可控组件,分页封装,多点登录拦截,资源权限,上传下载,代码生成器,表单生成器,chatGPT自动查表等开发必备功能。 -
excelize
Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets -
xlsx
(No longer maintained!) Go (golang) library for reading and writing XLSX files. -
godotenv
A Go port of Ruby's dotenv library (Loads environment variables from .env files) -
go-funk
A modern Go utility library which provides helpers (map, find, contains, filter, ...) -
gorequest
GoRequest -- Simplified HTTP client ( inspired by nodejs SuperAgent ) -
Kopia
Cross-platform backup tool for Windows, macOS & Linux with fast, incremental backups, client-side end-to-end encryption, compression and data deduplication. CLI and GUI included. -
goreporter
A Golang tool that does static analysis, unit testing, code review and generate code quality report. -
gojson
Automatically generate Go (golang) struct definitions from example JSON -
create-go-app
✨ Create a new production-ready project with backend, frontend and deploy automation by running one CLI command! -
spinner
Go (golang) package with 90 configurable terminal spinner/progress indicators. -
filetype
Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature -
EaseProbe
A simple, standalone, and lightweight tool that can do health/status checking, written in Go. -
mole
CLI application to create ssh tunnels focused on resiliency and user experience. -
boilr
:zap: boilerplate template manager that generates files or directories from template repositories -
beaver
💨 A real time messaging system to build a scalable in-app notifications, multiplayer games, chat apps in web and mobile apps. -
mimetype
A fast Golang library for media type and file extension detection, based on magic numbers -
go-underscore
Helpfully Functional Go - A useful collection of Go utilities. Designed for programmer happiness. -
JobRunner
Framework for performing work asynchronously, outside of the request flow
Static code analysis for 29 languages.
Do you think we are missing an alternative of scan or a related project?
Popular Comparisons
README
Scan
Scan standard lib database rows directly to structs or slices. For the most comprehensive and up-to-date docs see the godoc
Examples
Multiple Rows
db, err := sql.Open("sqlite3", "database.sqlite")
rows, err := db.Query("SELECT * FROM persons")
var persons []Person
err := scan.Rows(&persons, rows)
fmt.Printf("%#v", persons)
// []Person{
// {ID: 1, Name: "brett"},
// {ID: 2, Name: "fred"},
// {ID: 3, Name: "stacy"},
// }
Multiple rows of primitive type
rows, err := db.Query("SELECT name FROM persons")
var names []string
err := scan.Rows(&names, rows)
fmt.Printf("%#v", names)
// []string{
// "brett",
// "fred",
// "stacy",
// }
Single row
rows, err := db.Query("SELECT * FROM persons where name = 'brett' LIMIT 1")
var person Person
err := scan.Row(&person, rows)
fmt.Printf("%#v", person)
// Person{ ID: 1, Name: "brett" }
Scalar value
rows, err := db.Query("SELECT age FROM persons where name = 'brett' LIMIT 1")
var age int8
err := scan.Row(&age, rows)
fmt.Printf("%d", age)
// 100
Nested Struct Fields (as of v2.0.0)
rows, err := db.Query(`
SELECT person.id,person.name,company.name FROM person
JOIN company on company.id = person.company_id
LIMIT 1
`)
var person struct {
ID int `db:"person.id"`
Name string `db:"person.name"`
Company struct {
Name string `db:"company.name"`
}
}
err = scan.RowStrict(&person, rows)
err = json.NewEncoder(os.Stdout).Encode(&person)
// Output:
// {"ID":1,"Name":"brett","Company":{"Name":"costco"}}
Strict Scanning
Both Rows
and Row
have strict alternatives to allow scanning to structs strictly based on their db
tag.
To avoid unwanted behavior you can use RowsStrict
or RowStrict
to scan without using field names.
Any fields not tagged with the db
tag will be ignored even if columns are found that match the field names.
Columns
Columns
scans a struct and returns a string slice of the assumed column names based on the db
tag or the struct field name respectively. To avoid assumptions, use ColumnsStrict
which will only return the fields tagged with the db
tag. Both Columns
and ColumnsStrict
are variadic. They both accept a string slice of column names to exclude from the list. It is recommended that you cache this slice.
package main
type User struct {
ID int64
Name string
Age int
BirthDate string `db:"bday"`
Zipcode string `db:"-"`
Store struct {
ID int
// ...
}
}
var nobody = new(User)
var userInsertCols = scan.Columns(nobody, "ID")
// []string{ "Name", "Age", "bday" }
var userSelectCols = scan.Columns(nobody)
// []string{ "ID", "Name", "Age", "bday" }
Values
Values
scans a struct and returns the values associated with the provided columns. Values uses a sync.Map
to cache fields of structs to greatly improve the performance of scanning types. The first time a struct is scanned it's exported fields locations are cached. When later retrieving values from the same struct it should be much faster. See Benchmarks below.
user := &User{
ID: 1,
Name: "Brett",
Age: 100,
}
vals := scan.Values([]string{"ID", "Name"}, user)
// []interface{}{ 1, "Brett" }
I find that the usefulness of both Values and Columns lies within using a library such as sq.
sq.Insert(userCols...).
Into("users").
Values(scan.Values(userCols, &user)...)
Configuration
AutoClose: Automatically call rows.Close()
after scan completes (default true)
Why
While many other projects support similar features (i.e. sqlx) scan allows you to use any database lib such as the stdlib or squirrel to write fluent SQL statements and pass the resulting rows
to scan
for scanning.
Benchmarks
λ go test -bench=. -benchtime=10s ./...
goos: linux
goarch: amd64
pkg: github.com/blockloop/scan
BenchmarkColumnsLargeStruct-8 50000000 272 ns/op
BenchmarkValuesLargeStruct-8 2000000 8611 ns/op
BenchmarkScanRowOneField-8 2000000 8528 ns/op
BenchmarkScanRowFiveFields-8 1000000 12234 ns/op
BenchmarkScanTenRowsOneField-8 1000000 16802 ns/op
BenchmarkScanTenRowsTenFields-8 100000 104587 ns/op
PASS
ok github.com/blockloop/scan 116.055s