2023-06-14 12:43:34 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2021 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package sql
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
|
2023-06-23 12:42:55 +00:00
|
|
|
"github.com/cerc-io/plugeth-statediff/indexer/database/metrics"
|
2023-06-14 12:43:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Database interfaces required by the sql indexer
|
|
|
|
type Database interface {
|
|
|
|
Driver
|
|
|
|
Statements
|
|
|
|
}
|
|
|
|
|
|
|
|
// Driver interface has all the methods required by a driver implementation to support the sql indexer
|
|
|
|
type Driver interface {
|
|
|
|
UseCopyFrom() bool
|
|
|
|
QueryRow(ctx context.Context, sql string, args ...interface{}) ScannableRow
|
|
|
|
Exec(ctx context.Context, sql string, args ...interface{}) (Result, error)
|
|
|
|
Select(ctx context.Context, dest interface{}, query string, args ...interface{}) error
|
|
|
|
Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error
|
|
|
|
Begin(ctx context.Context) (Tx, error)
|
|
|
|
Stats() metrics.DbStats
|
|
|
|
NodeID() string
|
|
|
|
Context() context.Context
|
|
|
|
io.Closer
|
|
|
|
}
|
|
|
|
|
|
|
|
// Statements interface to accommodate different SQL query syntax
|
|
|
|
type Statements interface {
|
2023-06-24 04:04:57 +00:00
|
|
|
DetectGapsStm() string
|
|
|
|
MaxHeaderStm() string
|
2023-06-21 15:49:57 +00:00
|
|
|
ExistsHeaderStm() string
|
2023-06-14 12:43:34 +00:00
|
|
|
InsertHeaderStm() string
|
2023-07-20 02:15:48 +00:00
|
|
|
SetCanonicalHeaderStm() string
|
2023-06-14 12:43:34 +00:00
|
|
|
InsertUncleStm() string
|
|
|
|
InsertTxStm() string
|
|
|
|
InsertRctStm() string
|
|
|
|
InsertLogStm() string
|
2024-05-07 16:23:32 +00:00
|
|
|
InsertWithdrawalStm() string
|
2023-06-14 12:43:34 +00:00
|
|
|
InsertStateStm() string
|
|
|
|
InsertStorageStm() string
|
|
|
|
InsertIPLDStm() string
|
|
|
|
InsertIPLDsStm() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tx interface to accommodate different concrete SQL transaction types
|
|
|
|
type Tx interface {
|
|
|
|
QueryRow(ctx context.Context, sql string, args ...interface{}) ScannableRow
|
|
|
|
Exec(ctx context.Context, sql string, args ...interface{}) (Result, error)
|
|
|
|
CopyFrom(ctx context.Context, tableName []string, columnNames []string, rows [][]interface{}) (int64, error)
|
|
|
|
Commit(ctx context.Context) error
|
|
|
|
Rollback(ctx context.Context) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// ScannableRow interface to accommodate different concrete row types
|
|
|
|
type ScannableRow interface {
|
|
|
|
Scan(dest ...interface{}) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Result interface to accommodate different concrete result types
|
|
|
|
type Result interface {
|
|
|
|
RowsAffected() (int64, error)
|
|
|
|
}
|