db

package
v0.0.0-...-9171f6b Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColumnCreateSQL

func ColumnCreateSQL(col Column) string

func ColumnDropSQL

func ColumnDropSQL(col Column) string

func ColumnsSQL

func ColumnsSQL(columns ...Column) string

func ConstraintCreateSQL

func ConstraintCreateSQL(ctr Constraint) string

func ConstraintDropSQL

func ConstraintDropSQL(ctr Constraint) string

func ConvertParams

func ConvertParams(sql string) string

func DefinitionCreateSQL

func DefinitionCreateSQL(def Definition) string

func DefinitionDropSQL

func DefinitionDropSQL(def Definition) string

func TableDefinitionCreateSQL

func TableDefinitionCreateSQL(def TableDefinition) string

func TableDefinitionDropSQL

func TableDefinitionDropSQL(def TableDefinition) string

Types

type BasicColumn

type BasicColumn struct {
	BasicTableDefinition
	// contains filtered or unexported fields
}

func (BasicColumn) DefinitionType

func (_ BasicColumn) DefinitionType() string

func (BasicColumn) Eq

func (self BasicColumn) Eq(other any) Condition

func (*BasicColumn) Init

func (self *BasicColumn) Init(table Table, name string, options ...ColumnOption) *BasicColumn

func (BasicColumn) OptionSQL

func (self BasicColumn) OptionSQL() string

type BasicColumnsDefinition

type BasicColumnsDefinition struct {
	BasicTableDefinition
	// contains filtered or unexported fields
}

func (*BasicColumnsDefinition) Columns

func (self *BasicColumnsDefinition) Columns() []Column

func (*BasicColumnsDefinition) Init

func (self *BasicColumnsDefinition) Init(table Table, name string, columns ...Column) *BasicColumnsDefinition

type BasicConstraint

type BasicConstraint struct {
	BasicColumnsDefinition
}

func (BasicConstraint) DefinitionType

func (_ BasicConstraint) DefinitionType() string

func (*BasicConstraint) Init

func (self *BasicConstraint) Init(table Table, name string, columns ...Column) *BasicConstraint

type BasicDefinition

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

func (*BasicDefinition) Init

func (self *BasicDefinition) Init(name string) *BasicDefinition

func (BasicDefinition) Name

func (self BasicDefinition) Name() string

func (BasicDefinition) SQLName

func (self BasicDefinition) SQLName() string

type BasicTable

type BasicTable struct {
	BasicDefinition
	// contains filtered or unexported fields
}

func NewTable

func NewTable(name string) *BasicTable

func (*BasicTable) AddColumn

func (self *BasicTable) AddColumn(column Column)

func (*BasicTable) AddDefinition

func (self *BasicTable) AddDefinition(definition Definition)

func (*BasicTable) AddForeignKey

func (self *BasicTable) AddForeignKey(key *ForeignKey)

func (*BasicTable) AddIndex

func (self *BasicTable) AddIndex(index *Index)

func (BasicTable) Columns

func (self BasicTable) Columns() []Column

func (BasicTable) Create

func (self BasicTable) Create(tx *Tx) error

func (BasicTable) CreateSQL

func (self BasicTable) CreateSQL() string

func (BasicTable) DefinitionType

func (_ BasicTable) DefinitionType() string

func (BasicTable) Delete

func (self BasicTable) Delete(cond Condition, tx *Tx) error

func (BasicTable) Drop

func (self BasicTable) Drop(tx *Tx) error

func (BasicTable) DropSQL

func (self BasicTable) DropSQL() string

func (*BasicTable) Init

func (self *BasicTable) Init(name string) *BasicTable

func (BasicTable) Insert

func (self BasicTable) Insert(rec Record, tx *Tx) error

func (BasicTable) PrimaryKey

func (self BasicTable) PrimaryKey() *Key

func (*BasicTable) SetPrimaryKey

func (self *BasicTable) SetPrimaryKey(key *Key)

func (BasicTable) Update

func (self BasicTable) Update(rec Record, cond Condition, tx *Tx) error

type BasicTableDefinition

type BasicTableDefinition struct {
	BasicDefinition
	// contains filtered or unexported fields
}

func (*BasicTableDefinition) Init

func (self *BasicTableDefinition) Init(table Table, name string) *BasicTableDefinition

func (*BasicTableDefinition) QualifiedName

func (self *BasicTableDefinition) QualifiedName() string

