Skip to content

Commit

Permalink
Change library name to Scany (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgysavva authored Jul 1, 2020
1 parent 031e107 commit 6deceb3
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 58 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# dbscan
# Scany

[![GoDoc](https://img.shields.io/badge/pkg.go.dev-doc-blue)](http://pkg.go.dev/github.com/georgysavva/dbscan)
[![Build Status](https://travis-ci.com/georgysavva/dbscan.svg?branch=master)](https://travis-ci.com/georgysavva/dbscan)
[![codecov](https://codecov.io/gh/georgysavva/dbscan/branch/master/graph/badge.svg)](https://codecov.io/gh/georgysavva/dbscan)
[![Go Report Card](https://goreportcard.com/badge/github.com/georgysavva/dbscan)](https://goreportcard.com/report/github.com/georgysavva/dbscan)
[![GoDoc](https://img.shields.io/badge/pkg.go.dev-doc-blue)](http://pkg.go.dev/github.com/georgysavva/scany)
[![Build Status](https://travis-ci.com/georgysavva/scany.svg?branch=master)](https://travis-ci.com/georgysavva/scany)
[![codecov](https://codecov.io/gh/georgysavva/scany/branch/master/graph/badge.svg)](https://codecov.io/gh/georgysavva/scany)
[![Go Report Card](https://goreportcard.com/badge/github.com/georgysavva/scany)](https://goreportcard.com/report/github.com/georgysavva/scany)

Library for scanning data from database into Go structs and more.

Expand All @@ -14,7 +14,7 @@ It provides great control and efficiency in your queries, but here is a problem:
you need to manually iterate over database rows and scan data from all columns into a corresponding destination.
It can be error prone, verbose and just tedious.

`dbscan` library aims to solve this problem,
`Scany` library aims to solve this problem,
it allows developers to scan complex data from database into Go structs and other composite types
with just one function call and don't bother with rows iteration.
It's not limited to any specific database, it works with standard `database/sql` library,
Expand Down Expand Up @@ -69,14 +69,14 @@ if err := dbscan.ScanAll(&users, rows); err != nil {
## Install

```
go get github.com/georgysavva/dbscan
go get github.com/georgysavva/scany
```

## Tests

The only thing you need to run tests locally is an internet connection,
it's required to download and cache the database binary.
Just type `go test ./...` inside dbscan root directory and let the code to the rest.
Just type `go test ./...` inside scany root directory and let the code to the rest.

## what it is not

Expand All @@ -90,7 +90,7 @@ Customize

## Supported Go versions

dbscan supports Go 1.13 and higher.
Scany supports Go 1.13 and higher.


## Versions policy
Expand Down
22 changes: 11 additions & 11 deletions dbscan/dbscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

dbscan2 "github.com/georgysavva/dbscan/dbscan"
"github.com/georgysavva/scany/dbscan"
)

var (
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestScanAll(t *testing.T) {
t.Parallel()
rows := queryRows(t, tc.query)
dst := allocateDestination(tc.expected)
err := dbscan2.ScanAll(dst, rows)
err := dbscan.ScanAll(dst, rows)
require.NoError(t, err)
assertDestinationEqual(t, tc.expected, dst)
})
Expand All @@ -170,7 +170,7 @@ func TestScanAll_nonEmptySlice_resetsDestinationSlice(t *testing.T) {
expected := []*model{{Foo: "foo val"}, {Foo: "foo val 2"}, {Foo: "foo val 3"}}

got := []*model{{Foo: "junk data"}, {Foo: "junk data 2"}}
err := dbscan2.ScanAll(&got, rows)
err := dbscan.ScanAll(&got, rows)
require.NoError(t, err)

assert.Equal(t, expected, got)
Expand All @@ -190,7 +190,7 @@ func TestScanAll_nonSliceDestination_returnsErr(t *testing.T) {
}{}
expectedErr := "dbscan: destination must be a slice, got: struct { Foo string }"

err := dbscan2.ScanAll(dst, rows)
err := dbscan.ScanAll(dst, rows)

assert.EqualError(t, err, expectedErr)
}
Expand All @@ -207,7 +207,7 @@ func TestScanAll_sliceByPointerToPointerDestination_returnsErr(t *testing.T) {
dst := new(*[]struct{ Foo string })
expectedErr := "dbscan: destination must be a slice, got: *[]struct { Foo string }"

err := dbscan2.ScanAll(dst, rows)
err := dbscan.ScanAll(dst, rows)

assert.EqualError(t, err, expectedErr)
}
Expand All @@ -226,7 +226,7 @@ func TestScanAll_closedRows(t *testing.T) {
requireNoRowsErrorsAndClose(t, rows)

var got []struct{ Foo string }
err := dbscan2.ScanAll(&got, rows)
err := dbscan.ScanAll(&got, rows)
require.NoError(t, err)

assert.Len(t, got, 0)
Expand All @@ -245,7 +245,7 @@ func TestScanOne(t *testing.T) {
expected := model{Foo: "foo val", Bar: "bar val"}

got := model{}
err := dbscan2.ScanOne(&got, rows)
err := dbscan.ScanOne(&got, rows)
require.NoError(t, err)

assert.Equal(t, expected, got)
Expand All @@ -259,8 +259,8 @@ func TestScanOne_zeroRows_returnsNotFoundErr(t *testing.T) {
rows := queryRows(t, query)

dst := &struct{ Foo string }{}
err := dbscan2.ScanOne(dst, rows)
isNotFound := dbscan2.NotFound(err)
err := dbscan.ScanOne(dst, rows)
isNotFound := dbscan.NotFound(err)

assert.True(t, isNotFound)
}
Expand All @@ -277,7 +277,7 @@ func TestScanOne_multipleRows_returnsErr(t *testing.T) {
expectedErr := "dbscan: expected 1 row, got: 3"

dst := &struct{ Foo string }{}
err := dbscan2.ScanOne(dst, rows)
err := dbscan.ScanOne(dst, rows)

assert.EqualError(t, err, expectedErr)
}
Expand All @@ -297,7 +297,7 @@ func TestScanRow(t *testing.T) {
expected := model{Foo: "foo val", Bar: "bar val"}

var got model
err := dbscan2.ScanRow(&got, rows)
err := dbscan.ScanRow(&got, rows)
require.NoError(t, err)
requireNoRowsErrorsAndClose(t, rows)

Expand Down
8 changes: 4 additions & 4 deletions dbscan/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
/*
dbscan works with abstract Rows and doesn't depend on any specific database or library.
If a type implements Rows interface it can leverage full functional of this package.
Subpackages github.com/georgysavva/dbscan/sqlscan
and github.com/georgysavva/dbscan/pgxscan are wrappers around this package,
Subpackages github.com/georgysavva/scany/sqlscan
and github.com/georgysavva/scany/pgxscan are wrappers around this package,
they contain functions and adapters tailored to database/sql
and github.com/jackc/pgx/v4 libraries correspondingly. sqlscan and pgxscan proxy all calls to dbscan internally.
dbscan does all the logic, but generally, it shouldn't be imported by the application code directly.
If you are working with database/sql - use github.com/georgysavva/dbscan/sqlscan package.
If you are working with database/sql - use github.com/georgysavva/scany/sqlscan package.
If you are working with pgx - use github.com/georgysavva/dbscan/pgxscan package.
If you are working with pgx - use github.com/georgysavva/scany/pgxscan package.
Scanning into struct
Expand Down
18 changes: 9 additions & 9 deletions dbscan/example_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dbscan_test

import (
dbscan2 "github.com/georgysavva/dbscan/dbscan"
"github.com/georgysavva/scany/dbscan"
)

func ExampleScanAll() {
Expand All @@ -13,10 +13,10 @@ func ExampleScanAll() {
}

// Query rows from the database that implement dbscan.Rows interface.
var rows dbscan2.Rows
var rows dbscan.Rows

var users []*User
if err := dbscan2.ScanAll(&users, rows); err != nil {
if err := dbscan.ScanAll(&users, rows); err != nil {
// Handle rows processing error
}
// users variable now contains data from all rows.
Expand All @@ -31,10 +31,10 @@ func ExampleScanOne() {
}

// Query rows from the database that implement dbscan.Rows interface.
var rows dbscan2.Rows
var rows dbscan.Rows

var user User
if err := dbscan2.ScanOne(&user, rows); err != nil {
if err := dbscan.ScanOne(&user, rows); err != nil {
// Handle rows processing error.
}
// user variable now contains data from the single row.
Expand All @@ -49,11 +49,11 @@ func ExampleRowScanner() {
}

// Query rows from the database that implement dbscan.Rows interface.
var rows dbscan2.Rows
var rows dbscan.Rows

// Make sure rows are always closed.
defer rows.Close()
rs := dbscan2.NewRowScanner(rows)
rs := dbscan.NewRowScanner(rows)
for rows.Next() {
var user User
if err := rs.Scan(&user); err != nil {
Expand All @@ -78,13 +78,13 @@ func ExampleScanRow() {
}

// Query rows from the database that implement dbscan.Rows interface.
var rows dbscan2.Rows
var rows dbscan.Rows

// Make sure rows are always closed.
defer rows.Close()
for rows.Next() {
var user User
if err := dbscan2.ScanRow(&user, rows); err != nil {
if err := dbscan.ScanRow(&user, rows); err != nil {
// Handle row scanning error.
}
// user variable now contains data from the current row.
Expand Down
12 changes: 6 additions & 6 deletions dbscan/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

dbscan2 "github.com/georgysavva/dbscan/dbscan"
"github.com/georgysavva/dbscan/pgxscan"
"github.com/georgysavva/scany/dbscan"
"github.com/georgysavva/scany/pgxscan"
)

func makeStrPtr(v string) *string { return &v }

func queryRows(t *testing.T, query string) dbscan2.Rows {
func queryRows(t *testing.T, query string) dbscan.Rows {
t.Helper()
pgxRows, err := testDB.Query(ctx, query)
require.NoError(t, err)
rows := pgxscan.NewRowsAdapter(pgxRows)
return rows
}

func scan(t *testing.T, dst interface{}, rows dbscan2.Rows) error {
func scan(t *testing.T, dst interface{}, rows dbscan.Rows) error {
defer rows.Close()
rs := dbscan2.NewRowScanner(rows)
rs := dbscan.NewRowScanner(rows)
rows.Next()
if err := rs.Scan(dst); err != nil {
return err
Expand All @@ -32,7 +32,7 @@ func scan(t *testing.T, dst interface{}, rows dbscan2.Rows) error {
return nil
}

func requireNoRowsErrorsAndClose(t *testing.T, rows dbscan2.Rows) {
func requireNoRowsErrorsAndClose(t *testing.T, rows dbscan.Rows) {
t.Helper()
require.NoError(t, rows.Err())
require.NoError(t, rows.Close())
Expand Down
10 changes: 5 additions & 5 deletions dbscan/rowscanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

dbscan2 "github.com/georgysavva/dbscan/dbscan"
"github.com/georgysavva/dbscan/internal/mocks"
"github.com/georgysavva/scany/dbscan"
"github.com/georgysavva/scany/internal/mocks"
)

type FooNested struct {
Expand Down Expand Up @@ -660,12 +660,12 @@ func TestRowScanner_Scan_startCalledExactlyOnce(t *testing.T) {
rows := queryRows(t, query)
defer rows.Close()
mockStart := &mocks.StartScannerFunc{}
rs := dbscan2.NewRowScannerWithStart(rows, mockStart.Execute)
rs := dbscan.NewRowScannerWithStart(rows, mockStart.Execute)
mockStart.On("Execute", rs, mock.AnythingOfType("reflect.Value")).Return(nil).Run(func(args mock.Arguments) {
rs := args.Get(0).(*dbscan2.RowScanner)
rs := args.Get(0).(*dbscan.RowScanner)
columns := []string{"foo"}
columnToFieldIndex := map[string][]int{"foo": {0}}
dbscan2.PatchRowScanner(rs, columns, columnToFieldIndex, nil /* mapElementType */)
dbscan.PatchRowScanner(rs, columns, columnToFieldIndex, nil /* mapElementType */)
})
for rows.Next() {
dst := &struct {
Expand Down
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ It provides great control and efficiency in your queries, but here is a problem:
you need to manually iterate over database rows and scan data from all columns into a corresponding destination.
It can be error prone, verbose and just tedious.
dbscan library aims to solve this problem,
scany library aims to solve this problem,
it allows developers to scan complex data from database into Go structs and other composite types
with just one function call and don't bother with rows iteration.
It's not limited to any specific database, it works with standard database/sql library,
Expand All @@ -14,4 +14,4 @@ It also supports pgx library specific for PostgreSQL.
This library consists of the following packages: sqlscan, pgxscan and dbscan.
*/
package dbscan
package scany
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/georgysavva/dbscan
module github.com/georgysavva/scany

go 1.14

Expand Down
6 changes: 3 additions & 3 deletions internal/mocks/startScannerFunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (

mock "github.com/stretchr/testify/mock"

dbscan2 "github.com/georgysavva/dbscan/dbscan"
dbscan "github.com/georgysavva/scany/dbscan"
)

type StartScannerFunc struct {
mock.Mock
}

func (_m *StartScannerFunc) Execute(rs *dbscan2.RowScanner, dstValue reflect.Value) error {
func (_m *StartScannerFunc) Execute(rs *dbscan.RowScanner, dstValue reflect.Value) error {
ret := _m.Called(rs, dstValue)

var r0 error
if rf, ok := ret.Get(0).(func(*dbscan2.RowScanner, reflect.Value) error); ok {
if rf, ok := ret.Get(0).(func(*dbscan.RowScanner, reflect.Value) error); ok {
r0 = rf(rs, dstValue)
} else {
r0 = ret.Error(0)
Expand Down
2 changes: 1 addition & 1 deletion pgxscan/doc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Package pgxscan improves scanning abilities of pgx library.
/*
pgxscan allows scanning complex data into Go structs and other composite types,
when working with pgx library. Essentially, it is a wrapper around github.com/georgysavva/dbscan package.
when working with pgx library. Essentially, it is a wrapper around github.com/georgysavva/scany/dbscan package.
It contains adapters and proxy functions that are meant to connect github.com/jackc/pgx/v4
with dbscan functionality. pgxscan mirrors all capabilities provided by dbscan.
See dbscan docs to get familiar with all concepts and features.
Expand Down
2 changes: 1 addition & 1 deletion pgxscan/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pgxscan_test
import (
"github.com/jackc/pgx/v4/pgxpool"

"github.com/georgysavva/dbscan/pgxscan"
"github.com/georgysavva/scany/pgxscan"
)

func ExampleQueryAll() {
Expand Down
2 changes: 1 addition & 1 deletion pgxscan/pgxscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/jackc/pgx/v4/pgxpool"
"github.com/pkg/errors"

"github.com/georgysavva/dbscan/dbscan"
"github.com/georgysavva/scany/dbscan"
)

// Querier is something that pgxscan can query and get the pgx.Rows from.
Expand Down
2 changes: 1 addition & 1 deletion pgxscan/pgxscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/georgysavva/dbscan/pgxscan"
"github.com/georgysavva/scany/pgxscan"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion sqlscan/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
sqlscan allows scanning complex data into Go structs and other composite types,
when working with database/sql library. Essentially,
it is a wrapper around github.com/georgysavva/dbscan package.
it is a wrapper around github.com/georgysavva/scany/dbscan package.
It contains adapters and proxy functions that are meant to connect database/sql
with dbscan functionality. sqlscan mirrors all capabilities provided by dbscan.
See dbscan docs to get familiar with all concepts and features.
Expand Down
2 changes: 1 addition & 1 deletion sqlscan/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sqlscan_test
import (
"database/sql"

"github.com/georgysavva/dbscan/sqlscan"
"github.com/georgysavva/scany/sqlscan"
)

func ExampleQueryAll() {
Expand Down
2 changes: 1 addition & 1 deletion sqlscan/sqlscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/pkg/errors"

"github.com/georgysavva/dbscan/dbscan"
"github.com/georgysavva/scany/dbscan"
)

// Querier is something that sqlscan can query and get the *sql.Rows from.
Expand Down
Loading

0 comments on commit 6deceb3

Please sign in to comment.