zsql

package
v0.0.0-...-aa698f8 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AllreadyExistsError = errors.New("already exists")
)

Functions

func ColumnNamesFromStruct

func ColumnNamesFromStruct(s interface{}, skip []string, prefix string) []string

func ColumnNamesStringFromStruct

func ColumnNamesStringFromStruct(istruct interface{}, skip []string, prefix string) string

func ConvertFieldName

func ConvertFieldName(i zreflect.Item) string

func CustomizeQuery

func CustomizeQuery(query string, btype BaseType) string

CustomizeQuery can make a sqlite or psql (or other in future) query, replacing $x with ?x for sqlite. It also replaces $NOW, $SERIAL and $PRIMARY-INT-INC with what is needed for each DB type.

func FieldIndexForColumnName

func FieldIndexForColumnName(s interface{}, skip []string, prefix, column string) int

func FieldNamesToColumnFromStruct

func FieldNamesToColumnFromStruct(s interface{}, skip []string, prefix string) (m map[string]string, primaryCol string)

func ForEachColumn

func ForEachColumn(s interface{}, skip []string, prefix string, got func(each ColumnInfo) bool)

func QuoteString

func QuoteString(str string) string

func ReplaceQuestionMarkArguments

func ReplaceQuestionMarkArguments(squery string, args ...interface{}) string

func SanitizeString

func SanitizeString(str string) string

func Scan

func Scan[A any](a *A, value any) error

func Value

func Value(a any) (d driver.Value, err error)

Types

type BaseType

type BaseType int
const (
	NoType          = 0
	SQLite BaseType = iota + 1
	Postgres
	MySQL // Not used yet
)

type ColumnInfo

type ColumnInfo struct {
	zreflect.FieldInfo
	Column      string
	IsPrimary   bool
	IsUserID    bool
	ColumnIndex int
}

func FieldForColumnName

func FieldForColumnName(s interface{}, skip []string, prefix, column string) (ColumnInfo, bool)

type InsertInfo

type InsertInfo[S any] struct {
	UpsertInfo[S]
	DefCols []string
}

InsertInfo can be simlified? Not used as upsert, oly insert

type JSONStringArray

type JSONStringArray []string

type JSONStringArrayPtr

type JSONStringArrayPtr []string

type JSONer

type JSONer []byte // TODO: Remove? Use sql.Scan/Value methods instead?

type QueryBase

type QueryBase struct {
	Constraints string
	Table       string
	SkipColumns []string
}

type UpsertInfo

type UpsertInfo[S any] struct {
	Rows [][]S
}

type UserIDer

type UserIDer interface {
	GetUserID() int64
}

UserIDer is an interface a struct can get a field that represents a user id with.

Jump to

Keyboard shortcuts

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