func (*BasicTableDefinition) Table

func (self *BasicTableDefinition) Table() Table

type Column

type Column interface {
	TableDefinition
	Clone(table Table, name string) Column
	ColumnType() string
	Eq(any) Condition
	OptionSQL() string
}

type ColumnOption

type ColumnOption string
const (
	NotNull ColumnOption = "NOT NULL"
)

type ColumnsDefinition

type ColumnsDefinition interface {
	TableDefinition
	Columns() []Column
}

type Condition

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

func And

func And(conds ...Condition) Condition

func NewCondition

func NewCondition(sql string, params ...any) Condition

func Or

func Or(conds ...Condition) Condition

func (Condition) And

func (self Condition) And(other Condition) Condition

func (Condition) Or

func (self Condition) Or(other Condition) Condition

type Constraint

type Constraint interface {
	ColumnsDefinition
	ConstraintType() string
}

type Cx

type Cx struct {
	StoredValues
	// contains filtered or unexported fields
}

func NewCx

func NewCx(cx context.Context, url string) (*Cx, error)

func (*Cx) Close

func (self *Cx) Close() error

func (*Cx) Init

func (self *Cx) Init(cx context.Context, url string) (*Cx, error)

func (*Cx) StartTx

func (self *Cx) StartTx() (*Tx, error)

type CxOptions

type CxOptions struct {
	Context  context.Context
	Host     string
	Port     int
	Database string
	User     string
	Password string
	SSLMode  bool
}

func DefaultCxOptions

func DefaultCxOptions() CxOptions

func (CxOptions) NewCx

func (self CxOptions) NewCx() (*Cx, error)

type Definition

type Definition interface {
	DefinitionType() string
	Name() string
	//Exists() (bool, error)
	Create(tx *Tx) error
	CreateSQL() string
	Drop(tx *Tx) error
	DropSQL() string
	SQLName() string
}

type Field

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

type ForeignKey

type ForeignKey struct {
	BasicConstraint

	OnUpdate ForeignKeyAction
	OnDelete ForeignKeyAction
	// contains filtered or unexported fields
}

func NewForeignKey

func NewForeignKey(table Table, name string, foreignTable Table, columns ...Column) *ForeignKey

func (ForeignKey) ConstraintType

func (_ ForeignKey) ConstraintType() string

func (ForeignKey) Create

func (self ForeignKey) Create(tx *Tx) error

func (ForeignKey) CreateSQL

func (self ForeignKey) CreateSQL() string

func (ForeignKey) Drop

func (self ForeignKey) Drop(tx *Tx) error

func (ForeignKey) DropSQL

func (self ForeignKey) DropSQL() string

func (*ForeignKey) Init

func (self *ForeignKey) Init(table Table, name string, foreignTable Table, columns ...Column) *ForeignKey

type ForeignKeyAction

type ForeignKeyAction string
const (
	CASCADE  ForeignKeyAction = "CASCADE"
	RESTRICT ForeignKeyAction = "RESTRICT"
)

type Index

type Index struct {
	BasicColumnsDefinition
	// contains filtered or unexported fields
}

func NewIndex

func NewIndex(table Table, name string, unique bool, columns ...Column) *Index

func (Index) Create

func (self Index) Create(tx *Tx) error

func (Index) CreateSQL

func (self Index) CreateSQL() string

func (Index) DefinitionType

func (_ Index) DefinitionType() string

func (Index) Drop

func (self Index) Drop(tx *Tx) error

func (Index) DropSQL

func (self Index) DropSQL() string

func (*Index) Init

func (self *Index) Init(table Table, name string, unique bool, columns ...Column) *Index

type IntegerColumn

type IntegerColumn struct {
	BasicColumn
}

func NewIntegerColumn

func NewIntegerColumn(table Table, name string, options ...ColumnOption) *IntegerColumn

func (IntegerColumn) Clone

func (self IntegerColumn) Clone(table Table, name string) Column

func (IntegerColumn) ColumnType

func (_ IntegerColumn) ColumnType() string

func (IntegerColumn) Create

func (self IntegerColumn) Create(tx *Tx) error

func (IntegerColumn) CreateSQL

func (self IntegerColumn) CreateSQL() string

func (IntegerColumn) Drop

func (self IntegerColumn) Drop(tx *Tx) error

func (IntegerColumn) DropSQL

