sqlp

package module
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 2 Imported by: 0

README

sqlp is a custom orm for Go that uses reflection to map structs to database tables. Heavy work in progress. Breaking changes every week. No tests. No documentation. No optimization (20-30% slower than native). No guarantees. Do not use.

sql+

Go Reference

sql+ provides some convenience functions for using structs with go's database/sql package

it is fully based on kisielks package. I am using it for experimenting with orm-concepts and am using it for some private projects. Simple stuff, no external dependencies.

Documentation

Overview

Package sqlp is a custom orm for Go that uses reflection to map structs to database tables. Heavy work in progress. Breaking changes every week. No tests. No documentation. No optimization (20-30% slower than native). No guarantees. Do not use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete added in v0.1.2

func Delete[T Repo](pk any) error

Delete deletes the row in the table that the Repo type maps to based on the given primary key.

func DeleteObj added in v0.1.25

func DeleteObj[T Repo](obj T) error

DeleteObj deletes the row in the table that the Repo type maps to based on the primary key of the given object.

func GetAll added in v0.1.25

func GetAll[T Repo]() ([]T, error)

GetAll retrieves all rows from the table that the Repo type maps to.

func GetAllWhere added in v0.1.25

func GetAllWhere[T Repo](where string, args ...any) ([]T, error)

GetAllWhere retrieves all rows from the table that the Repo type maps to, where the where clause is true. The clause should start with "WHERE" or "ORDERBY".

func GetByPk added in v0.1.25

func GetByPk[T Repo](pk any) (T, error)

GetByPk retrieves a single row from the table that the Repo type maps to, where the primary key matches the given value.

func GetSingleWhere added in v0.1.25

func GetSingleWhere[T Repo](where string, args ...any) (res T, err error)

GetSingleWhere retrieves the first row from the table that the Repo type maps to that matches the where clause. The clause should start with "WHERE" or "ORDERBY".

func Insert

func Insert[T Repo](obj T) (int, error)

Insert inserts a new row into the table that the Repo type maps to.

func Query

func Query[T any](query string, args ...any) (results []T, err error)

func QueryBasic

func QueryBasic[T string | int | int64 | float32 | float64](query string, args ...any) (results []T, err error)

func QueryBasicRow added in v0.1.4

func QueryBasicRow[T string | int | int64 | float32 | float64](query string, args ...any) (result T, err error)

func QueryRow

func QueryRow[T any](query string, args ...any) (result T, err error)

func SetDatabase

func SetDatabase(sqldb *sql.DB)

SetDatabase sets the global database handle to be used by the Query function.

func Update

func Update[T Repo](obj T) error

Update updates the row in the table that the Repo type maps to.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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