Documentation
¶
Overview ¶
package sqlhelp provides a set of generic helper functions to work with SQL databases.
Index ¶
- Variables
- func AddSearchPath(dsn string, schema ...string) string
- func Collect2[T any](seq iter.Seq2[T, error]) ([]T, error)
- func Delete(ctx context.Context, db sqlx.ExtContext, table string, where sq.Sqlizer) error
- func DeleteByID(ctx context.Context, db sqlx.ExtContext, table string, id any) error
- func Exists(ctx context.Context, db sqlx.ExtContext, table string, where sq.Sqlizer) (bool, error)
- func ExistsByID(ctx context.Context, db sqlx.ExtContext, table string, id any) (bool, error)
- func Insert[T any](ctx context.Context, db sqlx.ExtContext, table string, a T) (int64, error)
- func InsertFull[T any](ctx context.Context, db sqlx.ExtContext, omitEmpty bool, table string, a T) (int64, error)
- func InsertPSQL[T any](ctx context.Context, db sqlx.ExtContext, table string, idCol string, a T) (int64, error)
- func InsertPSQLFull[T any](ctx context.Context, db sqlx.ExtContext, omitEmpty bool, table string, ...) (int64, error)
- func JustErr(_ any, err error) error
- func Select[T any](ctx context.Context, db sqlx.ExtContext, table string, where sq.Sqlizer) (iter.Seq2[T, error], error)
- func SelectRow[T any](ctx context.Context, db sqlx.ExtContext, table string, where sq.Sqlizer) (*T, error)
- func SelectRowByID[T any](ctx context.Context, db sqlx.ExtContext, table string, id int64) (*T, error)
- func SelectRowByIntegrationID[T any](ctx context.Context, db sqlx.ExtContext, table string, integrationID string) (*T, error)
- func Update[T any](ctx context.Context, db sqlx.ExtContext, table string, a *T, where sq.Sqlizer) (int64, error)
- func UpdateByID[T any](ctx context.Context, db sqlx.ExtContext, table string, id any, a *T) (int64, error)
Constants ¶
This section is empty.
Variables ¶
var Tag = "db"
Functions ¶
func AddSearchPath ¶
AddSearchPath adds a search path to postgres dsn string.
func DeleteByID ¶
func ExistsByID ¶
ExistsByID checks if a record with the given ID exists.
func InsertFull ¶ added in v0.1.0
func InsertFull[T any](ctx context.Context, db sqlx.ExtContext, omitEmpty bool, table string, a T) (int64, error)
InsertFull is a generic function to insert a record into a table, if omitEmpty is specified, fields with empty values will be omitted from the insert statement.
func InsertPSQL ¶
func InsertPSQL[T any](ctx context.Context, db sqlx.ExtContext, table string, idCol string, a T) (int64, error)
InsertPSQL is a Postgres flavour of Insert.
func InsertPSQLFull ¶ added in v0.1.0
func InsertPSQLFull[T any](ctx context.Context, db sqlx.ExtContext, omitEmpty bool, table string, idCol string, a T) (int64, error)
InsertPSQLFull is a Postgres flavour of InsertFull.
func JustErr ¶
JustErr is a helper function to return just an error from a function that returns two values, where the first one is not needed and the second is an error.
func Select ¶
func Select[T any](ctx context.Context, db sqlx.ExtContext, table string, where sq.Sqlizer) (iter.Seq2[T, error], error)
Select selects rows from a table.
func SelectRow ¶
func SelectRow[T any](ctx context.Context, db sqlx.ExtContext, table string, where sq.Sqlizer) (*T, error)
SelectRow selects a row from a table.
func SelectRowByID ¶
func SelectRowByID[T any](ctx context.Context, db sqlx.ExtContext, table string, id int64) (*T, error)
SelectRowByID selects a row by ID (assuming that ID column is named "id").
func SelectRowByIntegrationID ¶
func SelectRowByIntegrationID[T any](ctx context.Context, db sqlx.ExtContext, table string, integrationID string) (*T, error)
SelectRowByIntegrationID selects a row by integration_id (assuming that there is an "integration_id" column).
Types ¶
This section is empty.
Directories
¶
Path | Synopsis |
---|---|
package sqlhelptest contains helper functions for testing database functions.
|
package sqlhelptest contains helper functions for testing database functions. |