quirk

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT, MIT Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Id        = "id"
	CreatedAt = "created_at"
	UpdatedAt = "updated_at"
	Vectors   = "vectors"
)
View Source
const (
	Default          = "DEFAULT"
	CurrentTimestamp = "CURRENT_TIMESTAMP"
)
View Source
const (
	Postgres = "postgres"
	Mysql    = "mysql"
)
View Source
const (
	ParamPrefix = "@"
	Placeholder = "?"
)
View Source
const (
	DefaultTimout = 30 * time.Second
)

Variables

View Source
var (
	ErrorMismatchArgs = errors.New("placeholders and args count mismatch")
)

Functions

func CreateInsert

func CreateInsert(data map[string]any) (string, string)

func CreateTableStructure

func CreateTableStructure(fields []Field) string

func CreateTsQuery

func CreateTsQuery(values ...any) string

func CreateTsVector

func CreateTsVector(values ...any) string

func CreateUpdate

func CreateUpdate(data map[string]any) string

func Escape

func Escape(value string) string

func MapToTsVectorsValue

func MapToTsVectorsValue[T any](m map[string]T) string

func Normalize

func Normalize(value string) string

func Nullable added in v0.1.2

func Nullable[T any](v T) sql.Null[T]

func RemoveAccents

func RemoveAccents(value string) string

Types

type Config

type Config interface{}

func WithCertPath

func WithCertPath(certpath string) Config

func WithDbname

func WithDbname(dbname string) Config

func WithDriver

func WithDriver(driver string) Config

func WithHost

func WithHost(host string) Config

func WithLog

func WithLog(log bool) Config

func WithMysql

func WithMysql() Config

func WithPassword

func WithPassword(password string) Config

func WithPort

func WithPort(port int) Config

func WithPostgres

func WithPostgres() Config

func WithSsl

func WithSsl(sslmode string) Config

func WithSslAllow

func WithSslAllow() Config

func WithSslDisable

func WithSslDisable() Config

func WithSslPrefer

func WithSslPrefer() Config

func WithSslRequire

func WithSslRequire() Config

func WithSslVerifyCa

func WithSslVerifyCa() Config

func WithSslVerifyFull

func WithSslVerifyFull() Config

func WithTimeout added in v0.2.2

func WithTimeout(duration time.Duration) Config

func WithUser

func WithUser(user string) Config

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

func Connect

func Connect(configs ...Config) (*DB, error)

func MustConnect

func MustConnect(configs ...Config) *DB

func Open

func Open(driverName, dataSourceName string) (*DB, error)

func (*DB) Begin

func (d *DB) Begin() (*DB, error)

func (*DB) Commit

func (d *DB) Commit() error

func (*DB) DriverName

func (d *DB) DriverName() string

func (*DB) Log

func (d *DB) Log(use ...bool)

func (*DB) MustBegin

func (d *DB) MustBegin() *DB

func (*DB) MustCommit

func (d *DB) MustCommit()

func (*DB) MustRollback

func (d *DB) MustRollback()

func (*DB) Q

func (d *DB) Q(query string, arg ...Map) *Quirk

func (*DB) Rollback

func (d *DB) Rollback() error

type Field

type Field struct {
	Name  string
	Props string
	Value any
}

func MergeFields

func MergeFields(a []Field, b []Field) []Field

type Jsonb

type Jsonb[T any] map[string]T

func MapToJsonb

func MapToJsonb[T any](mv map[string]T) Jsonb[T]

func (*Jsonb[T]) Scan

func (j *Jsonb[T]) Scan(value any) error

func (Jsonb[T]) Value

func (j Jsonb[T]) Value() (driver.Value, error)

type Map

type Map map[string]any

type Quirk

type Quirk struct {
	*DB
	// contains filtered or unexported fields
}

func New

func New(db *DB) *Quirk

func (*Quirk) CreateMatcher

func (q *Quirk) CreateMatcher() string

func (*Quirk) CreateSql

func (q *Quirk) CreateSql() string

func (*Quirk) Exec

func (q *Quirk) Exec(r ...any) error

func (*Quirk) ExecCtx added in v0.2.2

func (q *Quirk) ExecCtx(ctx context.Context, r ...any) error

func (*Quirk) If

func (q *Quirk) If(condition bool, query string, arg ...Map) *Quirk

func (*Quirk) MustExec

func (q *Quirk) MustExec(r ...any)

func (*Quirk) MustExecCtx added in v0.2.2

func (q *Quirk) MustExecCtx(ctx context.Context, r ...any)

func (*Quirk) Q

func (q *Quirk) Q(query string, arg ...Map) *Quirk

func (*Quirk) Subscribe

func (q *Quirk) Subscribe(s subscription)

func (*Quirk) WhereExists

func (q *Quirk) WhereExists() bool

type Safe

type Safe []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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