Introduce own Numeric type and revert to stdlib from pgx

This commit is contained in:
2021-12-02 21:29:44 +00:00
parent 6f8a94ff5d
commit 4646356b2d
16 changed files with 136 additions and 57 deletions

View File

@ -1,12 +1,10 @@
package postgres
import (
"context"
"database/sql"
"embed"
"fmt"
"github.com/jackc/pgx/v4"
_ "github.com/jackc/pgx/v4/stdlib"
"github.com/pressly/goose/v3"
)
@ -27,12 +25,7 @@ func Connect(server string, user string, password string, database string) (*Que
return nil, nil, err
}
connPG, err := pgx.Connect(context.Background(), connString)
if err != nil {
return nil, nil, err
}
return New(connPG), conn, nil
return New(conn), conn, nil
}
func (tx Transaction) GetAmount() float64 {
@ -62,3 +55,17 @@ func (tx GetTransactionsForBudgetRow) GetPositive() bool {
amount := tx.GetAmount()
return amount >= 0
}
func (tx GetAccountsWithBalanceRow) GetBalance() float64 {
var balance float64
err := tx.Balance.AssignTo(&balance)
if err != nil {
panic(err)
}
return balance
}
func (tx GetAccountsWithBalanceRow) GetPositive() bool {
balance := tx.GetBalance()
return balance >= 0
}