orm

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2021 License: MIT Imports: 10 Imported by: 0

README

orm

planned features

  • 🚧 YAML descriptor;
  • 🚧 Code generation;
  • 🚧 Schema;
  • 🔲 Relation, eager and lazy, loading;
  • 🔲 Queries;
    • 🔲 Cache;
    • 🔲 Scopes;
    • 🔲 Static;
    • 🔲 Dynamic;
  • 🔲 Stores;

✔ Done
✅ Partially done
🚧 Development started
🔲 Pending

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFieldNotFound = errors.New("field not found")
)
View Source
var ErrInvalidJoinType = errors.New("invalid join type")

Functions

This section is empty.

Types

type BaseRecord

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

BaseRecord implements some basic methods to be used by the store.

func (*BaseRecord) IsPersisted

func (record *BaseRecord) IsPersisted() bool

IsPersisted returns if the record was persisted.

func (*BaseRecord) IsWritable

func (record *BaseRecord) IsWritable() bool

IsWritable returns if the record can be saved to the database.

func (*BaseRecord) TableName

func (record *BaseRecord) TableName() string

TableName returns the name of the table that this record repesents.

type BaseTxRunner

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

func (*BaseTxRunner) Commit

func (tx *BaseTxRunner) Commit(ctx context.Context) error

func (*BaseTxRunner) Exec

func (tx *BaseTxRunner) Exec(ctx context.Context, query string, args ...interface{}) (pgconn.CommandTag, error)

func (*BaseTxRunner) Prepare

func (tx *BaseTxRunner) Prepare(ctx context.Context, name, query string) (*pgconn.StatementDescription, error)

func (*BaseTxRunner) Query

func (tx *BaseTxRunner) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

func (*BaseTxRunner) QueryFunc

func (tx *BaseTxRunner) QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error)

func (*BaseTxRunner) QueryRow

func (tx *BaseTxRunner) QueryRow(ctx context.Context, query string, args ...interface{}) pgx.Row

func (*BaseTxRunner) Rollback

func (tx *BaseTxRunner) Rollback(ctx context.Context) error

type ConnectionPgx

type ConnectionPgx interface {
	PgxDBRunner
	DB() PgxDBProxy
	Builder() sqlf.Builder
	Begin(ctx context.Context) (TxPgxProxy, error)
	BeginTx(ctx context.Context, opts pgx.TxOptions) (TxPgxProxy, error)
}

func NewConnectionPgx

func NewConnectionPgx(db *pgxpool.Pool, builder sqlf.Builder) ConnectionPgx

NewConnectionPgx will create a new instance of the `*BaseConnection`.

type DefaultScoper

type DefaultScoper interface {
	DefaultScope() error
}

type HookAfterDelete

type HookAfterDelete interface {
	AfterDelete(ctx context.Context, err error)
}

type HookAfterInsert

type HookAfterInsert interface {
	AfterInsert(ctx context.Context, err error, fields ...SchemaField)
}

type HookAfterSave

type HookAfterSave interface {
	AfterSave(ctx context.Context, err error, fields ...SchemaField)
}

type HookAfterUpdate

type HookAfterUpdate interface {
	AfterUpdate(ctx context.Context, err error, fields ...SchemaField)
}

type HookBeforeDelete

type HookBeforeDelete interface {
	BeforeDelete(ctx context.Context) error
}

type HookBeforeInsert

type HookBeforeInsert interface {
	BeforeInsert(ctx context.Context, fields ...SchemaField) error
}

type HookBeforeSave

type HookBeforeSave interface {
	BeforeSave(ctx context.Context, fields ...SchemaField) error
}

type HookBeforeUpdate

type HookBeforeUpdate interface {
	BeforeUpdate(ctx context.Context, fields ...SchemaField) error
}

type JoinType

type JoinType int
const (
	JoinNone JoinType = iota
	InnerJoin
	LeftJoin
	RightJoin
	FullJoin
	OuterJoin
)

func (JoinType) String

func (t JoinType) String() string

type PgxDBProxy

