sqlhelp

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2025 License: MIT Imports: 9 Imported by: 0

README

SQLHELP

SQLHelp contains a set of generic database access functions.

LICENSE: MIT

Documentation

Overview

package sqlhelp provides a set of generic helper functions to work with SQL databases.

Index

Constants

This section is empty.

Variables

View Source
var Tag = "db"

Functions

func AddSearchPath

func AddSearchPath(dsn string, schema ...string) string

AddSearchPath adds a search path to postgres dsn string.

func Collect2

func Collect2[T any](seq iter.Seq2[T, error]) ([]T, error)

Collect2 collects all values from the iterator into a slice.

func Delete

func Delete(ctx context.Context, db sqlx.ExtContext, table string, where sq.Sqlizer) error

Delete deletes rows from the table matching where argument.

func DeleteByID

func DeleteByID(ctx context.Context, db sqlx.ExtContext, table string, id any) error

func Exists

func Exists(ctx context.Context, db sqlx.ExtContext, table string, where sq.Sqlizer) (bool, error)

func ExistsByID

func ExistsByID(ctx context.Context, db sqlx.ExtContext, table string, id any) (bool, error)

ExistsByID checks if a record with the given ID exists.

func Insert

func Insert[T any](ctx context.Context, db sqlx.ExtContext, table string, a T) (int64, error)

Insert is a generic function to insert a record into a table.

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

func JustErr(_ any, err error) error

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).

func Update

func Update[T any](ctx context.Context, db sqlx.ExtContext, table string, a *T, where sq.Sqlizer) (int64, error)

Update updates a record.

func UpdateByID

func UpdateByID[T any](ctx context.Context, db sqlx.ExtContext, table string, id any, a *T) (int64, error)

UpdateByID updates a record by ID.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL