dbx

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 8 Imported by: 0

README

go-dbx

A database helper for golang

Documentation

Index

Constants

View Source
const (
	DRIVER_SQLITE3 = "sqlite3"
	DRIVER_MYSQL   = "mysql"
	DRIVER_POSTGRE = "postgre"
)

Variables

This section is empty.

Functions

func SetLogger added in v0.1.1

func SetLogger(logger func(string))

Types

type Column

type Column struct {
	Name            string
	FormName        string
	Index           int
	Sqlite          string
	Mysql           string
	Postgre         string
	IsPrimaryKey    bool
	IsAutoIncrement bool
}

type Database

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

func NewDatabase

func NewDatabase() *Database

func (*Database) Begin

func (this *Database) Begin() (*Transaction, error)

func (*Database) Close

func (this *Database) Close()

func (*Database) CreateTable

func (this *Database) CreateTable(name string) error

func (*Database) CreateTables

func (this *Database) CreateTables() error

func (*Database) DB

func (this *Database) DB() *sql.DB

func (*Database) DriverName

func (this *Database) DriverName() string

func (*Database) DropTable

func (this *Database) DropTable(name string) error

func (*Database) GetTableSchema added in v0.1.3

func (this *Database) GetTableSchema(name string) (Table, error)

func (*Database) Open

func (this *Database) Open(driver, dsn string) error

func (*Database) OpenMySQL

func (this *Database) OpenMySQL(dbName, user, passwd, host string, port int) error

func (*Database) OpenSQLite

func (this *Database) OpenSQLite(dbFile string) error

func (*Database) RegisterTable

func (this *Database) RegisterTable(name string, table interface{}) error

func (*Database) T

func (this *Database) T(name string) *SQLExecutor

type SQLExecutor

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

SQLExecutor

func (*SQLExecutor) Count

func (this *SQLExecutor) Count(where string, args ...interface{}) (int, error)

Count counts rows by given filter

func (*SQLExecutor) CountAll

func (this *SQLExecutor) CountAll() (int, error)

CountAll counts all rows of table

func (*SQLExecutor) Delete

func (this *SQLExecutor) Delete(where string, args ...interface{}) error

Delete deletes rows by given filter

func (*SQLExecutor) Insert

func (this *SQLExecutor) Insert(row interface{}) (sql.Result, error)

Insert inserts given row to table

func (*SQLExecutor) Replace

func (this *SQLExecutor) Replace(row interface{}) (sql.Result, error)

Replace replaces with given row

func (*SQLExecutor) Select

func (this *SQLExecutor) Select(cols ...string) *SQLSelector

Select selects the given columns from table

func (*SQLExecutor) SelectAll

func (this *SQLExecutor) SelectAll() *SQLSelector

SelectAll selects all columns from table

func (*SQLExecutor) Update

func (this *SQLExecutor) Update(where string, args ...interface{}) *SQLUpdater

Update updates row by given filter

type SQLJointer

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

func (*SQLJointer) All

func (this *SQLJointer) All(rows ...interface{}) error

func (*SQLJointer) Asc

func (this *SQLJointer) Asc(cols ...string) *SQLJointer

Asc sorts given columns by asc

func (*SQLJointer) Desc

func (this *SQLJointer) Desc(cols ...string) *SQLJointer

Desc sorts given columns by desc

func (*SQLJointer) Filter

func (this *SQLJointer) Filter(where string, args ...interface{}) *SQLJointer

Filter set filters for select

func (*SQLJointer) FullJoin

func (this *SQLJointer) FullJoin(table, onLeft, onRight string) jointer

func (*SQLJointer) FullOuterJoin

func (this *SQLJointer) FullOuterJoin(table, onLeft, onRight string) jointer

func (*SQLJointer) InnerJoin

func (this *SQLJointer) InnerJoin(table, onLeft, onRight string) jointer

func (*SQLJointer) LeftJoin

func (this *SQLJointer) LeftJoin(
	table, onLeft, onRight, onWhere string,
) jointer

func (*SQLJointer) LeftOuterJoin

func (this *SQLJointer) LeftOuterJoin(table, onLeft, onRight string) jointer

func (*SQLJointer) Limit

func (this *SQLJointer) Limit(n int) *SQLJointer

Limit sets limit of query

func (*SQLJointer) Offset

func (this *SQLJointer) Offset(n int) *SQLJointer

