drivers

package
v0.0.0-...-7687a33 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DateLayout = "2006-01-02"
)

Variables

View Source
var (
	CheckID          = exp.NewLiteralExpression(`'^[0-9]+$'`)
	CheckNumber      = exp.NewLiteralExpression(`'^[+-]?[0-9]+(\.[0-9]+)?$'`)
	CheckFullISO8061 = exp.NewLiteralExpression(`'^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}(\.[0-9]*)?)((-([0-9]{2}):([0-9]{2})|Z)?)$'`)
	CheckDateISO8061 = exp.NewLiteralExpression(`'^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2}):([0-9]{2}):([0-9]{2}(\.[0-9]*)?)((-([0-9]{2}):([0-9]{2})|Z)?))?$'`)
	CheckTimeISO8061 = exp.NewLiteralExpression(`'^(([0-9]{4})-([0-9]{2})-([0-9]{2}))?T?([0-9]{2}):([0-9]{2}):([0-9]{2}(\.[0-9]*)?)((-([0-9]{2}):([0-9]{2})|Z)?)$'`)
	LiteralNULL      = exp.NewLiteralExpression(`NULL`)
	LiteralFALSE     = exp.NewLiteralExpression(`FALSE`)
	LiteralTRUE      = exp.NewLiteralExpression(`TRUE`)
)

Functions

func AttributeCast

func AttributeCast(attr *dal.Attribute, val exp.Expression) (exp.Expression, error)

func BooleanCheck

func BooleanCheck(val exp.Expression) exp.Expression

func IndexFieldModifiers

func IndexFieldModifiers(attr *dal.Attribute, quoteIdent func(i string) string, mm ...dal.IndexFieldModifier) (string, error)

@note copied to data_definer_test to avoid import cycle; if modified, fixup both parts

func OpHandlerIn

func OpHandlerIn(d Dialect, n *ql.ASTNode, args ...exp.Expression) (expr exp.Expression, err error)

func OpHandlerNotIn

func OpHandlerNotIn(d Dialect, n *ql.ASTNode, args ...exp.Expression) (expr exp.Expression, err error)

func RegexpLike

func RegexpLike(format, val exp.Expression) exp.BooleanExpression

func TimeLayout

func TimeLayout(tz bool, precision int) string

func TimestampLayout

func TimestampLayout(tz bool, precision int) string

Types

type Column

type Column interface {
	Name() string
	Attribute() *dal.Attribute
	IsPrimaryKey() bool
	Encode(dal.ValueGetter) (any, error)
	Decode(any, dal.ValueSetter) error
	Type() Type
}

type Dialect

type Dialect interface {
	// Nuances returns dialect nuances
	// subtle differences between RDBMS implementations that
	// should be handled on common code
	Nuances() Nuances

	// GOQU returns goqu's dialect wrapper struct
	GOQU() goqu.DialectWrapper

	DialectOptions() *sqlgen.SQLDialectOptions

	JsonQuote(exp.Expression) exp.Expression

	// JsonExtract returns expression that returns a value from  inside JSON document
	//
	// Use this when you want use JSON encoded value
	JsonExtract(exp.Expression, ...any) (exp.Expression, error)

	// JsonExtractUnquote returns expression that returns a value from  inside JSON document:
	//
	// Use this when you want to use unencoded value!
	JsonExtractUnquote(exp.Expression, ...any) (exp.Expression, error)

	// JsonArrayContains generates expression JSON array containment check expression
	//
	// Literal values need to be JSON docs!
	//
	// @todo recheck if we really need JsonArrayContains on Dialect interface
	JsonArrayContains(needle, haystack exp.Expression) (exp.Expression, error)

	// AttributeCast prepares complex SQL expression that verifies
	// arbitrary string value in the db and casts it to b used in
	// comparison or soring expression
	AttributeCast(*dal.Attribute, exp.Expression) (exp.Expression, error)

	AttributeExpression(attr *dal.Attribute, modelIdent string, ident string) (expr exp.Expression, err error)

	// TableCodec returns table codec (encodes & decodes data to/from db table)
	TableCodec(*dal.Model) TableCodec

	// TypeWrap returns driver's type implementation for a particular attribute type
	TypeWrap(dal.Type) Type

	QuoteIdent(string) string

	AggregateBase(t TableCodec, gb []dal.AggregateAttr, out []dal.AggregateAttr) *goqu.SelectDataset

	// AttributeToColumn converts attribute to column defunition
	AttributeToColumn(*dal.Attribute) (*ddl.Column, error)
	ColumnFits(base, assert *ddl.Column) bool

	// ExprHandler returns driver specific expression handling
	ExprHandler(*ql.ASTNode, ...exp.Expression) (exp.Expression, error)

	// ValHandler returns driver specific value expression handling
	ValHandler(*ql.ASTNode) (exp.Expression, error)

	// OrderedExpression returns compatible expression for ordering
	//
	// Database understand order modifiers differently. For example, MySQL does not know
	// about NULLS FIRST/LAST. Drivers should gracefully handle this.
	OrderedExpression(exp.Expression, exp.SortDirection, exp.NullSortType) exp.OrderedExpression
}

