dbstorage

package module
v0.0.0-...-7245913 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: MIT Imports: 19 Imported by: 8

README

go.dbstorage

loc license discord paypal goreportcard codefactor

Dynamic SQL library for Go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StatementDebug bool
	DebugVerbose   bool
)

flag vars

View Source
var (
	// InsertsLock - use this so that Database.QueryNextID and DataBase.Build.Ins happen in an atomic fashion.
	InsertsLock = new(sync.Mutex)
)

Functions

func QueryHasRows

func QueryHasRows(query *sql.Rows) bool

QueryHasRows checks if a Rows response contains any values, and then closes the query.

func ScanStream

func ScanStream(qb QueryBuilder, s Scannable, f func(Scannable))

Types

type Database

type Database interface {
	Inner
	CreateTableStruct(name string, v interface{})
}

Database represents an active db connection

func ConnectMysql

func ConnectMysql() (Database, error)

ConnectMysql does

func ConnectPostgres

func ConnectPostgres() (Database, error)

ConnectPostgres does

func ConnectSqlite

func ConnectSqlite(path string) (Database, error)

type DbProxy

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

func (*DbProxy) Build

func (db *DbProxy) Build() QueryBuilder

func (*DbProxy) Close

func (db *DbProxy) Close() error

func (*DbProxy) CreateTable

func (db *DbProxy) CreateTable(name string, pk []string, columns [][]string)

func (*DbProxy) DB

func (db *DbProxy) DB() *sql.DB

func (*DbProxy) DoesTableExist

func (db *DbProxy) DoesTableExist(table string) bool

func (*DbProxy) DriverName

func (db *DbProxy) DriverName() string

func (*DbProxy) DropTable

func (db *DbProxy) DropTable(name string)

func (*DbProxy) IntPrimaryKey

func (db *DbProxy) IntPrimaryKey() string

func (*DbProxy) Ping

func (db *DbProxy) Ping() error

func (*DbProxy) QueryColumnList

func (db *DbProxy) QueryColumnList(table string) []string

func (*DbProxy) QueryNextID

func (db *DbProxy) QueryNextID(table string) int64

func (*DbProxy) QueryPrepared

func (db *DbProxy) QueryPrepared(modify bool, q string, args ...interface{}) *sql.Rows

func (*DbProxy) QueryRowCount

func (db *DbProxy) QueryRowCount(table string) int64

func (*DbProxy) QueryTableInfo

func (db *DbProxy) QueryTableInfo(table string) []PragmaTableInfo

func (*DbProxy) TagName

func (db *DbProxy) TagName() string

func (*DbProxy) TypeForType

func (db *DbProxy) TypeForType(t reflect.Type) string

type Executable

type Executable interface {
	Exe() *sql.Rows
}

Executable is any object who represents a query that can be called on to produce a sql.Rows

type Inner

type Inner interface {
	Ping() error
	Close() error
	DB() *sql.DB
	CreateTable(name string, pk []string, columns [][]string)
	DoesTableExist(table string) bool
	Build() QueryBuilder
	QueryColumnList(table string) []string
	QueryNextID(table string) int64
	QueryRowCount(table string) int64
	DropTable(name string)
	DriverName() string
	TagName() string
	IntPrimaryKey() string
	TypeForType(reflect.Type) string
}

type Outer

type Outer struct {
	Inner
}

func (*Outer) CreateTableStruct

func (db *Outer) CreateTableStruct(name string, v interface{})

type PragmaTableInfo

type PragmaTableInfo struct {
	CID        int
	Name       string
	Type       string
	NotNull    bool
	HasDefault bool
	HasPK      bool
}

type QueryBuilder

type QueryBuilder interface {
	Se(cols string) QueryBuilder
	Fr(tabls string) QueryBuilder
	WR(col string, op string, value string, raw bool, ags ...interface{}) QueryBuilder
	Wr(col string, op string, value string) QueryBuilder
	Wh(col string, value string) QueryBuilder
	Or(col string, order string) QueryBuilder
	Lm(limit int64) QueryBuilder
	Of(offset int64) QueryBuilder
	Up(table string, col string, value string) QueryBuilder
	Ins(table string, values ...interface{}) Executable
	InsI(table string, strct interface{}) Executable
	Del(table string) QueryBuilder
	Executable
}

type Scannable

type Scannable interface {
	Scan(rows *sql.Rows) Scannable
}

Scannable can take in Rows and return an object

func ScanAll

func ScanAll(qb QueryBuilder, s Scannable) []Scannable

ScanAll scans all possible values of a QueryBuilder into an array based on template Scannable.

func ScanFirst

func ScanFirst(qb QueryBuilder, s Scannable) Scannable

ScanFirst scans the first value from the QueryBuilder, then closes the query.

Jump to

Keyboard shortcuts

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