jsql

package
v1.3.25 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 18 Imported by: 12

Documentation

Index

Constants

View Source
const (
	Unknown = -1
)

Variables

This section is empty.

Functions

func DisableEnv

func DisableEnv()

DisableEnv disable env

func EnableEnv

func EnableEnv()

EnableEnv enable env

func EnvKey

func EnvKey() string

EnvKey returns env key

func EnvVal

func EnvVal() string

EnvVal returns env value

func GetDaoPath

func GetDaoPath() string

GetDaoPath returns conf.DaoPath

func GetDataSource added in v1.2.2

func GetDataSource() map[string]interface{}

GetDataSource returns json data source

func GetDefaultDataSource

func GetDefaultDataSource() string

GetDefaultDataSource returns json default data source

func Init

func Init() error

Init initialize

func SetDecodeFunc

func SetDecodeFunc(f func(string) (string, error))

SetDecodeFunc set decode data source name or data source json string function

func SetEnvFileName

func SetEnvFileName(name string)

SetEnvFileName set config env file name

func SetEnvKey

func SetEnvKey(key string)

SetEnvKey set env key

func SetEnvVal

func SetEnvVal(val string)

SetEnvVal set env value

func SetFileName

func SetFileName(name string)

SetFileName set config file name

func SetFormat

func SetFormat(f jfile.Format)

SetFormat set config format

func SetRoot added in v1.2.1

func SetRoot(root string)

SetRoot set config root path

func SubscribeSql added in v1.1.1

func SubscribeSql(e jevent.Event) jevent.Subscription

SubscribeSql subscribe sql event

Types

type Agent

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

func GetAgent

func GetAgent(dsKey ...string) (*Agent, error)

GetAgent returns SqlAgent if not input data source key then return default data source agent

func (*Agent) Begin

func (a *Agent) Begin() (*sql.Tx, error)

Begin same as sql.DB.Begin

func (*Agent) Commit

func (a *Agent) Commit() error

Commit same as sql.Tx.Commit

func (*Agent) Count added in v1.3.16

func (a *Agent) Count(id string, args ...interface{}) (count int, err error)

Count return query count

func (*Agent) CountTx added in v1.3.16

func (a *Agent) CountTx(id string, args ...interface{}) (count int, err error)

CountTx return query count

func (*Agent) DB

func (a *Agent) DB() *sql.DB

DB returns this Agent *sql.DB

func (*Agent) DBType

func (a *Agent) DBType() Type

DBType returns this Agent db Type

func (*Agent) DbName added in v1.2.2

func (a *Agent) DbName() string

DbName returns this Agent db name

func (*Agent) Delete

func (a *Agent) Delete(id string, args ...interface{}) (result Result, err error)

Delete executes a query with db.Exec

func (*Agent) DeletePrepare

