boilerplate

package module
v0.0.0-...-b7ff540 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverSqlite   = "sqlite"
	DriverPostgres = "postgres"
)

Variables

This section is empty.

Functions

func Connect

func Connect(driver Driver, connString string) (*sqlx.DB, error)

func Exec

func Exec(db *sqlx.DB, query string, args ...any) (err error)

func Get

func Get[T any](db *sqlx.DB, query string, args ...any) (t T, err error)

func NamedExec

func NamedExec(db *sqlx.DB, dest any, query string, args ...any) error

func NamedExecReturning

func NamedExecReturning(db *sqlx.DB, dest any, query string, args ...any) error

func Select

func Select[T any](db *sqlx.DB, query string, args ...any) (t T, err error)

Types

type Driver

type Driver string

type GenerateQueriesOptions

type GenerateQueriesOptions struct {
	TableName          string
	Model              any
	AutoGeneratingCols []string
	PrimaryKeys        []string
	Driver             Driver
}

type GeneratedQueries

type GeneratedQueries struct {
	CreateTable string
	DropTable   string
	Select      string
	Insert      string
	Update      string
	Upsert      string
	Delete      string
}

func GenerateQueries

func GenerateQueries(opts GenerateQueriesOptions) (queries GeneratedQueries)

Uses the struct fields 'db' and 'dbtype' to auto generate most queries.

`AutoGeneratingCols` is a list of col names that are auto generated on INSERT or UPSERT, like 'BIGSERIAL', etc. These will be excluded from INSERT statements to let the database auto generate.

`PrimaryKeys` is a list of col names that are used to control what is done on an UPDATE query.

type IntSlice

type IntSlice []int

func (*IntSlice) Scan

func (s *IntSlice) Scan(src any) error

func (IntSlice) Value

func (s IntSlice) Value() (driver.Value, error)

type JsonObject

type JsonObject map[string]any

func (*JsonObject) Scan

func (obj *JsonObject) Scan(src any) error

func (JsonObject) Value

func (obj JsonObject) Value() (driver.Value, error)

type StringSlice

type StringSlice []string

func (*StringSlice) Scan

func (s *StringSlice) Scan(src any) error

func (StringSlice) Value

func (s StringSlice) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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