db access wrapper for Go project
Why don't you want to leak sql.ErrNoRows outside? I find it quite explicit.

It seems that you are wrapping your errors with some context: there is a very nice package for this: https://godoc.org/github.com/pkg/errors

Using it, your code would look like this:



package db_access

import (
    "database/sql"
    "fmt"
    "my_database"
)

type TheType struct {
    Name string 
}

// uses named returns
func LoadTheTypeFromDb(db *sql.DB, id uint) (row TheType, err error) {
    query := fmt.Sprintf(
        "SELECT %s FROM %s WHERE %s = ?",
        my_database.NAME,
        my_database.TABLE,
        my_database.ID,
    )

    err = db.QueryRow(query, id).Scan(&amp;row.Name)
    return
}


And your "my_database"

package my_database

import (
    "database/sql"
    _ "github.com/go-sql-driver/mysql"
    "github.com/pkg/errors"
)

func GetDatabaseInstance(connectionString string) (db *sql.DB, err error) {
    db, err = sql.Open("mysql", connectionString)

    if err != nil {
        err = errors.Wrap("open failed", err)
        return
    }

    err = db.Ping()
    // if err is nil, errors.Wrap returns nil
    err = errors.Wrap("ping failed", err)

    return
}


Your custom error file should not be needed anymore!