db

package
v0.0.0-...-814a884 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPostgresDB = "postgres"
	DefaultMysqlDB    = "mysql"
)
View Source
const (
	DialectSQLite   = "sqlite"
	DialectMySQL    = "mysql"
	DialectPostgres = "postgres"
)

Variables

View Source
var (
	ErrUnknownDriver            = errors.New("unknown driver")
	ErrNoSuchDatabase           = errors.New("no such database exists")
	ErrCannotConnectToDefaultDB = errors.New("cannot connect to default db")
)
View Source
var (
	ErrUnsupportedDialect = errors.New("unsupported dialect")
)

Functions

func Has

func Has(connectionId string) bool

Determine if the map has an entry with the key

Types

type Config

type Config struct {
	ConnName string
	Driver   string
	Host     string
	Port     int
	User     string
	Password string
	Database string
	Params   string
}

type Connection

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

func NewConnection

func NewConnection(dbc *Config) *Connection

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) IsOpen

func (c *Connection) IsOpen() bool

func (*Connection) Open

func (c *Connection) Open() (*DB, error)

func (*Connection) WithDatabase

func (c *Connection) WithDatabase(database string) *Connection

func (*Connection) WithForceCreateDb

func (c *Connection) WithForceCreateDb() *Connection

type DB

type DB struct {
	*gorm.DB
}

func Get

func Get(arg ...interface{}) *DB

func Resolve

func Resolve(ctx context.Context, resolver ResolverFunc) (*DB, error)

func (*DB) BindWhere

func (db *DB) BindWhere(c context.Context, columnName string) *gorm.DB

func (*DB) Close

func (db *DB) Close() error

type DataSource

type DataSource struct {
	Dialect  string
	Host     string
	Port     string
	Username string
	Password string
	Name     string
	Params   string
}

DataSource holds the necessary fields for a DSN (data source name)

func (*DataSource) String

func (ds *DataSource) String() (string, error)

String returns the string representation of the data source

type Model

type Model struct {
	ID        uint           `json:"id" gorm:"primarykey"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

type Resolver

type Resolver struct {
	Ctx context.Context
	New func(context.Context) (*DB, error)
}

type ResolverFunc

type ResolverFunc func(context.Context) (*DB, error)

Jump to

Keyboard shortcuts

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