Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a test #2127

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions extended_query_builder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package pgx_test

import (
"os"
"testing"

"github.com/jackc/pgx/v5"
)

// type SomeObject struct {
// Item *Item
// }

type Item struct {
Name string
Value string
}

func TestExtendedQueryBuilder(t *testing.T) {
t.Parallel()

var conn *pgx.Conn
t.Run("connect to database", func(t *testing.T) {
connString := os.Getenv("PGX_TEST_DATABASE")
config := mustParseConfig(t, connString)
config.DefaultQueryExecMode = pgx.QueryExecModeExec
conn = mustConnect(t, config)
conn.TypeMap().RegisterDefaultPgType(&Item{}, "jsonb")
})

t.Run("create table", func(t *testing.T) {
sql := `
CREATE TABLE IF NOT EXISTS some_objects (
item jsonb
)
`
mustExec(t, conn, sql)
})

t.Run("insert data", func(t *testing.T) {
item := &Item{
Name: "test",
Value: "value",
}
sql := `INSERT INTO some_objects (item) VALUES ($1)`
mustExec(t, conn, sql, item)
})
}