Offset sets offset of query

func (*SQLJointer) One

func (this *SQLJointer) One(rows ...interface{}) error

func (*SQLJointer) RightJoin

func (this *SQLJointer) RightJoin(
	table, onLeft, onRight, onWhere string,
) jointer

func (*SQLJointer) RightOuterJoin

func (this *SQLJointer) RightOuterJoin(table, onLeft, onRight string) jointer

func (*SQLJointer) Run

func (this *SQLJointer) Run() (*sql.Rows, error)

type SQLSelector

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

SQLSelector

func (*SQLSelector) All

func (this *SQLSelector) All(rows interface{}) error

All selects all rows from table

func (*SQLSelector) Asc

func (this *SQLSelector) Asc(cols ...string) *SQLSelector

Asc sorts given columns by asc

func (*SQLSelector) Desc

func (this *SQLSelector) Desc(cols ...string) *SQLSelector

Desc sorts given columns by desc

func (*SQLSelector) Filter

func (this *SQLSelector) Filter(where string, args ...interface{}) *SQLSelector

Filter set filters for select

func (*SQLSelector) FullJoin

func (this *SQLSelector) FullJoin(table, onLeft, onRight string) jointer

func (*SQLSelector) FullOuterJoin

func (this *SQLSelector) FullOuterJoin(table, onLeft, onRight string) jointer

func (*SQLSelector) InnerJoin

func (this *SQLSelector) InnerJoin(table, onLeft, onRight string) jointer

func (*SQLSelector) LeftJoin

func (this *SQLSelector) LeftJoin(table, onLeft, onRight string) jointer

func (*SQLSelector) LeftOuterJoin

func (this *SQLSelector) LeftOuterJoin(table, onLeft, onRight string) jointer

func (*SQLSelector) Limit

func (this *SQLSelector) Limit(n int) *SQLSelector

Limit sets limit of query

func (*SQLSelector) Offset

func (this *SQLSelector) Offset(n int) *SQLSelector

Offset sets offset of query

func (*SQLSelector) One

func (this *SQLSelector) One(row interface{}) error

One selects one row from table

func (*SQLSelector) RightJoin

func (this *SQLSelector) RightJoin(table, onLeft, onRight string) jointer

func (*SQLSelector) RightOuterJoin

func (this *SQLSelector) RightOuterJoin(table, onLeft, onRight string) jointer

func (*SQLSelector) Run

func (this *SQLSelector) Run() (*sql.Rows, error)

func (*SQLSelector) Values

func (this *SQLSelector) Values(values ...interface{}) error

One selects one row from table

type SQLUpdater

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

SQLUpdater

func (*SQLUpdater) Set

func (this *SQLUpdater) Set(cols ...string) *SQLUpdater

Set sets columns to be updated

func (*SQLUpdater) Value

func (this *SQLUpdater) Value(row interface{}) (sql.Result, error)

Value updates given row to table

func (*SQLUpdater) ValueMap added in v0.1.4

func (this *SQLUpdater) ValueMap(valMap map[string]interface{}) (
	sql.Result, error)

func (*SQLUpdater) Values

func (this *SQLUpdater) Values(values ...interface{}) (sql.Result, error)

Values updates given values to table

type Table

type Table struct {
	Name    string
	Columns map[string]Column
}

func (*Table) ColumnIndexes

func (this *Table) ColumnIndexes() []int

func (*Table) ColumnNames

func (this *Table) ColumnNames() []string

func (*Table) CreateSQL

func (this *Table) CreateSQL(driver string) (string, error)

func (*Table) GetColumnsFromForm added in v0.1.2

func (this *Table) GetColumnsFromForm(r *http.Request) (
	[]string, []interface{}, error)

func (*Table) GetColumnsMapFromForm added in v0.1.4

func (this *Table) GetColumnsMapFromForm(r *http.Request) (
	map[string]interface{}, error)

func (*Table) Parse

func (this *Table) Parse(name string, table interface{}) error

type Transaction

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

Database Transaction

func (*Transaction) Commit

func (this *Transaction) Commit() error

func (*Transaction) Rollback

func (this *Transaction) Rollback() error

func (*Transaction) T

func (this *Transaction) T(name string) *SQLExecutor

func (*Transaction) Tx

func (this *Transaction) Tx() *sql.Tx

Jump to

Keyboard shortcuts

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