sql

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 32 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ConfigLogger     = "logger"
	ConfigTLS        = "tls"
	ConfigAuth       = "auth"
	ConfigQuery      = "query"
	ConfigTracer     = "tracer"
	ConfigMetrics    = "metrics"
	ConfigMySQL      = "mysql"
	ConfigPostgresql = "postgresql"
	ConfigPort       = "port"
	ConfigEnabled    = "enabled"
	ConfigLevel      = "level"
	ConfigPrometheus = "prometheus"
	ConfigStore      = "store"
	ConfigSQLite     = "sqlite"
	ConfigMemory     = "memory"
)
View Source
const (
	DatabaseDefaultFilename = ":memory:"
	DatabaseFilenameExt     = "sqlite3"
)
View Source
const (
	DefaultPrometheusPort                            = 9181
	DefaultPrometheusConnectionTimeout time.Duration = time.Second * 60
)
View Source
const (
	// ProductName is the product name.
	ProductName = "go-sqlserver"
)
View Source
const (
	Version = "v0.0.1"
)

Variables

View Source
var (
	ErrExist        = errors.New("exist")
	ErrNotExist     = errors.New("not exist")
	ErrNotSupported = errors.New("not supported")
	ErrInvalid      = errors.New("invalid")
	ErrNotEqual     = errors.New("not equal")
)

Functions

func NewResultSet added in v0.9.0

func NewResultSet(opts ...ResultSetOption) (sql.ResultSet, error)

NewResultSet creates a new result set.

func NewResultSetColumnFrom added in v0.9.0

func NewResultSetColumnFrom(name string, ct *dbsql.ColumnType) (sql.Column, error)

NewResultSetColumn creates a new result set column from a column name and type.

func NewResultSetDataTypeFrom added in v0.9.0

func NewResultSetDataTypeFrom(ct *dbsql.ColumnType) (sql.DataType, error)

NewResultSetDataTypeFrom creates a new result set data type from a column type.

Types

type Config

type Config interface {
	// MySQLPort returns the MySQL port.
	MySQLPort() (int, error)
	// PostgresqlPort returns the Postgresql port.
	PostgresqlPort() (int, error)
	// IsLoggerEnabled returns true if the logger is enabled.
	IsLoggerEnabled() (bool, error)
	// LoggerLevel returns the logger level.
	LoggerLevel() (string, error)
	// IsTLSEnabled returns true if the TLS is enabled.
	IsTLSEnabled() (bool, error)
	// TLSCert returns the TLS certificate.
	TLSConfig() (*tls.Config, error)
	// IsPrometheusEnabled returns true if the Prometheus is enabled.
	IsPrometheusEnabled() (bool, error)
	// PrometheusPort returns the Prometheus port.
	PrometheusPort() (int, error)
	// IsMemoryStoreEnabled returns true if the store is memory.
	IsMemoryStoreEnabled() (bool, error)
}

Config represents a configuration interface for PuzzleDB.

func NewConfig added in v0.9.0

func NewConfig() (Config, error)

NewConfig returns a new configuration.

func NewConfigWithFile added in v0.9.0

func NewConfigWithFile(confFile string) (Config, error)

NewConfigWithFile returns a new configuration with the specified file.

func NewConfigWithPath added in v0.9.0

func NewConfigWithPath(path string) (Config, error)

NewConfigWithPath returns a new configuration with the specified path.

func NewConfigWithPaths added in v0.9.0

func NewConfigWithPaths(paths ...string) (Config, error)

func NewConfigWithString added in v0.9.0

func NewConfigWithString(conString string) (Config, error)

NewConfigWithString returns a new configuration with the specified string.

func NewDefaultConfig

func NewDefaultConfig() (Config, error)

type Conn

type Conn interface {
	net.Conn
}

Conn represents a connection.

type ConnID

type ConnID = net.ConnID

ConnID represents a connection ID.

type Database added in v0.9.0

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

Database represents a destination or source database of query.

func NewDatabaseWith added in v0.9.0

func NewDatabaseWith(opt ...DatabaseOption) (*Database, error)

NewDatabaseWith returns a new database with the specified string.

func (*Database) Begin added in v0.9.0

func (db *Database) Begin() error

Begin starts a transaction.

func (*Database) Commit added in v0.9.0

func (db *Database) Commit() error

Commit commits a transaction.

func (*Database) DB added in v0.9.0

func (db *Database) DB() *sql.DB

DB returns the database.

func (*Database) Exec added in v0.9.0

func (db *Database) Exec(query string, args ...any) (sql.Result, error)

Exec executes a query.

func (*Database) Name added in v0.9.0

func (db *Database) Name() string

Name returns the database name.

func (*Database) Query added in v0.9.0

func (db *Database) Query(query string, args ...any) (*sql.Rows, error)

Query executes a query.

func (*Database) Rollback added in v0.9.0

func (db *Database) Rollback() error

Rollback rolls back a transaction.

func (*Database) SetOptions added in v0.9.0

func (db *Database) SetOptions(opts ...DatabaseOption) error

SetOptions sets the database options.

type DatabaseOption added in v0.9.0

type DatabaseOption func(*Database) error

DatabaseOption is a function that configures a database.

func WithDatabaseFilename added in v0.9.0

func WithDatabaseFilename(filename string) DatabaseOption