type GenericTableCodec

type GenericTableCodec struct {
	// contains filtered or unexported fields
}

GenericTableCodec is a generic implementation of TableCodec

func NewTableCodec

func NewTableCodec(m *dal.Model, d Dialect) *GenericTableCodec

func (*GenericTableCodec) AttributeExpression

func (t *GenericTableCodec) AttributeExpression(ident string) (exp.Expression, error)

func (*GenericTableCodec) AttributeExpressionQuoted

func (t *GenericTableCodec) AttributeExpressionQuoted(ident string) (exp.Expression, error)

func (*GenericTableCodec) Columns

func (t *GenericTableCodec) Columns() []Column

func (*GenericTableCodec) Decode

func (t *GenericTableCodec) Decode(buf []any, r dal.ValueSetter) (err error)

func (*GenericTableCodec) Encode

func (t *GenericTableCodec) Encode(r dal.ValueGetter) (_ []any, err error)

func (*GenericTableCodec) Ident

func (*GenericTableCodec) MakeScanBuffer

func (t *GenericTableCodec) MakeScanBuffer() []any

type ID

type ID struct {
	ID    uint64
	Valid bool // Valid is true if Uint64 is not NULL
}

nullUint64 represents an uint64 that may be null. nullUint64 implements the Scanner interface so it can be used as a scan dåestination, similar to NullString.

func (*ID) Scan

func (n *ID) Scan(value any) (err error)

Scan implements the Scanner interface.

func (ID) String

func (n ID) String() string

func (ID) Value

func (n ID) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Nuances

type Nuances struct {
	// HavingClauseMustUseAlias
	// For example, Postgres and SQLite require
	// use of aliases inside HAVING clause and
	// MySQL does not.
	HavingClauseMustUseAlias bool

	// TwoStepUpsert allows support for databases which don't have an upsert
	// or we simply couldn't figure out how to make work.
	//
	// TwoStepUpsert uses the context from the update statement to figure out
	// if it needs to do an insert.
	TwoStepUpsert bool

	// @todo change this around; temporary fix as not sure how I'd rewrite
	ExpandedJsonColumnSelector func(ident string) exp.Expression
}

type SimpleJsonDocColumn

type SimpleJsonDocColumn struct {
	// contains filtered or unexported fields
}

func (*SimpleJsonDocColumn) Attribute

func (c *SimpleJsonDocColumn) Attribute() *dal.Attribute

func (*SimpleJsonDocColumn) Decode

func (c *SimpleJsonDocColumn) Decode(raw any, r dal.ValueSetter) (err error)

func (*SimpleJsonDocColumn) DecodeOld

func (c *SimpleJsonDocColumn) DecodeOld(raw any, r dal.ValueSetter) (err error)

func (*SimpleJsonDocColumn) Encode

func (c *SimpleJsonDocColumn) Encode(r dal.ValueGetter) (_ any, err error)

func (*SimpleJsonDocColumn) IsPrimaryKey

func (c *SimpleJsonDocColumn) IsPrimaryKey() bool

func (*SimpleJsonDocColumn) Name

func (c *SimpleJsonDocColumn) Name() string

func (*SimpleJsonDocColumn) Type

func (c *SimpleJsonDocColumn) Type() Type

type SingleValueColumn

type SingleValueColumn struct {
	// contains filtered or unexported fields
}

func NewSingleValueColumn

func NewSingleValueColumn(d Dialect, a *dal.Attribute) *SingleValueColumn

func (*SingleValueColumn) Attribute

func (c *SingleValueColumn) Attribute() *dal.Attribute

func (*SingleValueColumn) Decode

func (c *SingleValueColumn) Decode(raw any, r dal.ValueSetter) error

func (*SingleValueColumn) Encode

func (c *SingleValueColumn) Encode(r dal.ValueGetter) (any, error)

func (*SingleValueColumn) IsPrimaryKey

func (c *SingleValueColumn) IsPrimaryKey() bool

func (*SingleValueColumn) Name

func (c *SingleValueColumn) Name() string

func (*SingleValueColumn) Type

func (c *SingleValueColumn) Type() Type

type TableCodec

type TableCodec interface {
	Columns() []Column
	Ident() exp.IdentifierExpression
	MakeScanBuffer() []any
	Encode(r dal.ValueGetter) (_ []any, err error)
	Decode(buf []any, r dal.ValueSetter) (err error)
	AttributeExpression(string) (exp.Expression, error)
	AttributeExpressionQuoted(string) (exp.Expression, error)
}

TableCodec is an RDBMS representation of data.Model structure and its arguments

type Type

type Type interface {
	MakeScanBuffer() any
	Decode(any) (any, bool, error)
	Encode(any) (driver.Value, error)
}

func TypeWrap

func TypeWrap(dt dal.Type) Type

TypeWrap wraps type from data package

type TypeBlob

type TypeBlob struct{ *dal.TypeBlob }

