database

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 3 Imported by: 28

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectDriver

func DetectDriver(dsn string) string

func Register

func Register(name string, factory DriverFactory)

Types

type BaseDialect

type BaseDialect struct{}

func (*BaseDialect) CaseInsensitiveLike

func (d *BaseDialect) CaseInsensitiveLike() string

func (*BaseDialect) LimitOffset

func (d *BaseDialect) LimitOffset(limit, offset int) string

func (*BaseDialect) MapType added in v0.4.6

func (d *BaseDialect) MapType(dbType string) string

func (*BaseDialect) OnConflictClause added in v0.4.6

func (d *BaseDialect) OnConflictClause(columns []string, action string) string

func (*BaseDialect) Placeholder added in v0.4.6

func (d *BaseDialect) Placeholder(n int) string

func (*BaseDialect) QuoteIdentifier added in v0.4.6

func (d *BaseDialect) QuoteIdentifier(name string) string

func (*BaseDialect) ReturningClause added in v0.4.6

func (d *BaseDialect) ReturningClause(cols ...string) string

func (*BaseDialect) SupportsArrays added in v0.4.6

func (d *BaseDialect) SupportsArrays() bool

func (*BaseDialect) SupportsCTE added in v0.4.6

func (d *BaseDialect) SupportsCTE() bool

func (*BaseDialect) SupportsFullJoin added in v0.4.6

func (d *BaseDialect) SupportsFullJoin() bool

func (*BaseDialect) SupportsReturning added in v0.4.6

func (d *BaseDialect) SupportsReturning() bool

func (*BaseDialect) SupportsWindowFunctions added in v0.4.6

func (d *BaseDialect) SupportsWindowFunctions() bool

func (*BaseDialect) UpsertSupport added in v0.4.6

func (d *BaseDialect) UpsertSupport() bool

type Column

type Column struct {
	Name       string
	Type       string
	IsNullable bool
}

type Database

type Database interface {
	Connect(ctx context.Context, dsn string) error
	Close() error
	Ping(ctx context.Context) error

	Query(ctx context.Context, query string, args ...interface{}) (Rows, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) Row
	Exec(ctx context.Context, query string, args ...interface{}) (Result, error)

	Begin(ctx context.Context) (Tx, error)

	Dialect() Dialect
	DriverName() string
	Introspector() SchemaIntrospector
}

func Open

func Open(driverName, dsn string) (Database, error)

type Dialect

type Dialect interface {
	Placeholder(n int) string
	SupportsReturning() bool
	ReturningClause(cols ...string) string
	LimitOffset(limit, offset int) string
	QuoteIdentifier(name string) string
	MapType(dbType string) string
	CaseInsensitiveLike() string

	// Query builder capabilities
	SupportsFullJoin() bool
	SupportsWindowFunctions() bool
	SupportsCTE() bool
	SupportsArrays() bool
	OnConflictClause(columns []string, action string) string
	UpsertSupport() bool
}

type DriverFactory

type DriverFactory func() Database

type Relation

type Relation struct {
	ChildTable   string
	ChildColumn  string
	ParentTable  string
	ParentColumn string
}

type Result

type Result interface {
	LastInsertId() (int64, error)
	RowsAffected() (int64, error)
}

type Row

type Row interface {
	Scan(dest ...interface{}) error
}

type Rows

type Rows interface {
	Next() bool
	Scan(dest ...interface{}) error
	Close() error
	Err() error
}

type SchemaIntrospector

type SchemaIntrospector interface {
	LoadSchema(ctx context.Context) ([]TableSchema, error)
	GetColumns(ctx context.Context, tableName string) ([]Column, error)
	GetRelations(ctx context.Context) ([]Relation, error)
}

type StandardType

type StandardType string
const (
	TypeInteger   StandardType = "integer"
	TypeBigInt    StandardType = "bigint"
	TypeString    StandardType = "string"
	TypeText      StandardType = "text"
	TypeBoolean   StandardType = "boolean"
	TypeTimestamp StandardType = "timestamp"
	TypeUUID      StandardType = "uuid"
	TypeJSON      StandardType = "json"
	TypeFloat     StandardType = "float"
	TypeDecimal   StandardType = "decimal"
	TypeDate      StandardType = "date"
	TypeTime      StandardType = "time"
	TypeBytea     StandardType = "bytea"
)

func StandardizeType

func StandardizeType(dbType, driverName string) StandardType

type TableSchema

type TableSchema struct {
	TableName string
	Columns   []Column
	Relations []Relation
}

type Tx

type Tx interface {
	Query(ctx context.Context, query string, args ...interface{}) (Rows, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) Row
	Exec(ctx context.Context, query string, args ...interface{}) (Result, error)
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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