orm

package
v0.0.0-...-af561f6 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2019 License: MIT Imports: 4 Imported by: 0

README

orm

-- import "github.com/KyleBanks/go-kit/orm/"

Package orm manages access to a database, including ORM-like functionality.

The package wraps the GORM library, which can then be potentially swapped out with minimal changes.

Usage

var (
	// ErrRecordNotFound is the error returned when trying to load a record
	// that cannot be found.
	ErrRecordNotFound = gorm.ErrRecordNotFound
)
type Model
type Model struct {
	gorm.Model
}

Model is a type added to domain models that will provide ORM functionality.

type ORM
type ORM struct {
}

ORM is a container for the underlying database connection.

func (ORM) AutoMigrate
func (orm ORM) AutoMigrate(models []interface{}) error

AutoMigrate performs database migration for all Model types provided.

func (ORM) Begin
func (orm ORM) Begin() *gorm.DB

Begin starts a new database transaction.

func (ORM) Create
func (orm ORM) Create(model interface{}) *gorm.DB

Create inserts a new model instance into the database.

func (ORM) Exec
func (orm ORM) Exec(query string, output interface{}) *gorm.DB

Exec performs a raw SQL query against the underlying database.

func (ORM) First
func (orm ORM) First(model interface{}, where ...interface{}) *gorm.DB

First returns the first model (ordered by ID) that matches the specified query.

func (ORM) Last
func (orm ORM) Last(model interface{}, where ...interface{}) *gorm.DB

Last returns the last model (ordered by ID) that matches the specified query.

func (ORM) Model
func (orm ORM) Model(model interface{}) *gorm.DB

Model specifies the domain model that subsequent queries will be run against.

func (ORM) ModelExistsWithID
func (orm ORM) ModelExistsWithID(model interface{}, id uint) (bool, error)

ModelExistsWithID returns a boolean indicating if an instance of the specified model exists with a given ID.

func (ORM) ModelWithID
func (orm ORM) ModelWithID(model interface{}, id uint) error

ModelWithID returns an instance of the specified model with the given ID.

func (*ORM) Open
func (orm *ORM) Open(dialect, connectionString string) (*gorm.DB, error)

Open creates a database connection, or returns an existing one if present.

func (ORM) Save
func (orm ORM) Save(value interface{}) *gorm.DB

Save updates a model with the given attributes.

func (ORM) Where
func (orm ORM) Where(query interface{}, args ...interface{}) *gorm.DB

Where performs a query with "Where" parameters.

Documentation

Overview

Package orm manages access to a database, including ORM-like functionality.

The package wraps the GORM library, which can then be potentially swapped out with minimal changes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRecordNotFound is the error returned when trying to load a record
	// that cannot be found.
	ErrRecordNotFound = gorm.ErrRecordNotFound
)

Functions

This section is empty.

Types

type Model

type Model struct {
	gorm.Model
}

Model is a type added to domain models that will provide ORM functionality.

type ORM

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

ORM is a container for the underlying database connection.

func (ORM) AutoMigrate

func (orm ORM) AutoMigrate(models []interface{}) error

AutoMigrate performs database migration for all Model types provided.

func (ORM) Begin

func (orm ORM) Begin() *gorm.DB

Begin starts a new database transaction.

func (ORM) Create

func (orm ORM) Create(model interface{}) *gorm.DB

Create inserts a new model instance into the database.

func (ORM) Exec

func (orm ORM) Exec(query string, output interface{}) *gorm.DB

Exec performs a raw SQL query against the underlying database.

func (ORM) First

func (orm ORM) First(model interface{}, where ...interface{}) *gorm.DB

First returns the first model (ordered by ID) that matches the specified query.

func (ORM) Last

func (orm ORM) Last(model interface{}, where ...interface{}) *gorm.DB

Last returns the last model (ordered by ID) that matches the specified query.

func (ORM) Model

func (orm ORM) Model(model interface{}) *gorm.DB

Model specifies the domain model that subsequent queries will be run against.

func (ORM) ModelExistsWithID

func (orm ORM) ModelExistsWithID(model interface{}, id uint) (bool, error)

ModelExistsWithID returns a boolean indicating if an instance of the specified model exists with a given ID.

func (ORM) ModelWithID

func (orm ORM) ModelWithID(model interface{}, id uint) error

ModelWithID returns an instance of the specified model with the given ID.

func (*ORM) Open

func (orm *ORM) Open(dialect, connectionString string) (*gorm.DB, error)

Open creates a database connection, or returns an existing one if present.

func (ORM) Save

func (orm ORM) Save(value interface{}) *gorm.DB

Save updates a model with the given attributes.

func (ORM) Where

func (orm ORM) Where(query interface{}, args ...interface{}) *gorm.DB

Where performs a query with "Where" parameters.

Jump to

Keyboard shortcuts

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