feat: refactor db handling to use db-wrapper package; enhance connection management and result handling for MSSQL and Postgres
This commit is contained in:
@@ -15,16 +15,24 @@ func init() {
|
||||
}
|
||||
|
||||
type postgresRowResult struct {
|
||||
row pgx.Row
|
||||
}
|
||||
|
||||
func (pr *postgresRowResult) Scan(dest ...any) error {
|
||||
return pr.row.Scan(dest...)
|
||||
}
|
||||
|
||||
type postgresRowsResult struct {
|
||||
columns []string
|
||||
rows pgx.Rows
|
||||
}
|
||||
|
||||
func (pr *postgresRowResult) Close() error {
|
||||
func (pr *postgresRowsResult) Close() error {
|
||||
pr.rows.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pr *postgresRowResult) Columns() ([]string, error) {
|
||||
func (pr *postgresRowsResult) Columns() ([]string, error) {
|
||||
if pr.columns != nil {
|
||||
return pr.columns, nil
|
||||
}
|
||||
@@ -42,19 +50,19 @@ func (pr *postgresRowResult) Columns() ([]string, error) {
|
||||
return columns, nil
|
||||
}
|
||||
|
||||
func (pr *postgresRowResult) Err() error {
|
||||
func (pr *postgresRowsResult) Err() error {
|
||||
return pr.rows.Err()
|
||||
}
|
||||
|
||||
func (pr *postgresRowResult) Next() bool {
|
||||
func (pr *postgresRowsResult) Next() bool {
|
||||
return pr.rows.Next()
|
||||
}
|
||||
|
||||
func (pr *postgresRowResult) Scan(dest ...any) error {
|
||||
func (pr *postgresRowsResult) Scan(dest ...any) error {
|
||||
return pr.rows.Scan(dest...)
|
||||
}
|
||||
|
||||
func (pr *postgresRowResult) Values() ([]any, error) {
|
||||
func (pr *postgresRowsResult) Values() ([]any, error) {
|
||||
return pr.rows.Values()
|
||||
}
|
||||
|
||||
@@ -102,7 +110,12 @@ func (pw *postgresDbWrapper) Query(ctx context.Context, query string, args ...an
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &postgresRowResult{columns: nil, rows: rows}, nil
|
||||
return &postgresRowsResult{columns: nil, rows: rows}, nil
|
||||
}
|
||||
|
||||
func (pw *postgresDbWrapper) QueryRow(ctx context.Context, query string, args ...any) RowResult {
|
||||
row := pw.db.QueryRow(ctx, query, args...)
|
||||
return &postgresRowResult{row: row}
|
||||
}
|
||||
|
||||
func (pw *postgresDbWrapper) SaveMassive(ctx context.Context, schema string, table string, columnNames []string, rows [][]any) (int64, error) {
|
||||
|
||||
Reference in New Issue
Block a user