Documentation
¶
Index ¶
- Variables
- func CreateDB(dsn string, opts ...CreateOptFn) error
- func DbFilePath(name, dbFolder string) (string, error)
- func IsSQLite(dn DriverName) bool
- func MigrateDB(dsn string, opts ...CreateOptFn) (err error)
- func OpenDB(dsn string, opts ...OpenOptFn) (*bun.DB, error)
- func TableExists(ctx context.Context, db *bun.DB, tableName string) (bool, error)
- type Cache
- type CreateOptFn
- type CreateOptions
- type DriverName
- type IDB
- type ListOptions
- type OpenOptFn
- type Options
- type Transact
- type TransactFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCacheClosed = errors.New("cache is closed") ErrDatabaseNotFound = errors.New("database not found in cache") ErrDatabaseOpenFailed = errors.New("database failed to open in another goroutine") )
View Source
var ErrDBFileNotFound = errors.New("db file not found")
Functions ¶
func CreateDB ¶
func CreateDB(dsn string, opts ...CreateOptFn) error
CreateDB creates a new database specified by the dsn and runs migrations. Provides the following options:
- CreateWithDriverName(driverName DriverName) - specify the database driver (default: DriverSQLite)
- CreateWithDbFolder(folder string) - specify the folder to create the SQLite database file in (default: "./data")
- CreateWithSource(fs embed.FS) - specify the embedded filesystem containing migration files
- CreateWithSrcFolder(folder string) - specify the folder within the embedded filesystem containing migration files
For SQLite, if the database file already exists, it will not be overwritten. For other databases, ensure that the user has the necessary permissions to create a new database.
func DbFilePath ¶
DbFilePath converts a name into a full path to the db including the file extension
func IsSQLite ¶
func IsSQLite(dn DriverName) bool
func MigrateDB ¶
func MigrateDB(dsn string, opts ...CreateOptFn) (err error)
MigrateDB runs migrations on the db
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
type CreateOptFn ¶
type CreateOptFn func(options *CreateOptions)
func CreateWithDbFolder ¶
func CreateWithDbFolder(nme string) CreateOptFn
func CreateWithDriverName ¶
func CreateWithDriverName(dn DriverName) CreateOptFn
func CreateWithSource ¶
func CreateWithSource(fs embed.FS) CreateOptFn
func CreateWithSrcFolder ¶
func CreateWithSrcFolder(n string) CreateOptFn
type CreateOptions ¶
type CreateOptions struct {
// contains filtered or unexported fields
}
type DriverName ¶
type DriverName string
const ( DriverSQLiteMc DriverName = "sqlite" DriverSQLite DriverName = "sqlite3" DriverPostgres DriverName = "postgres" DriverPgx DriverName = "pgx" DriverMySQL DriverName = "mysql" DriverMSSQL DriverName = "mssql" )
type ListOptions ¶
type OpenOptFn ¶
type OpenOptFn func(options *Options)
func WithConnMaxIdleTime ¶
func WithConnMaxLifetime ¶
func WithDbFolder ¶
func WithDriverName ¶
func WithDriverName(dn DriverName) OpenOptFn
func WithMaxIdleConns ¶
func WithMaxOpenConns ¶
type Transact ¶
type Transact struct {
// contains filtered or unexported fields
}
func (*Transact) Transaction ¶
func (t *Transact) Transaction(opt *sql.TxOptions, fn TransactFunc) (err error)
type TransactFunc ¶
Click to show internal directories.
Click to hide internal directories.