Documentation ¶
Index ¶
- Constants
- func MapToString(m map[string]string) string
- func ToSnakeCase(s string) string
- type Builder
- type DB
- func (d *DB) Close() error
- func (d *DB) Conn(ctx context.Context) (*sql.Conn, error)
- func (d *DB) DataSourceName() string
- func (d *DB) DisableDebug()
- func (d *DB) Driver() driver.Driver
- func (d *DB) DriverName() string
- func (d *DB) DropTable(name string) bool
- func (d *DB) EnableDebug()
- func (d *DB) Exec(query string, args ...any) (sql.Result, error)
- func (d *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (d *DB) IsTableExist(name string) bool
- func (d *DB) NewSession() *session.Session
- func (d *DB) Ping() error
- func (d *DB) PingContext(ctx context.Context) error
- func (d *DB) Query(query string, args ...any) (*sql.Rows, error)
- func (d *DB) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (d *DB) QueryRow(query string, args ...any) *sql.Row
- func (d *DB) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
- func (d *DB) SetConnMaxIdleTime(t time.Duration)
- func (d *DB) SetConnMaxLifetime(t time.Duration)
- func (d *DB) SetMaxIdleConns(n int)
- func (d *DB) SetMaxOpenConns(n int)
- func (d *DB) Stats() sql.DBStats
- func (d *DB) Version() (string, error)
- type DataSource
- type DriverName
- type Option
Constants ¶
const (
MySQL = "mysql"
)
Variables ¶
This section is empty.
Functions ¶
func MapToString ¶
MapToString is a utility function that converts a map into a string. Each key-value pair in the map is converted into a "key=value" string, and these strings are joined with "&" as the separator. The resulting string does not end with "&".
func ToSnakeCase ¶
ToSnakeCase is a utility function that converts a given string into snake case.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) Conn ¶
Conn returns a single connection by either opening a new connection or returning an existing connection from the connection pool. Conn will block until either a connection is returned or ctx is canceled. Queries run on the same Conn will be run in the same database session.
Every Conn must be returned to the database pool after use by calling Conn.Close.
func (*DB) DataSourceName ¶
func (*DB) DriverName ¶
func (*DB) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*DB) ExecContext ¶
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*DB) IsTableExist ¶
IsTableExist checks if a table with the given name exists in the database. It returns true if the table exists, false otherwise.
func (*DB) NewSession ¶
NewSession creates a new session with the current database connection
func (*DB) Ping ¶
Ping verifies a connection to the database is still alive, establishing a connection if necessary.
func (*DB) PingContext ¶
PingContext verifies a connection to the database is still alive, establishing a connection if necessary.
func (*DB) Query ¶
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryContext ¶
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryRow ¶
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*DB) QueryRowContext ¶
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*DB) SetConnMaxIdleTime ¶
SetConnMaxIdleTime sets the maximum amount of time a connection may be idle before being closed.
func (*DB) SetConnMaxLifetime ¶
SetConnMaxLifetime sets the maximum amount of time a connection may be reused for before being closed.
func (*DB) SetMaxIdleConns ¶
SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
func (*DB) SetMaxOpenConns ¶
SetMaxOpenConns sets the maximum number of open connections to the database.
type DataSource ¶
type DataSource struct { User string Password string Net string Host string Port int32 DBName string Params map[string]string Driver DriverName }
func NewDataSource ¶
func NewDataSource(options ...Option) *DataSource
NewDataSource creates a new DataSource with the given options
func (*DataSource) DSN ¶
func (d *DataSource) DSN() string
DSN returns the data source name for the DataSource
type Option ¶
type Option func(*DataSource)
func SetPassword ¶
SetPassword sets the password for the DataSource