Migrate to postgres
This commit is contained in:
@@ -9,8 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ostafen/clover/v2"
|
||||
"github.com/ostafen/clover/v2/document"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"pool-stats/constants"
|
||||
"pool-stats/database"
|
||||
@@ -18,11 +17,11 @@ import (
|
||||
)
|
||||
|
||||
type IngestSharesJob struct {
|
||||
db *clover.DB
|
||||
db *pgxpool.Pool
|
||||
logPath string
|
||||
}
|
||||
|
||||
func NewIngestSharesJob(db *clover.DB, path string) *IngestSharesJob {
|
||||
func NewIngestSharesJob(db *pgxpool.Pool, path string) *IngestSharesJob {
|
||||
return &IngestSharesJob{db: db, logPath: path}
|
||||
}
|
||||
|
||||
@@ -67,7 +66,7 @@ func (this *IngestSharesJob) ingestClosedBlocks() {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *IngestSharesJob) ingestBlockDir(db *clover.DB, dirPath string) {
|
||||
func (this *IngestSharesJob) ingestBlockDir(db *pgxpool.Pool, dirPath string) {
|
||||
files, err := os.ReadDir(dirPath)
|
||||
if err != nil {
|
||||
log.Printf("Failed to read block dir %s: %v", dirPath, err)
|
||||
@@ -97,8 +96,7 @@ func (this *IngestSharesJob) ingestBlockDir(db *clover.DB, dirPath string) {
|
||||
continue
|
||||
}
|
||||
|
||||
doc := document.NewDocumentOf(&share)
|
||||
if _, err := db.InsertOne(database.CollectionName, doc); err != nil {
|
||||
if err := database.InsertShare(db, share); err != nil {
|
||||
log.Println("DB insert error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ import (
|
||||
"pool-stats/database"
|
||||
"time"
|
||||
|
||||
"github.com/ostafen/clover/v2"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
type RecalculateCurrentDayStatsJob struct {
|
||||
DB *clover.DB
|
||||
DB *pgxpool.Pool
|
||||
}
|
||||
|
||||
func NewRecalculateCurrentDayStatsJob(db *clover.DB) *RecalculateCurrentDayStatsJob {
|
||||
func NewRecalculateCurrentDayStatsJob(db *pgxpool.Pool) *RecalculateCurrentDayStatsJob {
|
||||
return &RecalculateCurrentDayStatsJob{DB: db}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/ostafen/clover/v2"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
type RecalculateTimeWindowHighSharesJob struct {
|
||||
DB *clover.DB
|
||||
DB *pgxpool.Pool
|
||||
}
|
||||
|
||||
func NewRecalculateTimeWindowHighSharesJob(db *clover.DB) *RecalculateTimeWindowHighSharesJob {
|
||||
func NewRecalculateTimeWindowHighSharesJob(db *pgxpool.Pool) *RecalculateTimeWindowHighSharesJob {
|
||||
return &RecalculateTimeWindowHighSharesJob{DB: db}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,14 +9,14 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/ostafen/clover/v2"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
type RecalculateTopSharesJob struct {
|
||||
DB *clover.DB
|
||||
DB *pgxpool.Pool
|
||||
}
|
||||
|
||||
func NewRecalculateTopSharesJob(db *clover.DB) *RecalculateTopSharesJob {
|
||||
func NewRecalculateTopSharesJob(db *pgxpool.Pool) *RecalculateTopSharesJob {
|
||||
return &RecalculateTopSharesJob{DB: db}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user