Documentation
¶
Overview ¶
Package sqlp provides some convenience functions for using structs with the Go standard library's database/sql package.
The package matches struct field names to SQL query column names. A field can also specify a matching column with "sql" tag, if it's different from field name. Unexported fields or fields marked with `sql:"-"` are ignored, just like with "encoding/json" package.
For example: ToDo (See Readme)
Index ¶
- func Delete[T any](pk any, table string) error
- func DeleteR[T Repo](obj T) error
- func GetR[T Repo]() ([]T, error)
- func GetSingleWhereR[T Repo](where string, args ...any) (res T, err error)
- func GetWhereR[T Repo](where string, args ...any) ([]T, error)
- func Insert[T any](obj T, table string) (int, error)
- func InsertR[T Repo](obj T) (int, error)
- func Query[T any](query string, args ...any) (results []T, err error)
- func QueryBasic[T string | int | int64 | float32 | float64](query string, args ...any) (results []T, err error)
- func QueryBasicRow[T string | int | int64 | float32 | float64](query string, args ...any) (result T, err error)
- func QueryRow[T any](query string, args ...any) (result T, err error)
- func SetDatabase(sqldb *sql.DB)
- func ToSnakeCase(src string) string
- func Update[T any](obj T, table string) error
- func UpdateR[T Repo](obj T) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSingleWhereR ¶ added in v0.1.21
func Insert ¶
Insert inserts the given object into the table and returns the last inserted id. Autogenerated fields can be tagged with `sql-auto:""` (AutoGenTagName) in order for them to be ignored during insert. Deprecated
func QueryBasic ¶
func QueryBasicRow ¶ added in v0.1.4
func SetDatabase ¶
SetDatabase sets the global database handle to be used by the Query function.
func ToSnakeCase ¶
ToSnakeCase converts a string to snake case, words separated with underscores. It's intended to be used with NameMapper to map struct field names to snake case database fields.
Types ¶
This section is empty.