func (*TypeBlob) Decode

func (t *TypeBlob) Decode(raw any) (any, bool, error)

func (*TypeBlob) Encode

func (t *TypeBlob) Encode(val any) (driver.Value, error)

func (*TypeBlob) MakeScanBuffer

func (*TypeBlob) MakeScanBuffer() any

type TypeBoolean

type TypeBoolean struct{ *dal.TypeBoolean }

func (*TypeBoolean) Decode

func (t *TypeBoolean) Decode(raw any) (any, bool, error)

func (*TypeBoolean) Encode

func (t *TypeBoolean) Encode(val any) (driver.Value, error)

func (*TypeBoolean) MakeScanBuffer

func (*TypeBoolean) MakeScanBuffer() any

type TypeDate

type TypeDate struct{ *dal.TypeDate }

func (*TypeDate) Decode

func (t *TypeDate) Decode(raw any) (any, bool, error)

func (*TypeDate) Encode

func (t *TypeDate) Encode(val any) (driver.Value, error)

func (*TypeDate) MakeScanBuffer

func (*TypeDate) MakeScanBuffer() any

type TypeEnum

type TypeEnum struct{ *dal.TypeEnum }

func (*TypeEnum) Decode

func (t *TypeEnum) Decode(raw any) (any, bool, error)

func (*TypeEnum) Encode

func (t *TypeEnum) Encode(val any) (driver.Value, error)

func (*TypeEnum) MakeScanBuffer

func (*TypeEnum) MakeScanBuffer() any

type TypeGeometry

type TypeGeometry struct{ *dal.TypeGeometry }

func (*TypeGeometry) Decode

func (t *TypeGeometry) Decode(raw any) (any, bool, error)

func (*TypeGeometry) Encode

func (t *TypeGeometry) Encode(val any) (driver.Value, error)

func (*TypeGeometry) MakeScanBuffer

func (*TypeGeometry) MakeScanBuffer() any

type TypeID

type TypeID struct{ *dal.TypeID }

func (*TypeID) Decode

func (t *TypeID) Decode(raw any) (any, bool, error)

func (*TypeID) Encode

func (t *TypeID) Encode(val any) (driver.Value, error)

func (*TypeID) MakeScanBuffer

func (*TypeID) MakeScanBuffer() any

type TypeJSON

type TypeJSON struct{ *dal.TypeJSON }

func (*TypeJSON) Decode

func (t *TypeJSON) Decode(raw any) (any, bool, error)

func (*TypeJSON) Encode

func (t *TypeJSON) Encode(val any) (driver.Value, error)

func (*TypeJSON) MakeScanBuffer

func (*TypeJSON) MakeScanBuffer() any

type TypeNumber

type TypeNumber struct{ *dal.TypeNumber }

func (*TypeNumber) Decode

func (t *TypeNumber) Decode(raw any) (any, bool, error)

func (*TypeNumber) Encode

func (t *TypeNumber) Encode(val any) (driver.Value, error)

func (*TypeNumber) MakeScanBuffer

func (*TypeNumber) MakeScanBuffer() any

type TypeRef

type TypeRef struct{ *dal.TypeRef }

func (*TypeRef) Decode

func (t *TypeRef) Decode(raw any) (any, bool, error)

func (*TypeRef) Encode

func (t *TypeRef) Encode(val any) (driver.Value, error)

func (*TypeRef) MakeScanBuffer

func (*TypeRef) MakeScanBuffer() any

type TypeText

type TypeText struct{ *dal.TypeText }

func (*TypeText) Decode

func (t *TypeText) Decode(raw any) (any, bool, error)

func (*TypeText) Encode

func (t *TypeText) Encode(val any) (driver.Value, error)

func (*TypeText) MakeScanBuffer

func (*TypeText) MakeScanBuffer() any

type TypeTime

type TypeTime struct{ *dal.TypeTime }

func (*TypeTime) Decode

func (t *TypeTime) Decode(raw any) (any, bool, error)

func (*TypeTime) Encode

func (t *TypeTime) Encode(val any) (driver.Value, error)

func (*TypeTime) MakeScanBuffer

func (*TypeTime) MakeScanBuffer() any

type TypeTimestamp

type TypeTimestamp struct{ *dal.TypeTimestamp }

func (*TypeTimestamp) Decode

func (t *TypeTimestamp) Decode(raw any) (any, bool, error)

func (*TypeTimestamp) Encode

func (t *TypeTimestamp) Encode(val any) (driver.Value, error)

func (*TypeTimestamp) MakeScanBuffer

func (*TypeTimestamp) MakeScanBuffer() any

type TypeUUID

type TypeUUID struct{ *dal.TypeUUID }

func (*TypeUUID) Decode

func (t *TypeUUID) Decode(raw any) (any, bool, error)

func (*TypeUUID) Encode

func (t *TypeUUID) Encode(val any) (driver.Value, error)

func (*TypeUUID) MakeScanBuffer

func (*TypeUUID) MakeScanBuffer() any

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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