func (self IntegerColumn) DropSQL() string

func (*IntegerColumn) Get

func (self *IntegerColumn) Get(record Record) int

func (*IntegerColumn) Init

func (self *IntegerColumn) Init(table Table, name string, options ...ColumnOption) *IntegerColumn

func (*IntegerColumn) Set

func (self *IntegerColumn) Set(record *Record, value int)

type Key

type Key struct {
	BasicConstraint
}

func NewKey

func NewKey(table Table, name string, columns ...Column) *Key

func (*Key) ConstraintType

func (self *Key) ConstraintType() string

func (Key) Create

func (self Key) Create(tx *Tx) error

func (Key) CreateSQL

func (self Key) CreateSQL() string

func (Key) Drop

func (self Key) Drop(tx *Tx) error

func (Key) DropSQL

func (self Key) DropSQL() string

func (*Key) Init

func (self *Key) Init(table Table, name string, columns ...Column) *Key

type Record

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

func NewRecord

func NewRecord() *Record

func (Record) Condition

func (self Record) Condition(table Table, tx *Tx) (Condition, error)

func (Record) Delete

func (self Record) Delete(table Table, tx *Tx) error

func (Record) Fields

func (self Record) Fields() []*Field

func (Record) Get

func (self Record) Get(column Column) any

func (*Record) Init

func (self *Record) Init() *Record

func (Record) Modified

func (self Record) Modified(column Column, tx *Tx) bool

func (Record) Null

func (self Record) Null(column Column) bool

func (*Record) Set

func (self *Record) Set(column Column, value any)

func (Record) Store

func (self Record) Store(table Table, tx *Tx) error

func (Record) Stored

func (self Record) Stored(column Column, tx *Tx) bool

func (Record) StoredValue

func (self Record) StoredValue(column Column, tx *Tx) (any, bool)

type StoredValues

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

func (*StoredValues) DeleteStoredValue

func (self *StoredValues) DeleteStoredValue(field *Field)

func (*StoredValues) Init

func (self *StoredValues) Init() *StoredValues

func (*StoredValues) StoreValue

func (self *StoredValues) StoreValue(field *Field)

func (StoredValues) StoredValue

func (self StoredValues) StoredValue(field *Field) (any, bool)

type Table

type Table interface {
	Definition
	AddColumn(Column)
	AddDefinition(Definition)
	AddForeignKey(*ForeignKey)
	AddIndex(*Index)
	Columns() []Column
	Delete(Condition, *Tx) error
	Insert(Record, *Tx) error
	PrimaryKey() *Key
	SetPrimaryKey(*Key)
	Update(Record, Condition, *Tx) error
}

type TableDefinition

type TableDefinition interface {
	Definition
	QualifiedName() string
	Table() Table
}

type TextColumn

type TextColumn struct {
	BasicColumn
}

func NewTextColumn

func NewTextColumn(table Table, name string, options ...ColumnOption) *TextColumn

func (TextColumn) Clone

func (self TextColumn) Clone(table Table, name string) Column

func (TextColumn) ColumnType

func (_ TextColumn) ColumnType() string

func (*TextColumn) Create

func (self *TextColumn) Create(tx *Tx) error

func (*TextColumn) CreateSQL

func (self *TextColumn) CreateSQL() string

func (*TextColumn) Drop

func (self *TextColumn) Drop(tx *Tx) error

func (*TextColumn) DropSQL

func (self *TextColumn) DropSQL() string

func (*TextColumn) Get

func (self *TextColumn) Get(record Record) string

func (*TextColumn) Init

func (self *TextColumn) Init(table Table, name string, options ...ColumnOption) *TextColumn

func (*TextColumn) Set

func (self *TextColumn) Set(record Record, value string)

type Tx

type Tx struct {
	StoredValues
	// contains filtered or unexported fields
}

func (*Tx) Commit

func (self *Tx) Commit() error

func (*Tx) DeleteStoredValue

func (self *Tx) DeleteStoredValue(field *Field)

func (*Tx) ExecSQL

func (self *Tx) ExecSQL(sql string, params ...any) error

func (*Tx) Init

func (self *Tx) Init(cx *Cx, imp pgx.Tx) *Tx

func (*Tx) Rollback

func (self *Tx) Rollback() error

func (Tx) StoredValue

func (self Tx) StoredValue(field *Field) (any, bool)

Jump to

Keyboard shortcuts

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