database

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Begin() (Tx, error)
	Prepare(query string) (stmt *sql.Stmt, err error)
	Exec(query string, args ...interface{}) (result sql.Result, err error)
	Query(query string, args ...interface{}) (rows *sql.Rows, err error)
	Close()

	NewTable(content interface{}, tableName string) (table Table, err error)
}

func NewDatabase

func NewDatabase(driverName string, dataSourceName string) (Database, error)

type PrimaryKey

type PrimaryKey struct {
	Id int `json:"id" db:"id" db_index:"primary" db_omit:"create,update"`
}

type Resource

type Resource struct {
	PrimaryKey
	Name       string `json:"name" db:"name" db_type:"VARCHAR(256)" db_default:"''"`
	Creator    string `json:"creator" db:"creator" db_omit:"update" db_type:"VARCHAR(256)" db_default:"''"`
	Updater    string `json:"updater" db:"updater" db_type:"VARCHAR(256)" db_default:"''"`
	CreateTime string `json:"createTime" db:"createTime" db_omit:"create,update" db_type:"DATETIME" db_default:"CURRENT_TIMESTAMP"`
	UpdateTime string `json:"updateTime" db:"updateTime" db_omit:"create" db_type:"DATETIME" db_default:"CURRENT_TIMESTAMP"`
}

type Table

type Table interface {
	Database() Database
	TableName() string

	GetList(whereSql string, args ...interface{}) (values []interface{}, err error)
	Get(whereSql string, args ...interface{}) (values interface{}, err error)
	Create(data interface{}) (sql.Result, error)
	Update(data interface{}, whereSql string, args ...interface{}) (sql.Result, error)
	Delete(whereSql string, args ...interface{}) (sql.Result, error)
}

type Tx

type Tx interface {
	Commit() error
	Rollback() error
	Exec(query string, args ...interface{}) (sql.Result, error)
}

Jump to

Keyboard shortcuts

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