db

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Models []interface{}

Models stores the current set of application models.

Functions

func AddModels

func AddModels(models ...interface{})

AddModels add the given models to the model list.

func Open

func Open()

Open opens a new database connection.

Types

type DB

type DB struct {
	*gorm.DB
}

DB represents the database structure used

var Builder *DB

Builder represents the current database used.

func (*DB) All

func (b *DB) All(models interface{}, where ...interface{}) *DB

All finds all records of a given model

func (*DB) Count

func (b *DB) Count() interface{}

Count 's the database records in the given table

func (*DB) Create

func (b *DB) Create(value interface{}) *DB

Create insert the value into database

func (*DB) Delete

func (b *DB) Delete(value interface{}, where ...interface{}) *DB

Delete delete value match given conditions, if the value has primary key, then will including the primary key as condition

func (*DB) First

func (b *DB) First(out interface{}, where ...interface{}) *DB

First finds the first record with the given condition

func (*DB) Group

func (b *DB) Group(query string) *DB

Group specify the group method on the find

func (*DB) Having

func (b *DB) Having(query string) *DB

Having specify HAVING conditions for GROUP BY

func (*DB) IsNew

func (b *DB) IsNew(model interface{}) bool

IsNew checks if the model was already saved

func (*DB) Last

func (b *DB) Last(out interface{}, where ...interface{}) *DB

Last finds the last record with the given condition

func (*DB) Limit

func (b *DB) Limit(limit interface{}) *DB

Limit adds a limit to the query

func (*DB) Model

func (b *DB) Model(value interface{}) *DB

Model specify the model you would like to run db operations

func (*DB) OrWhere

func (b *DB) OrWhere(query interface{}, args ...interface{}) *DB

OrWhere adds an or filter to the query

func (*DB) Save

func (b *DB) Save(value interface{}) *DB

Save update value in database, if the value doesn't have primary key, will insert it

func (*DB) Scan

func (b *DB) Scan(dest interface{}) *DB

Scan scan value to a struct

func (*DB) Select

func (b *DB) Select(query interface{}, args ...interface{}) *DB

Select specifies field you want to query from the database

func (*DB) Skip

func (b *DB) Skip(skip interface{}) *DB

Skip adds an offset to the query

func (*DB) Table

func (b *DB) Table(name string) *DB

Table specify the table you would like to run db operations

func (*DB) Unscoped

func (b *DB) Unscoped() *DB

Unscoped return all record including deleted record

func (*DB) Update

func (b *DB) Update(attrs ...interface{}) *DB

Update update attributes with callbacks

func (*DB) Updates

func (b *DB) Updates(values interface{}, ignoreProtectedAttrs ...bool) *DB

Updates update attributes with callbacks

func (*DB) Where

func (b *DB) Where(query interface{}, args ...interface{}) *DB

Where adds a condition to the query statement

func (*DB) WhereNot

func (b *DB) WhereNot(query interface{}, args ...interface{}) *DB

WhereNot adds a condition to the query statement

type Model

type Model struct {
	ID        uint       `json:"id,omitempty" gorm:"primary_key"`
	CreatedAt time.Time  `json:"created_at,omitempty"`
	UpdatedAt time.Time  `json:"updated_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty" sql:"index"`
}

Model represents the base database model.

Jump to

Keyboard shortcuts

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