database

package
v0.0.0-...-6b835ca Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DropDB

func DropDB(database *Database) error

DropDB Drop database schemas

func InstallDB

func InstallDB(database *Database) error

InstallDB Database schemas installer

func ToJSON

func ToJSON(model DBInterface) string

ToJSON Converting models belonging to DBInterface to json string

func ValidateConstraint

func ValidateConstraint(err error, r interface{}) (map[string]string, error)

ValidateConstraint sql violation error validator

func ValidateStruct

func ValidateStruct(r interface{}) (map[string]string, error)

ValidateStruct struct validator

Types

type Change

type Change struct {
	Key     string
	Name    string
	String  string
	Int     int64
	Bool    bool
	Decimal decimal.Decimal
}

Change database model compare and change

func GetChanges

func GetChanges(m interface{}, c interface{}, typs ...string) ([]Change, []string, map[string]interface{})

GetChanges Get repo model changes

type DBInterface

type DBInterface interface {
	TableName() string
	ToJSON() string
}

DBInterface database model interface

type Database

type Database struct {
	Config    *model.Config
	Type      model.DB
	DB        *sqlx.DB
	Tx        *sqlx.Tx
	Logger    *utils.Logger
	Error     error
	Reset     bool
	QueryType string
}

Database struct

func NewDB

func NewDB(config *model.Config, connURL ...string) (*Database, error)

NewDB building database

func (*Database) Delete

func (d *Database) Delete(table string, whereClause string, args ...interface{}) Result

Delete query build by database type

func (Database) Force

func (d Database) Force() Database

Force raise panic database query result is nil

func (*Database) Insert

func (d *Database) Insert(m DBInterface, data interface{}, keys ...string) error

Insert query builder by database type

func (*Database) Query

func (d *Database) Query(query string, params ...interface{}) Result

Query database query builder

func (*Database) QueryRow

func (d *Database) QueryRow(query string, params ...interface{}) Result

QueryRow database row query builder

func (*Database) QueryRowWithModel

func (d *Database) QueryRowWithModel(query string, target interface{}, params ...interface{}) Result

QueryRowWithModel database row query builder with target model

func (*Database) QueryWithModel

func (d *Database) QueryWithModel(query string, target interface{}, params ...interface{}) Result

QueryWithModel database query builder with given model

func (*Database) Transaction

func (d *Database) Transaction(cb func(tx *Tx) error) *Database

Transaction database tx builder

func (*Database) Update

func (d *Database) Update(m DBInterface, data interface{}, whereClause *string, keys ...string) error

Update query builder by database type

type Error

type Error int

Error for database violation errors

const (
	// TableNotFound sql violation code
	TableNotFound Error = 1
	// OtherError unhandled sql violation codes
	OtherError Error = 0
	// InternalError SQLite Error
	InternalError Error = 1
)

type Postgres

type Postgres string

Postgres type for postgres contants

const (
	// UniqueViolation sql unique violation code
	UniqueViolation Postgres = "23505"
	// ForeignKeyViolation sql foreign key violation code
	ForeignKeyViolation Postgres = "23503"
	// NotNullViolation sql not null violation code
	NotNullViolation Postgres = "23502"
)

type Result

type Result struct {
	QueryType string
	Rows      []interface{}
	Count     int64
	Error     error
}

Result structure for database query results

func (Result) Force

func (r Result) Force() Result

Force raise panic database query result is nil

type Tables

type Tables string

Tables db table enum type

type Tag

type Tag struct {
	Name       string
	Constraint string
}

Tag error constraint structure

type Tx

type Tx struct {
	DB *Database
}

Tx transaction for database queries

func (*Tx) Select

func (t *Tx) Select(table string, whereClause string) Result

Select query builder by database type.

type Violation

type Violation string

Violation type for violation constants

const (
	// UniqueError unique violation error string
	UniqueError Violation = "has been already taken"
	// NotExistsError not exists violation error string
	NotExistsError Violation = "does not exists"
	// NotNullError not null violation error string
	NotNullError Violation = "is not null"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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