WithDatabaseFilename returns a database option that sets the filename.

func WithDatabaseName added in v0.9.0

func WithDatabaseName(name string) DatabaseOption

WithDatabaseName returns a database option that sets the name.

type Databases added in v0.9.0

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

Databases represents a collection of databases.

func NewDatabases added in v0.9.0

func NewDatabases() *Databases

NewDatabases returns a databases instance.

func (*Databases) AddDatabase added in v0.9.0

func (dbs *Databases) AddDatabase(db *Database) error

AddDatabase adds a specified database.

func (*Databases) DropDatabase added in v0.9.0

func (dbs *Databases) DropDatabase(db *Database) error

DropDatabase remove the specified database.

func (*Databases) LookupDatabase added in v0.9.0

func (dbs *Databases) LookupDatabase(name string) (*Database, error)

LookupDatabase returns a database with the specified name.

type PrometheusExporter added in v0.9.0

type PrometheusExporter struct {
	Addr string
	Port int
	// contains filtered or unexported fields
}

PrometheusExporter is a prometheus exporter service.

func NewPrometheusExporter added in v0.9.0

func NewPrometheusExporter() *PrometheusExporter

NewPrometheusExporter returns a new prometheus exporter service.

func (*PrometheusExporter) SetAddress added in v0.9.0

func (expoter *PrometheusExporter) SetAddress(addr string)

SetAddress sets an address of the expoter.

func (*PrometheusExporter) SetPort added in v0.9.0

func (expoter *PrometheusExporter) SetPort(port int)

SetPort sets a port number of the expoter.

func (*PrometheusExporter) Start added in v0.9.0

func (expoter *PrometheusExporter) Start() error

Start starts the expoter.

func (*PrometheusExporter) Stop added in v0.9.0

func (expoter *PrometheusExporter) Stop() error

Stop stops the Grpc expoter.

type ResultSetOption added in v0.9.0

type ResultSetOption func(*resultset) error

ResultSetOption is a result set option.

func WithResultSetResult added in v0.9.0

func WithResultSetResult(result dbsql.Result) ResultSetOption

WithResultSetResult sets the result set result.

func WithResultSetRows added in v0.9.0

func WithResultSetRows(rows *dbsql.Rows) ResultSetOption

WithResultSetRows sets the result set rows.

type SQLExecutor added in v0.9.0

type SQLExecutor = sql.Executor

SQLExecutor represents a SQL executor.

type Server

type Server interface {
	// SetConfig sets a configuration.
	SetConfig(Config)
	// SetTracer sets a tracing tracer.
	SetTracer(tracer.Tracer)
	// SetSQLExecutor sets a SQL executor.
	SetSQLExecutor(SQLExecutor)
	// MySQLServer returns a MySQL server.
	MySQLServer() mysql.Server
	// PostgreSQLServer returns a PostgreSQL server.
	PostgreSQLServer() postgresql.Server
	// Start starts the server.
	Start() error
	// Stop stops the server.
	Stop() error
	// Restart restarts the server.
	Restart() error
}

Server represents a PostgreSQL protocol server.

func NewServer

func NewServer() Server

NewServer creates a new SQL server.

type TLSConf

type TLSConf struct {
	ClientAuthType tls.ClientAuthType
	ServerCert     []byte
	ServerKey      []byte
	RootCerts      [][]byte
	// contains filtered or unexported fields
}

TLSConf represents a TLS configuration.

func NewTLSConf

func NewTLSConf() *TLSConf

NewTLSConf returns a new TLS configuration.

func (*TLSConf) IsTLSEnabled

func (config *TLSConf) IsTLSEnabled() bool

IsEnabled returns true if the TLS is enabled.

func (*TLSConf) SetClientAuthType

func (config *TLSConf) SetClientAuthType(authType tls.ClientAuthType)

SetClientAuthType sets a client authentication type.

func (*TLSConf) SetRootCertFiles

func (config *TLSConf) SetRootCertFiles(files ...string) error

SetRootCertFile sets a SSL root certificates.

func (*TLSConf) SetRootCerts

func (config *TLSConf) SetRootCerts(certs ...[]byte)

SetRootCerts sets a SSL root certificates.

func (*TLSConf) SetServerCert

func (config *TLSConf) SetServerCert(cert []byte)

SetServerCert sets a SSL server certificate.

func (*TLSConf) SetServerCertFile

func (config *TLSConf) SetServerCertFile(file string) error

SetServerCertFile sets a SSL server certificate file.

func (*TLSConf) SetServerKey

func (config *TLSConf) SetServerKey(key []byte)

SetServerKey sets a SSL server key.

func (*TLSConf) SetServerKeyFile

func (config *TLSConf) SetServerKeyFile(file string) error

SetServerKeyFile sets a SSL server key file.

func (*TLSConf) SetTLSConfig

func (config *TLSConf) SetTLSConfig(tlsConfig *tls.Config)

SetTLSConfig sets a TLS configuration.

func (*TLSConf) SetTLSEnabled

func (config *TLSConf) SetTLSEnabled(enabled bool)

SetTLSEnabled sets a TLS enabled flag.

func (*TLSConf) TLSConfig

func (config *TLSConf) TLSConfig() (*tls.Config, error)

TLSConfig returns a TLS configuration from the configuration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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