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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user