Skip to content

Commit 2826c91

Browse files
committed
rename file
1 parent 09ac652 commit 2826c91

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

destination.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Destination struct {
3939
getTableName destination.TableFn
4040

4141
conn *pgx.Conn
42-
dbInfo *internal.DbInfo
42+
dbInfo *internal.NumericScaleInfo
4343
stmtBuilder sq.StatementBuilderType
4444
}
4545

@@ -347,7 +347,7 @@ func (d *Destination) formatBigRat(ctx context.Context, table string, column str
347347

348348
// we need to get the scale of the column so we that we can properly
349349
// round the result of dividing the input big.Rat's numerator and denominator.
350-
scale, err := d.dbInfo.GetNumericColumnScale(ctx, table, column)
350+
scale, err := d.dbInfo.Get(ctx, table, column)
351351
if err != nil {
352352
return "", fmt.Errorf("failed getting scale of numeric column: %w", err)
353353
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,52 +22,52 @@ import (
2222
"github.com/jackc/pgx/v5"
2323
)
2424

25-
// DbInfo provides information about tables in a database.
26-
type DbInfo struct {
25+
// NumericScaleInfo provides information about the scale of numeric columns
26+
// in a database.
27+
type NumericScaleInfo struct {
2728
conn *pgx.Conn
2829
cache map[string]*tableCache
2930
}
3031

3132
// tableCache stores information about a table.
32-
// The information is cached and refreshed every 'cacheExpiration'.
3333
type tableCache struct {
3434
columns map[string]int
3535
}
3636

37-
func NewDbInfo(conn *pgx.Conn) *DbInfo {
38-
return &DbInfo{
37+
func NewDbInfo(conn *pgx.Conn) *NumericScaleInfo {
38+
return &NumericScaleInfo{
3939
conn: conn,
4040
cache: map[string]*tableCache{},
4141
}
4242
}
4343

44-
func (d *DbInfo) GetNumericColumnScale(ctx context.Context, table string, column string) (int, error) {
45-
// Check if table exists in cache and is not expired
46-
tableInfo, ok := d.cache[table]
44+
func (i *NumericScaleInfo) Get(ctx context.Context, table string, column string) (int, error) {
45+
// Check if table exists in cache
46+
tableInfo, ok := i.cache[table]
4747
if ok {
4848
scale, ok := tableInfo.columns[column]
4949
if ok {
5050
return scale, nil
5151
}
5252
} else {
5353
// Table info has expired, refresh the cache
54-
d.cache[table] = &tableCache{
54+
i.cache[table] = &tableCache{
5555
columns: map[string]int{},
5656
}
5757
}
5858

5959
// Fetch scale from database
60-
scale, err := d.numericScaleFromDb(ctx, table, column)
60+
scale, err := i.fetchFromDB(ctx, table, column)
6161
if err != nil {
6262
return 0, err
6363
}
6464

65-
d.cache[table].columns[column] = scale
65+
i.cache[table].columns[column] = scale
6666

6767
return scale, nil
6868
}
6969

70-
func (d *DbInfo) numericScaleFromDb(ctx context.Context, table string, column string) (int, error) {
70+
func (i *NumericScaleInfo) fetchFromDB(ctx context.Context, table string, column string) (int, error) {
7171
// Query to get the column type and numeric scale
7272
query := `
7373
SELECT
@@ -83,7 +83,7 @@ func (d *DbInfo) numericScaleFromDb(ctx context.Context, table string, column st
8383
var dataType string
8484
var numericScale *int
8585

86-
err := d.conn.QueryRow(ctx, query, table, column).Scan(&dataType, &numericScale)
86+
err := i.conn.QueryRow(ctx, query, table, column).Scan(&dataType, &numericScale)
8787
if err != nil {
8888
if errors.Is(err, pgx.ErrNoRows) {
8989
return 0, fmt.Errorf("column %s not found in table %s", column, table)

0 commit comments

Comments
 (0)