type PgxDBProxy interface {
	PgxDBRunner
	Begin(ctx context.Context) (pgx.Tx, error)
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
}

type PgxDBRunner

type PgxDBRunner interface {
	PgxExecer
	PgxQueryer
	PgxRowQueryer
	PgxPreparer
}

type PgxExecer

type PgxExecer interface {
	Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
}

type PgxPreparer

type PgxPreparer interface {
	Prepare(ctx context.Context, name, sql string) (sd *pgconn.StatementDescription, err error)
}

type PgxQueryer

type PgxQueryer interface {
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
	QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error)
}

type PgxRowQueryer

type PgxRowQueryer interface {
	QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
}

type Query

type Query interface {
	sqlf.FastSqlizer
	sqlf.Sqlizer

	// Select defines what are the fields that this query should return. If this method is called twice, the second time
	// will override all values from the first call. If you want to stack fields, use `AddSelect` instead.
	Select(fields ...SchemaField)
	// AddSelect adds the passed fields to the select list.
	AddSelect(fields ...SchemaField)
	// GetSelect returns the fields that where selected.
	GetSelect() []SchemaField
	// From defines the FROM clause for the Query
	From(schema Schema)
	// Join adds a join to the Query.
	Join(joinType JoinType, schema Schema, condition string, params ...interface{})
	// Join adds a inner join to the Query.
	InnerJoin(schema Schema, condition string, params ...interface{})
	// Join adds a left join to the Query.
	LeftJoin(schema Schema, condition string, params ...interface{})
	// Join adds a right join to the Query.
	RightJoin(schema Schema, condition string, params ...interface{})
	// Join adds a full join to the Query.
	FullJoin(schema Schema, condition string, params ...interface{})
	// Where define the where condition for the Query.
	Where(condition string, params ...interface{})
	// WhereCriteria define the where condition for the Query using criteria.
	WhereCriteria(conditions ...sqlf.FastSqlizer)
	// Skip sets the skip option for the Query.
	Skip(skip int)
	// Limit defines the pagination for the Query.
	Limit(limit int)
	// GroupBy defines the GROUP BY clause for the Query.
	GroupBy(fields ...interface{})
	// GroupByX defines the GROUP BY with the HAVING clause for the Query.
	GroupByX(func(sqlf.GroupBy))
	// OrderBy defines the ORDER BY for the Query.
	OrderBy(fields ...interface{})
	// OrderBy defines the ORDER BY for the Query.
	OrderByX(f func(sqlf.OrderBy))
}

func NewQuery

func NewQuery(conn ConnectionPgx, schema Schema) Query

type Record

type Record interface {
	GetID() interface{}
	TableName() string
	IsPersisted() bool
	IsWritable() bool
}

type ResultSet

type ResultSet interface {
	Next() bool
	Scan(args ...interface{}) error
	Err() error
}

type ResultSetPgx

type ResultSetPgx interface {
	ResultSet
	Close()
	FieldDescriptions() []pgproto3.FieldDescription
}

type Schema

type Schema interface {
	// Table returns the table name for this schema.
	Table() string
	// Alias returns the alias name for the table. By default, its implementation
	// should return the table name.
	Alias() string
	// As returns a new Schema with an SQL alias set.
	As(alias string) Schema
	// Columns list all columns from this schema.
	Columns() []SchemaField
}

Schema represents a table schema.

func NewSchema

func NewSchema(table string, fields ...SchemaField) Schema

type SchemaField

type SchemaField interface {
	fmt.Stringer
	// Name returns the name of the field
	Name() string
	// QualifiedName returns the field name together with the Schema table name.
	QualifiedName(Schema) string
}

SchemaField represents a field in the schema.

func NewSchemaField

func NewSchemaField(name string) SchemaField

type TxPgxProxy

type TxPgxProxy interface {
	PgxDBRunner
	Commit(context.Context) error
	Rollback(context.Context) error
}

func NewPgxTx

func NewPgxTx(tx pgx.Tx) TxPgxProxy

NewPgxTx returns a new transaction abstraction.

Directories

Path Synopsis
gen
cmd
samples

Jump to

Keyboard shortcuts

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