orm

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEntityNotFound = errors.New("entity not found")
	ErrSessionNotSet  = errors.New("session not found in context")
)

Functions

func Session

func Session(ctx context.Context) *session

Session extract session from context, return nil if session not found.

Types

type Driver

type Driver interface {
	MakePusher(tx Transaction) persistence.Pusher

	ExecuteQuery(query *query.Query, tx Transaction) ([]map[string]interface{}, error)
	BeforeQuery(fn func(query string, args ...interface{}))
	AfterQuery(fn func(query string, args ...interface{}))

	BeginTx() (Transaction, error)

	MakeScalarDataMapper() ScalarDataMapper
}

type Orm

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

Orm - d3 orm instance.

func New

func New(driver Driver) *Orm

New - create an instance of d3 orm.

driver - d3 wrapper on database driver. Find it in adapter package.

func (*Orm) CtxWithSession

func (o *Orm) CtxWithSession(ctx context.Context) context.Context

CtxWithSession append new session instance to context.

func (*Orm) GenerateSchema

func (o *Orm) GenerateSchema() (string, error)

GenerateSchema - create sql DDL for persist all registered entities in database. May return error if driver nonsupport schema generation.

func (*Orm) MakeRepository

func (o *Orm) MakeRepository(entity interface{}) (*Repository, error)

MakeRepository - create new repository for entity.

entity - entity to store in repository.

func (*Orm) MakeSession

func (o *Orm) MakeSession() *session

MakeSession - create new instance of session.

func (*Orm) Register

func (o *Orm) Register(entities ...interface{}) error

Register - register entities in d3 orm. Note that entity must be structure and must implement D3Entity interface (it's implement it after use code generation tool). Besides if you register entity with dependencies (for example: one to one relation) you must registered depended entities too, in the same call.

type Repository

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

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, entities ...interface{}) error

Delete - delete entities from repository.

func (*Repository) FindAll

func (r *Repository) FindAll(ctx context.Context, q *query.Query) (*d3entity.Collection, error)

FindOne - return collection of entities fetched by query.

func (*Repository) FindOne

func (r *Repository) FindOne(ctx context.Context, q *query.Query) (interface{}, error)

FindOne - return one entity fetched by query. If entity not found ErrEntityNotFound will returned.

func (*Repository) Persists

func (r *Repository) Persists(ctx context.Context, entities ...interface{}) error

Persists - add entities to repository.

func (*Repository) Select

func (r *Repository) Select() *query.Query

Select - create query for fetch entity with the same type as the repository.

type ScalarDataMapper

type ScalarDataMapper func(data interface{}, into reflect.Kind) interface{}

type Transaction

type Transaction interface {
	Commit() error
	Rollback() error
}

Transaction for control transaction driver must provide instance of this interface.

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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