27 lines
693 B
Go
27 lines
693 B
Go
package adaptertest
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/uptrace/bun"
|
|
"github.com/uptrace/bun/dialect/sqlitedialect"
|
|
"github.com/uptrace/bun/driver/sqliteshim"
|
|
)
|
|
|
|
// NewBunDBSQLite initializes a new instance of *bun.DB, which is ready for use (all required migrations are applied).
|
|
// Data is stored in memory (https://www.sqlite.org/inmemorydb.html).
|
|
func NewBunDBSQLite(tb TestingTB) *bun.DB {
|
|
sqldb, err := sql.Open(sqliteshim.ShimName, "file::memory:")
|
|
require.NoError(tb, err)
|
|
sqldb.SetMaxOpenConns(1)
|
|
sqldb.SetMaxIdleConns(1)
|
|
sqldb.SetConnMaxLifetime(0)
|
|
|
|
db := bun.NewDB(sqldb, sqlitedialect.New())
|
|
|
|
runMigrations(tb, db)
|
|
|
|
return db
|
|
}
|