database

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(idx int32) error

Types

type Config

type Config struct {
	Database DatabaseConfig `yaml:"Database"`
}

func NewConfig

func NewConfig(path string) (*Config, error)

func (*Config) GetDatabase

func (c *Config) GetDatabase() DatabaseConfig

type Database

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

func Connect

func Connect(idx int32, user string, password string, host string, port int, dbName string) (*Database, error)

func Get

func Get(idx int32) *Database

func NewDatabase

func NewDatabase(idx int32, user string, password string, host string, port int) (*Database, error)

func (*Database) Close

func (d *Database) Close()

func (*Database) Exec

func (d *Database) Exec(sql string, args ...any) (*SqlResult, error)

func (*Database) IsTableExists

func (d *Database) IsTableExists(sql string) (bool, error)

func (*Database) Query

func (d *Database) Query(sql string, args ...any) (*SqlResult, error)

func (*Database) Use

func (d *Database) Use(dbName string) error

同時連結多個 database 時,由於維持多個連線,可以會發生錯誤。需再次呼叫此函式,告訴程式要連哪一個 database。

type DatabaseConfig

type DatabaseConfig struct {
	Host     string `yaml:"Host"`
	Port     int    `yaml:"Port"`
	DbName   string `yaml:"DbName"`
	User     string `yaml:"User"`
	Password string `yaml:"Password"`
}

func NewDatabaseConfig added in v0.2.3

func NewDatabaseConfig() *DatabaseConfig

func ParseDatabaseConfig added in v0.2.3

func ParseDatabaseConfig(args string) (*DatabaseConfig, error)

args ex: host=127.0.0.1;port=3306;dbname=pekomiko;user=user;password=password

type SqlResult

type SqlResult struct {
	// 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

	// RowsAffected returns the number of rows affected by an
	// update, insert, or delete. Not every database or database
	// driver may support this.
	RowsAffected int64

	// 欄位名稱
	Columns []string

	// 數據筆數
	NRow int32

	// 欄位個數
	NColumn int32

	Datas [][]string
}

func (*SqlResult) Merge added in v0.2.0

func (sr *SqlResult) Merge(other *SqlResult)

func (SqlResult) String

func (sr SqlResult) String() string

Jump to

Keyboard shortcuts

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