Documentation
¶
Index ¶
- Variables
- func CreateDB(dsn string, opts ...CreateOptFn) (err error)
- func DbFilePath(name, dbFolder string) (string, error)
- 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 ListOptions
- type OpenOptFn
- type Options
- type Transact
- type TransactFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrDBFileNotFound = errors.New("db file not found")
Functions ¶
func CreateDB ¶
func CreateDB(dsn string, opts ...CreateOptFn) (err 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 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 ( DriverSQLite DriverName = "sqlite" DriverPostgres DriverName = "postgres" DriverPgx DriverName = "pgx" DriverMySQL DriverName = "mysql" DriverMSSQL DriverName = "mssql" )
type ListOptions ¶
type OpenOptFn ¶
type OpenOptFn func(options *Options)
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 NewTransact ¶
func (*Transact) Transaction ¶
type TransactFunc ¶
Click to show internal directories.
Click to hide internal directories.