orm

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MySqlDb           DatabaseType = "mysql"
	PostgresDb        DatabaseType = "postgres"
	DefaultMaxIdle                 = 100
	DefaultMaxOpen                 = 100
	DefaultMaxTimeout              = 300
)

Variables

View Source
var (
	ErrInvalidDB = errors.New("invalid db")
)

Functions

func Close

func Close()

func Execute

func Execute(sqlStr string, args ...interface{}) (int64, error)

func Initialize

func Initialize(filename string) error

func InitializeDatabase

func InitializeDatabase(dbType, host string, port int, user, pwd, dbName string) error

func InitializeFromSettings

func InitializeFromSettings(cm map[string]string) error

func LoadProperties

func LoadProperties(filename string) map[string]string

func LoadSettings

func LoadSettings(filename string) map[string]string

func NewMapper

func NewMapper(name string) interface{}

func NewMapperPtr

func NewMapperPtr(name string) interface{}

func Query

func Query(sqlStr string, args ...interface{}) ([]map[string]interface{}, error)

func ReConnect

func ReConnect() error

func RegisterMapper

func RegisterMapper(inPtr interface{}) error

func RegisterModel

func RegisterModel(inPtr interface{})

func SchemaToCode

func SchemaToCode(dir, prefix, tables string)

func SetLogger

func SetLogger(logger log.Logger)

Types

type BaseMapper

type BaseMapper struct {
	*types.SqlMapper
}

type Config

type Config struct {
	Setting      MyBatisSetting
	MaxIdle      int
	MaxOpen      int
	MaxTimeout   int
	PreparedStmt bool
	SpringConfig bool
	Dialector
	ConnPool ConnPool
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(filename string) *Config

func NewConfigFromSettings

func NewConfigFromSettings(cm map[string]string) *Config

func (*Config) DriverName

func (in *Config) DriverName() string

func (*Config) GenerateDSN

func (in *Config) GenerateDSN() string

type ConnPool

type ConnPool interface {
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
	Stats() sql.DBStats
}

type DB

type DB struct {
	*Config
	Error     error
	Statement *Statement
}

func Open

func Open(cfg *Config) (db *DB, err error)

func (*DB) DB

func (db *DB) DB() (*sql.DB, error)

func (*DB) ExecContext

func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*DB) QueryContext

func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (*DB) QueryRowContext

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (*DB) Stats

func (db *DB) Stats() sql.DBStats

type DatabaseSetting

type DatabaseSetting struct {
	Host     string
	Port     int64
	Username string
	Password string
	Name     string
	Type     DatabaseType
}

type DatabaseType

type DatabaseType string

type Dialector

type Dialector interface {
	Name() string
	Initialize(*DB) error
	FormatPrepareSQL(src string) string
}

type GetDBConnector

type GetDBConnector interface {
	GetDBConn() (*sql.DB, error)
}

type MyBatisSetting

type MyBatisSetting struct {
	DatabaseSetting
	MapperLocations  string
	TypeAliasPackage string
	MaxRows          int64
}

type MySqlConfig

type MySqlConfig struct {
	Config
	DriverName string
	DSN        string
	Conn       ConnPool
}

type MySqlDialector

type MySqlDialector struct {
	*MySqlConfig
}

func NewMySqlDialector

func NewMySqlDialector(cfg *Config) *MySqlDialector

func (*MySqlDialector) FormatPrepareSQL

func (dialector *MySqlDialector) FormatPrepareSQL(src string) string

func (*MySqlDialector) Initialize

func (dialector *MySqlDialector) Initialize(db *DB) (err error)

func (*MySqlDialector) Name

func (dialector *MySqlDialector) Name() string

type ParamType

type ParamType struct {
	TagArgs    []TagArg
	TagArgsLen int
	Args       []reflect.Type
	ArgsLen    int
}

type PostgresConfig

type PostgresConfig struct {
	Config
	DriverName string
	DSN        string
	Conn       ConnPool
}

type PostgresDialector

type PostgresDialector struct {
	*PostgresConfig
}

func NewPostgresDialector

func NewPostgresDialector(cfg *Config) *PostgresDialector

func (*PostgresDialector) FormatPrepareSQL

func (dialector *PostgresDialector) FormatPrepareSQL(src string) string

func (*PostgresDialector) Initialize

func (dialector *PostgresDialector) Initialize(db *DB) (err error)

func (*PostgresDialector) Name

func (dialector *PostgresDialector) Name() string

type PreparedStmtDB

type PreparedStmtDB struct {
	Stmts       map[string]*Stmt
	PreparedSQL []string
	Mux         *sync.RWMutex
	ConnPool
}

func (*PreparedStmtDB) Close

func (db *PreparedStmtDB) Close()

func (*PreparedStmtDB) ExecContext

func (db *PreparedStmtDB) ExecContext(ctx context.Context, query string, args ...interface{}) (result sql.Result, err error)

func (*PreparedStmtDB) GetDBConn

func (db *PreparedStmtDB) GetDBConn() (*sql.DB, error)

func (*PreparedStmtDB) QueryContext

func (db *PreparedStmtDB) QueryContext(ctx context.Context, query string, args ...interface{}) (rows *sql.Rows, err error)

func (*PreparedStmtDB) QueryRowContext

func (db *PreparedStmtDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (*PreparedStmtDB) Reset

func (db *PreparedStmtDB) Reset()

func (*PreparedStmtDB) Stats

func (db *PreparedStmtDB) Stats() sql.DBStats

type ProxyArg

type ProxyArg struct {
	TagArgs    []TagArg
	TagArgsLen int
	Args       []reflect.Value
	ArgsLen    int
}

代理数据

func NewProxyArg

func NewProxyArg(tagArgs []TagArg, args []reflect.Value) ProxyArg

type ReturnType

type ReturnType struct {
	ErrorType     *reflect.Type
	ReturnOutType *reflect.Type
	ReturnIndex   int //返回数据位置索引
	NumOut        int //返回总数
}

type Rows

type Rows interface {
	Columns() ([]string, error)
	ColumnTypes() ([]*sql.ColumnType, error)
	Next() bool
	Scan(dest ...interface{}) error
	Err() error
	Close() error
}

type Statement

type Statement struct {
	QueryCount         int64
	ExecuteCount       int64
	ErrorCount         int64
	DurationTotal      int64
	QueryDuration      int64
	ExecuteDuration    int64
	QueryMaxDuration   int64
	QueryMinDuration   int64
	ExecuteMaxDuration int64
	ExecuteMinDuration int64
	DBExecCount        int64
	DBExecDuration     int64
	DBExecMaxDuration  int64
	DBExecMinDuration  int64
	DBQueryCount       int64
	DBQueryDuration    int64
	DBQueryMaxDuration int64
	DBQueryMinDuration int64
}

func (*Statement) String

func (state *Statement) String() string

type Stmt

type Stmt struct {
	*sql.Stmt
	// contains filtered or unexported fields
}

type TagArg

type TagArg struct {
	Name  string
	Index int
}

Jump to

Keyboard shortcuts

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