func (a *Agent) DeletePrepare(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

DeletePrepare creates a prepared statement for later queries or executions

func (*Agent) DeletePrepareTx

func (a *Agent) DeletePrepareTx(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

DeletePrepareTx creates a prepared statement for later queries or executions

func (*Agent) DeleteSqlAndArgs added in v1.3.16

func (a *Agent) DeleteSqlAndArgs(id string, args ...interface{}) (string, []interface{}, error)

DeleteSqlAndArgs returns delete sql and args

func (*Agent) DeleteTx

func (a *Agent) DeleteTx(id string, args ...interface{}) (result Result, err error)

DeleteTx executes a query with tx.Exec

func (*Agent) ExecTxWithSql

func (a *Agent) ExecTxWithSql(query string, cond ...interface{}) (Result, error)

ExecTxWithSql executes a query with tx.Exec

func (*Agent) ExecWithSql

func (a *Agent) ExecWithSql(query string, cond ...interface{}) (Result, error)

ExecWithSql executes a query with db.Exec

func (*Agent) Exists added in v1.3.16

func (a *Agent) Exists(id string, args ...interface{}) (exists bool, err error)

Exists return query sql exists data

func (*Agent) ExistsTx added in v1.3.16

func (a *Agent) ExistsTx(id string, args ...interface{}) (exists bool, err error)

ExistsTx return query sql exists data

func (*Agent) Insert

func (a *Agent) Insert(id string, args ...interface{}) (result Result, err error)

Insert executes a query with db.Exec

func (*Agent) InsertPrepare

func (a *Agent) InsertPrepare(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

InsertPrepare creates a prepared statement for later queries or executions

func (*Agent) InsertPrepareTx

func (a *Agent) InsertPrepareTx(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

InsertPrepareTx creates a prepared statement for later queries or executions

func (*Agent) InsertSqlAndArgs added in v1.3.16

func (a *Agent) InsertSqlAndArgs(id string, args ...interface{}) (string, []interface{}, error)

InsertSqlAndArgs returns insert sql and args

func (*Agent) InsertTx

func (a *Agent) InsertTx(id string, args ...interface{}) (result Result, err error)

InsertTx executes a query with tx.Exec

func (*Agent) InsertTxWithLastInsertId added in v1.3.16

func (a *Agent) InsertTxWithLastInsertId(id string, args ...interface{}) (lastInsertId int, err error)

InsertTxWithLastInsertId return last insert id by QueryRow.Scan

func (*Agent) InsertWithLastInsertId added in v1.3.16

func (a *Agent) InsertWithLastInsertId(id string, args ...interface{}) (lastInsertId int, err error)

InsertWithLastInsertId return last insert id by QueryRow.Scan

func (*Agent) Other

func (a *Agent) Other(id string, args ...interface{}) (result Result, err error)

Other executes a query with db.Exec

func (*Agent) OtherPrepare

func (a *Agent) OtherPrepare(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

OtherPrepare creates a prepared statement for later queries or executions

func (*Agent) OtherPrepareTx

func (a *Agent) OtherPrepareTx(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

OtherPrepareTx creates a prepared statement for later queries or executions

func (*Agent) OtherSqlAndArgs added in v1.3.16

func (a *Agent) OtherSqlAndArgs(id string, args ...interface{}) (string, []interface{}, error)

OtherSqlAndArgs returns other sql and args

func (*Agent) OtherTx

func (a *Agent) OtherTx(id string, args ...interface{}) (result Result, err error)

OtherTx executes a query with tx.Exec

func (*Agent) Ping

func (a *Agent) Ping() error

Ping same as sql.DB.Ping if db does not open, will call open before begin

func (*Agent) Query

func (a *Agent) Query(id string, args ...interface{}) (result Result, err error)

Query executes a query that returns Result the id are for xml select tag id the args are for any placeholder parameters in the query, or result struct point

func (*Agent) QueryPage

func (a *Agent) QueryPage(id string, start, end int64, args ...interface{}) (Result, error)

QueryPage executes a query that returns Result the id are for xml select tag id the start and end are for query start row and end row the args are for any placeholder parameters in the query, or result struct point

func (*Agent) QueryPageTx

func (a *Agent) QueryPageTx(id string, start, end int64, args ...interface{}) (Result, error)

QueryPageTx executes a query that returns Result the id are for xml select tag id the start and end are for query start row and end row the args are for any placeholder parameters in the query, or result struct point

func (*Agent) QueryPageTxWithSql

func (a *Agent) QueryPageTxWithSql(query, order string, start, end int64, args ...interface{}) (Result, error)

QueryPageTxWithSql executes a query that returns Result the start and end are for query start row and end row

func (*Agent) QueryPageWithSql

func (a *Agent) QueryPageWithSql(query, order string, start, end int64, args ...interface{}) (Result, error)

QueryPageWithSql executes a query that returns Result the start and end are for query start row and end row

func (*Agent) QueryPrepare

func (a *Agent) QueryPrepare(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

QueryPrepare creates a prepared statement for later queries or executions

func (*Agent) QueryPrepareTx

func (a *Agent) QueryPrepareTx(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

QueryPrepareTx creates a prepared statement for later queries or executions

func (*Agent) QueryRow

func (a *Agent) QueryRow(id string, args ...interface{}) (result Result, err error)

QueryRow executes a query that is expected to return at most one row the id are for xml select tag id the args are for any placeholder parameters in the query, or result struct point

func (*Agent) QueryRowPrepare

func (a *Agent) QueryRowPrepare(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

QueryRowPrepare creates a prepared statement for later queries or executions

func (*Agent) QueryRowPrepareTx

func (a *Agent) QueryRowPrepareTx(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

QueryRowPrepareTx creates a prepared statement for later queries or executions

func (*Agent) QueryRowTx

func (a *Agent) QueryRowTx(id string, args ...interface{}) (result Result, err error)

QueryRowTx executes a query that is expected to return at most one row the id are for xml select tag id the args are for any placeholder parameters in the query, or result struct point

func (*Agent) QueryRowTxWithSql

func (a *Agent) QueryRowTxWithSql(query string, cond ...interface{}) (Result, error)

QueryRowTxWithSql executes a query that is expected to return at most one row

func (*Agent) QueryRowWithSql

func (a *Agent) QueryRowWithSql(query string, cond ...interface{}) (Result, error)

QueryRowWithSql executes a query that is expected to return at most one row

func (*Agent) QuerySqlAndArgs added in v1.3.16

func (a *Agent) QuerySqlAndArgs(id string, args ...interface{}) (string, []interface{}, error)

QuerySqlAndArgs returns query sql and args

func (*Agent) QueryTx

func (a *Agent) QueryTx(id string, args ...interface{}) (result Result, err error)

QueryTx executes a query that returns Result the id are for xml select tag id the args are for any placeholder parameters in the query, or result struct point

func (*Agent) QueryTxWithSql

func (a *Agent) QueryTxWithSql(query string, cond ...interface{}) (Result, error)

QueryTxWithSql executes a query that returns Result

func (*Agent) QueryWithSql

func (a *Agent) QueryWithSql(query string, cond ...interface{}) (Result, error)

QueryWithSql executes a query that returns Result

func (*Agent) Rollback

func (a *Agent) Rollback() error

Rollback same as sql.Tx.Rollback

func (*Agent) TableSchema added in v1.2.2

func (a *Agent) TableSchema(table string, args ...interface{}) ([]TableSchema, error)

TableSchema return table schema or you can use args input query statement

func (*Agent) TableSchemaTx added in v1.2.2

func (a *Agent) TableSchemaTx(table string, args ...interface{}) ([]TableSchema, error)

TableSchemaTx return table schema or you can use args input query statement

func (*Agent) Tables added in v1.2.2

func (a *Agent) Tables(args ...interface{}) ([]string, error)

Tables returns table name list or you can use args input query statement

func (*Agent) TablesTx added in v1.2.2

func (a *Agent) TablesTx(args ...interface{}) ([]string, error)

TablesTx returns table name list or you can use args input query statement

func (*Agent) Tx

func (a *Agent) Tx() *sql.Tx

Tx returns this Agent *sql.Tx

func (*Agent) Update

func (a *Agent) Update(id string, args ...interface{}) (result Result, err error)

Update executes a query with db.Exec

func (*Agent) UpdatePrepare

func (a *Agent) UpdatePrepare(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

UpdatePrepare creates a prepared statement for later queries or executions

func (*Agent) UpdatePrepareTx

func (a *Agent) UpdatePrepareTx(id string, param map[string]interface{}, args ...[]interface{}) (result []Result, err error)

UpdatePrepareTx creates a prepared statement for later queries or executions

func (*Agent) UpdateSqlAndArgs added in v1.3.16

func (a *Agent) UpdateSqlAndArgs(id string, args ...interface{}) (string, []interface{}, error)

UpdateSqlAndArgs returns update sql and args

func (*Agent) UpdateTx

func (a *Agent) UpdateTx(id string, args ...interface{}) (result Result, err error)

UpdateTx executes a query with tx.Exec

func (*Agent) UseTx added in v1.2.2

func (a *Agent) UseTx(f func() error) error

UseTx start a transaction as a block, return error will roll back, otherwise to commit

type Logic

type Logic int

Logic clause Logic

const (
	And Logic = iota
	Or
)

func (Logic) String

func (l Logic) String() string

String returns Logic string

type Operations

type Operations int

Operations sql operations

const (
	Select Operations = iota
	Insert
	Update
	Delete
	Other
)

func (Operations) String

func (o Operations) String() string

String returns Operations string

type Operators

type Operators int

Operators clause Operators

const (
	Equal Operators = iota
	NotEqual
	In
	NotIn
	Between
	NotBetween
	IsNull
	IsNotNull
	Like
	SLike
	ELike
	Greater
	GreaterThanOrEqual
	Less
	LessThanOrEqual
)

func ParseOperators

func ParseOperators(o string) (Operators, error)

ParseOperators takes a string Operators and returns the Operators constant.

func (Operators) String

func (o Operators) String() string

String returns Operators string

type Param

type Param struct {
	Logic       Logic
	Col         string
	Val         interface{}
	Opr         Operators
	ParamsLogic Logic
	Params      []*Param
}

func (*Param) AddParam

func (p *Param) AddParam(param *Param)

AddParam add Param to this Param.Params array

type Result

type Result interface {
	// Row returns query row data
	// if multiple row then return first row data
	Row() map[string]interface{}
	// Rows returns query rows data
	Rows() []map[string]interface{}
	// RowStart returns the integer by query page start row number
	// if not query page, the value default zero
	RowStart() int64
	// RowEnd returns the integer by query page end row number
	// if not query page, the value default zero
	RowEnd() int64
	// TotalRecord returns query page total record
	// the other query then returns rows length
	TotalRecord() int64
	// LastInsertId returns the integer generated by the database
	// in response to a command. Typically this will be from an
	// "auto increment" column when inserting a new row. Not all
	// databases support this feature, and the syntax of such
	// statements varies.
	LastInsertId() (int64, error)
	// RowsAffected returns the number of rows affected by an
	// update, insert, or delete. Not every database or database
	// driver may support this.
	RowsAffected() (int64, error)
}

type TableAgent

type TableAgent struct {
	Agent  *Agent
	DSKey  string
	Table  string
	SelStr string
	OrdStr string
	Col    map[string]interface{}
	Params []*Param
}

func (*TableAgent) AddColumn

func (ta *TableAgent) AddColumn(args ...interface{}) error

AddColumn add insert or update column data

func (*TableAgent) AddMap

func (ta *TableAgent) AddMap(m map[string]interface{})

AddMap add insert or update column data with map[string]interface{}

func (*TableAgent) AddParam

func (ta *TableAgent) AddParam(param *Param)

AddParam add select or update or delete where clause param

func (*TableAgent) Between

func (ta *TableAgent) Between(col string, val []interface{})

Between add And Between Param

func (*TableAgent) Count added in v1.3.18

func (ta *TableAgent) Count() (int, error)

Count return query count

func (*TableAgent) CountTx added in v1.3.18

func (ta *TableAgent) CountTx() (int, error)

CountTx return query count

func (*TableAgent) Delete

func (ta *TableAgent) Delete() (Result, error)

Delete executes a query with db.Exec

func (*TableAgent) DeleteTx

func (ta *TableAgent) DeleteTx() (Result, error)

DeleteTx executes a query with tx.Exec

func (*TableAgent) Drop

func (ta *TableAgent) Drop() (Result, error)

Drop executes a query with db.Exec

func (*TableAgent) DropTx

func (ta *TableAgent) DropTx() (Result, error)

DropTx executes a query with tx.Exec

func (*TableAgent) ELike

func (ta *TableAgent) ELike(col string, val string)

ELike add And ELike Param

func (*TableAgent) Equal

func (ta *TableAgent) Equal(col string, val interface{})

Equal add And Equal Param

func (*TableAgent) Exists added in v1.3.18

func (ta *TableAgent) Exists() (bool, error)

Exists return query sql exists data

func (*TableAgent) ExistsTx added in v1.3.18

func (ta *TableAgent) ExistsTx() (bool, error)

ExistsTx return query sql exists data

func (*TableAgent) Greater

func (ta *TableAgent) Greater(col string, val interface{})

Greater add And Greater Param

func (*TableAgent) GreaterThanOrEqual

func (ta *TableAgent) GreaterThanOrEqual(col string, val interface{})

GreaterThanOrEqual add And GreaterThanOrEqual Param

func (*TableAgent) In

func (ta *TableAgent) In(col string, val []interface{})

In add And In Param

func (*TableAgent) Insert

func (ta *TableAgent) Insert() (Result, error)

Insert executes a query with db.Exec

func (*TableAgent) InsertTx

func (ta *TableAgent) InsertTx() (Result, error)

InsertTx executes a query with tx.Exec

func (*TableAgent) InsertTxWithLastInsertId added in v1.3.18

func (ta *TableAgent) InsertTxWithLastInsertId() (int, error)

InsertTxWithLastInsertId return last insert id by QueryRow.Scan

func (*TableAgent) InsertWithLastInsertId added in v1.3.18

func (ta *TableAgent) InsertWithLastInsertId() (int, error)

InsertWithLastInsertId return last insert id by QueryRow.Scan

func (*TableAgent) IsNotNull

func (ta *TableAgent) IsNotNull(col string)

IsNotNull add And IsNotNull Param

func (*TableAgent) IsNull

func (ta *TableAgent) IsNull(col string)

IsNull add And IsNull Param

func (*TableAgent) Less

func (ta *TableAgent) Less(col string, val interface{})

Less add And Less Param

func (*TableAgent) LessThanOrEqual

func (ta *TableAgent) LessThanOrEqual(col string, val interface{})

LessThanOrEqual add And LessThanOrEqual Param

func (*TableAgent) Like

func (ta *TableAgent) Like(col string, val string)

Like add And Like Param

func (*TableAgent) NotBetween

func (ta *TableAgent) NotBetween(col string, val []interface{})

NotBetween add And NotBetween Param

func (*TableAgent) NotEqual

func (ta *TableAgent) NotEqual(col string, val interface{})

NotEqual add And NotEqual Param

func (*TableAgent) NotIn

func (ta *TableAgent) NotIn(col string, val []interface{})

NotIn add And NotIn Param

func (*TableAgent) Query

func (ta *TableAgent) Query(v ...interface{}) (Result, error)

Query executes a query that returns Result

func (*TableAgent) QueryPage

func (ta *TableAgent) QueryPage(start, end int64, v ...interface{}) (Result, error)

QueryPage executes a query that returns Result the start and end are for query start row and end row

func (*TableAgent) QueryPageTx

func (ta *TableAgent) QueryPageTx(start, end int64, v ...interface{}) (Result, error)

QueryPageTx executes a query that returns Result the start and end are for query start row and end row

func (*TableAgent) QueryRow

func (ta *TableAgent) QueryRow(v ...interface{}) (Result, error)

QueryRow executes a query that is expected to return at most one row

func (*TableAgent) QueryRowTx

func (ta *TableAgent) QueryRowTx(v ...interface{}) (Result, error)

QueryRowTx executes a query that is expected to return at most one row

func (*TableAgent) QueryTx

func (ta *TableAgent) QueryTx(v ...interface{}) (Result, error)

QueryTx executes a query that returns Result

func (*TableAgent) SLike

func (ta *TableAgent) SLike(col string, val string)

SLike add And SLike Param

func (*TableAgent) SetMap

func (ta *TableAgent) SetMap(m map[string]interface{})

SetMap set insert or update column data with map[string]interface{}

func (*TableAgent) SetParams

func (ta *TableAgent) SetParams(p []*Param)

SetParams set select or update or delete where clause param

func (*TableAgent) Update

func (ta *TableAgent) Update() (Result, error)

Update executes a query with db.Exec

func (*TableAgent) UpdateTx

func (ta *TableAgent) UpdateTx() (Result, error)

UpdateTx executes a query with tx.Exec

type TableSchema added in v1.2.2

type TableSchema struct {
	// ColumnName column name
	ColumnName string `json:"COLUMN_NAME"`
	// DataType column data type
	DataType string `json:"DATA_TYPE"`
	// IsNullable is null(YES or NO)
	IsNullable string `json:"IS_NULLABLE"`
	// DataDefault column default data
	DataDefault string `json:"DATA_DEFAULT"`
	// PrimaryKey primary key
	PrimaryKey interface{} `json:"PRIMARY_KEY"`
	// IsIdentity is identity(YES OR NO)
	IsIdentity string `json:"IS_IDENTITY"`
	// ColumnComment column comment
	ColumnComment string `json:"COLUMN_COMMENT"`
	// TableComment table comment
	TableComment string `json:"TABLE_COMMENT"`
}

TableSchema table schema

type Type

type Type int

Type sql type

const (
	MySql Type = iota
	MSSql
	Oracle
	PostgreSql
)

func ParseDBType

func ParseDBType(t string) (Type, error)

ParseDBType takes a string db Type and returns the db Type constant.

func (Type) DriverName

func (t Type) DriverName() string

DriverName returns sql driver name

func (Type) Param

func (t Type) Param(i int) string

Param returns query params string of db Type

Jump to

Keyboard shortcuts

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