db

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2018 License: CC0-1.0 Imports: 11 Imported by: 0

README

Database migrations

Creating a new migration

To create a new SQL migration script issue the following command

goose create AddSomeColumn sql

Synchronization

Each time the API server is executed it will use the provided database connection information and attempt to synchronize migrations as needed. Essentially it is similar to executing the following commands with some additional logic:

goose dbversion
goose up

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentVersion

func CurrentVersion(directory, environment, schema string) (int64, error)

CurrentVersion gets the database current version according to the migration status

func MigrateUp

func MigrateUp(directory, environment, schema string) error

MigrateUp attempts to push any pending updates to the database

Types

type DatabaseContext

type DatabaseContext struct {
	Database *pg.DB
}

DatabaseContext to help abstract the technical implementation per driver used.

func NewDB

func NewDB() *DatabaseContext

NewDB establishes a new database connection

func (*DatabaseContext) CheckTable

func (context *DatabaseContext) CheckTable(entity interface{}) error

CheckTable ensures a the table exists for the persistor.

func (*DatabaseContext) Delete

func (context *DatabaseContext) Delete(query interface{}) error

Delete removes the model from the data store

func (*DatabaseContext) Find

func (context *DatabaseContext) Find(query interface{}, callback func(query interface{}))

Find will check if the model exists and run the additional functionality.

func (*DatabaseContext) Insert

func (context *DatabaseContext) Insert(query ...interface{}) error

Insert persists the new model in the data store

func (*DatabaseContext) Raw

func (context *DatabaseContext) Raw(query interface{}, params ...interface{}) error

Raw executes a string of SQL.

func (*DatabaseContext) Save

func (context *DatabaseContext) Save(query ...interface{}) error

Save persists the model in the data store

func (*DatabaseContext) Select

func (context *DatabaseContext) Select(query interface{}) error

Select returns the model from the data store

func (*DatabaseContext) Update

func (context *DatabaseContext) Update(query interface{}) error

Update persists the existing model in the data store

Jump to

Keyboard shortcuts

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