Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marino39 committed Mar 4, 2025
1 parent 2708740 commit 718c69b
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 122 deletions.
4 changes: 2 additions & 2 deletions examples/tracing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func main() {
stmt := pgkit.RawQuery("SELECT * FROM accounts WHERE name IN (?,?)")
q := stmt.Build("user-1", "user-2")

_, err = dbClient.Query.Exec(context.Background(), q)
_, err = dbClient.Query().Exec(context.Background(), q)
if err != nil {
log.Fatal(fmt.Errorf("failed to execute query: %w", err))
}

// example with incorrect sql query
stmt = pgkit.RawQuery("SELECT * FROM non_existent_table")
_, _ = dbClient.Query.Exec(context.Background(), stmt.Build())
_, _ = dbClient.Query().Exec(context.Background(), stmt.Build())
}
4 changes: 2 additions & 2 deletions pgkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (d *DB) Query() *Querier {

// TxQuery returns a new Querier that uses the given pgx.Tx
func (d *DB) TxQuery(tx pgx.Tx) *Querier {
return &Querier{tx: tx, SQL: d.sqlBuilder, pool: d.conn, Scan: d.query.Scan}
return &Querier{tx: tx, SQL: d.sqlBuilder, pool: d.conn, Scan: d.Query().Scan}
}

// TxQueryFromContext returns a new Querier that uses the pgx.Tx in the given context
Expand Down Expand Up @@ -122,7 +122,7 @@ func ConnectWithPGX(appName string, pgxConfig *pgxpool.Config) (*DB, error) {
return nil, wrapErr(err)
}

db.query = &Querier{pool: db.conn, Scan: pgxScanAPI, SQL: db.sqlBuilder}
db.query = &Querier{pool: DB.Conn(), Scan: pgxScanAPI, SQL: db.sqlBuilder}

Check failure on line 125 in pgkit.go

View workflow job for this annotation

GitHub Actions / Test

invalid method expression DB.Conn (needs pointer receiver (*DB).Conn)

return db, nil
}
Expand Down
4 changes: 2 additions & 2 deletions querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (r RawStatement) Err() error {
}

func (r RawStatement) GetQuery() string {
return r.query.Query
return r.Query().Query

Check failure on line 330 in querier.go

View workflow job for this annotation

GitHub Actions / Test

r.Query undefined (type RawStatement has no field or method Query, but does have field query)
}

func (r RawStatement) NumArgs() int {
Expand All @@ -338,7 +338,7 @@ func (r RawStatement) Build(args ...interface{}) Sqlizer {
if len(args) != r.numArgs {
return RawSQL{err: fmt.Errorf("pgkit: invalid arguments passed to statement, expecting %d args but received %d", r.numArgs, len(args))}
}
return RawSQL{Query: r.query.Query, Args: args, statement: true}
return RawSQL{Query: r.Query().Query, Args: args, statement: true}

Check failure on line 341 in querier.go

View workflow job for this annotation

GitHub Actions / Test

r.Query undefined (type RawStatement has no field or method Query, but does have field query)
}

func RawQuery(query string) RawStatement {
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func truncateAllTables(t *testing.T) {
}

func truncateTable(t *testing.T, tableName string) {
_, err := DB.Conn.Exec(context.Background(), fmt.Sprintf(`TRUNCATE TABLE %q CASCADE`, tableName))
_, err := DB.Conn().Exec(context.Background(), fmt.Sprintf(`TRUNCATE TABLE %q CASCADE`, tableName))
assert.NoError(t, err)
}

Expand Down
Loading

0 comments on commit 718c69b

Please sign in to comment.