golang: sqlx ошибка при Exec. Как исправить?

Есть такое подключение

import (
    "fmt"
    _ "github.com/jackc/pgx/v5/stdlib"
    "github.com/jmoiron/sqlx"
    "os"
)

func NewConnectTest() (*sqlx.DB, error) {
    dsn := fmt.Sprintf(
        "host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Europe/Moscow",
        "localhost",
        os.Getenv("POSTGRES_USER"),
        os.Getenv("POSTGRES_PASSWORD"),
        os.Getenv("POSTGRES_DB"),
        os.Getenv("POSTGRES_PORT_TEST_EXTERNAL"))
    return sqlx.Connect("pgx", dsn)
}

выполняю тест

func TestRepositoryAdd(t *testing.T) {
 connect, err := NewConnectTest()
    if err != nil {
        t.Fatal(err)
    }
    connect.Exec("TRUNCATE TABLE profile")
}

выдает ошибку

=== RUN   TestRepositoryAdd
--- FAIL: TestRepositoryAdd (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x71b9d5]

goroutine 19 [running]:
testing.tRunner.func1.2({0x767f80, 0xb63c10})
    C:/Users/G/sdk/go1.21.3/src/testing/testing.go:1545 +0x238
testing.tRunner.func1()
    C:/Users/G/sdk/go1.21.3/src/testing/testing.go:1548 +0x397
panic({0x767f80?, 0xb63c10?})
    C:/Users/G/sdk/go1.21.3/src/runtime/panic.go:914 +0x21f
github.com/3110Y/profile/internal/infrastructure/repository.TestRepositoryAdd(0x0?)
    C:/Users/G/GolandProjects/cc/cc-profile/internal/infrastructure/repository/profile_test.go:45 +0x15
testing.tRunner(0xc0001044e0, 0x8237b0)
    C:/Users/G/sdk/go1.21.3/src/testing/testing.go:1595 +0xff
created by testing.(*T).Run in goroutine 1
    C:/Users/G/sdk/go1.21.3/src/testing/testing.go:1648 +0x3ad


Process finished with the exit code 1

любой запрос в Exec выдает ошибку

github.com/jackc/pgx/v5 v5.4.3 github.com/jmoiron/sqlx v1.3.5

Не могу понять как исправить. Помогите пожалуйста


Ответы (0 шт):