-
Notifications
You must be signed in to change notification settings - Fork 0
Connect to database
Derevtsov Konstantin edited this page Oct 21, 2020
·
10 revisions
D3 uses wrappers on existing database drivers. Currently, available two PostgreSQL drivers for a single connection and for the connection pool (based on pgx) and SQLite driver (based on go-sqlite3).
This is an example of creating a drivers:
import (
d3pgx "github.com/godzie44/d3/adapter/pgx"
"github.com/godzie44/d3/adapter/sqlite"
"github.com/jackc/pgx/v4"
)
// postgres driver
cfg, err := pgx.ParseConfig(os.Getenv("DB"))
if err != nil {
log.Fatal(err)
}
driver, err := d3pgx.NewPgxDriver(cfg)
if err != nil {
log.Fatal(err)
}
// postgres connection pool driver
cfg, err := pgxpool.ParseConfig(os.Getenv("DB"))
if err != nil {
log.Fatal(err.Error())
}
driver, err := d3pgx.NewPgxPoolDriver(cfg)
if err != nil {
log.Fatal(err.Error())
}
// sqlite driver
driver, err := sqlite.NewSQLiteDriver("./test.db")
if err != nil {
log.Fatal(err.Error())
}