sql

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Datetime represents mysql DATETIME.
	Datetime = "2006-01-02 15:04:05"
)

Variables

View Source
var (
	// CST represents China Standard Time.
	CST = time.FixedZone("CST", 8*60*60)
)

Functions

func FormatLimitOffset

func FormatLimitOffset(limit, offset int) string

FormatLimitOffset returns a SQL string for a given limit & offset. Clauses are only added if limit and/or offset are greater than zero.

Types

type DB

type DB struct {

	// Datasource name.
	DSN string

	Logger logr.Logger

	// Returns the current time. Defaults to time.Now().
	// Can be mocked for tests.
	Now func() time.Time
	// contains filtered or unexported fields
}

func NewDB

func NewDB(dsn string) *DB

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginTx starts a transaction and returns a wrapper Tx type. This type provides a reference to the database and a fixed timestamp at the start of the transaction. The timestamp allows us to mock time during tests as well.

func (*DB) Close

func (db *DB) Close() error

Close the database connection.

func (*DB) Open

func (db *DB) Open() (err error)

type NullString

type NullString string

NullString represents a helper wrapper for string.

func (*NullString) Scan

func (s *NullString) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullString) Value

func (s *NullString) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NullTime

type NullTime time.Time

NullTime represents a helper wrapper for time.Time. It automatically converts time fields to/from RFC 3339 format. Also supports NULL for zero time.

func (*NullTime) Scan

func (t *NullTime) Scan(value interface{}) error

Scan reads a time value from the database.

func (*NullTime) Value

func (t *NullTime) Value() (driver.Value, error)

Value formats a time value for the database.

type ProxyService

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

func NewProxyService added in v0.1.0

func NewProxyService(db *DB, opts ProxyServiceOptions) *ProxyService

func (*ProxyService) CreateProxy

func (s *ProxyService) CreateProxy(ctx context.Context, proxy *batproxy.Proxy, opts batproxy.CreateProxyOptions) error

func (*ProxyService) DeleteProxy

func (s *ProxyService) DeleteProxy(ctx context.Context, proxyID string) error

func (*ProxyService) ListProxies

func (s *ProxyService) ListProxies(ctx context.Context, opts batproxy.ListProxiesOptions) (page *batproxy.ListProxiesPage, err error)

type ProxyServiceOptions added in v0.0.3

type ProxyServiceOptions struct {
	Suffix string
}

type Tx

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

Tx wraps the SQL Tx object to provide a timestamp at the start of the transaction.

type UTCTime

type UTCTime time.Time

UTCTime represents a helper wrapper for time.Time. It automatically converts time fields to/from MySQL datetime as UTC zone. Also supports NULL for zero time.

func (*UTCTime) Scan

func (n *UTCTime) Scan(value interface{}) error

Scan reads a time value from the database.

func (*UTCTime) Value

func (n *UTCTime) Value() (driver.Value, error)

Value formats a time value for the database.

Jump to

Keyboard shortcuts

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