Documentation ¶
Index ¶
Constants ¶
View Source
const ( Columns parameterType = iota Values )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SQLDialect ¶
type SQLDialect int
SQLDialect denotes the different dialects which define placeholders differently.
const ( MySQL SQLDialect = iota PostgreSQL Oracle SQLite ODBC MariaDB )
type SQLRepository ¶
type SQLRepository[T any] struct { // contains filtered or unexported fields }
SQLRepository handles CRUD queries to a table in an SQL database. T is the struct type that will be mapped against the table rows.
func New ¶
func New[T any](db *sqlx.DB, config SQLRepositoryConfig) (*SQLRepository[T], error)
New creates and returns a new SQLRepository.
func (SQLRepository[T]) Create ¶
func (r SQLRepository[T]) Create(model T) error
Create inserts the values in model into a new row in the table.
func (SQLRepository[T]) Delete ¶
func (r SQLRepository[T]) Delete(id any) error
Delete removes the row whose ID matches id.
func (SQLRepository[T]) Read ¶
func (r SQLRepository[T]) Read(id any) (*T, error)
Read fetches a row from the table whose ID matches id.
func (SQLRepository[T]) ReadAll ¶
func (r SQLRepository[T]) ReadAll() ([]T, error)
ReadAll fetches all rows from the table.
func (SQLRepository[T]) Update ¶
func (r SQLRepository[T]) Update(id any, model T) error
Update updates the row in the table, whose ID matches id, with the data found in model.
type SQLRepositoryConfig ¶
type SQLRepositoryConfig struct {
// contains filtered or unexported fields
}
type StructParser ¶
type StructParser interface { // ParseFieldNames TODO: write docs ParseFieldNames(typ reflect.Type) ([]string, error) // ParseProperties reads the struct type T and returns its fields // and values as two slices. The slices are guaranteed to match indices. // // Separating the properties into fields and values slices is required // when formatting and preparing statements. // // Specifying idFieldName filters out that field in the resulting slices, // which is necessary in INSERTS and UPDATES. ParseProperties(model any, idFieldName string) ([]string, []any, error) }
Click to show internal directories.
Click to hide internal directories.