Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hive.go SQL module #184

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions components/indexer/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (

"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/app/shutdown"
"github.com/iotaledger/hive.go/db"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/sql"
"github.com/iotaledger/inx-app/pkg/httpserver"
"github.com/iotaledger/inx-app/pkg/nodebridge"
"github.com/iotaledger/inx-indexer/pkg/daemon"
"github.com/iotaledger/inx-indexer/pkg/database"
"github.com/iotaledger/inx-indexer/pkg/indexer"
"github.com/iotaledger/inx-indexer/pkg/server"
inx "github.com/iotaledger/inx/go"
Expand Down Expand Up @@ -58,26 +59,27 @@ func provide(c *dig.Container) error {
if err := c.Provide(func() (*indexer.Indexer, error) {
Component.LogInfo("Setting up database ...")

engine, err := database.EngineFromString(ParamsIndexer.Database.Engine)
if err != nil {
return nil, err
}
engine := db.EngineFromString(ParamsIndexer.Database.Engine)

dbParams := database.Params{
dbParams := sql.DatabaseParameters{
Engine: engine,
}

//nolint:exhaustive // we already checked the values is one of the valid ones
switch engine {
case database.EngineSQLite:
case db.EngineSQLite:
dbParams.Path = ParamsIndexer.Database.SQLite.Path
dbParams.Filename = "indexer.db"

case database.EnginePostgreSQL:
case db.EnginePostgreSQL:
dbParams.Host = ParamsIndexer.Database.PostgreSQL.Host
dbParams.Port = ParamsIndexer.Database.PostgreSQL.Port
dbParams.Database = ParamsIndexer.Database.PostgreSQL.Database
dbParams.Username = ParamsIndexer.Database.PostgreSQL.Username
dbParams.Password = ParamsIndexer.Database.PostgreSQL.Password

default:
return nil, ierrors.Errorf("unknown database engine: %s, supported engines: %s", dbParams.Engine, db.GetSupportedEnginesString(indexer.AllowedEngines))
}

return indexer.NewIndexer(dbParams, Component.Logger)
Expand Down
32 changes: 17 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
module github.com/iotaledger/inx-indexer

go 1.22
go 1.22.0

require (
github.com/ethereum/go-ethereum v1.13.12
github.com/ethereum/go-ethereum v1.13.13
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/iotaledger/hive.go/app v0.0.0-20240216135101-261e99d9d84a
github.com/iotaledger/hive.go/crypto v0.0.0-20240216135101-261e99d9d84a
github.com/iotaledger/hive.go/ds v0.0.0-20240216135101-261e99d9d84a
github.com/iotaledger/hive.go/ierrors v0.0.0-20240216135101-261e99d9d84a
github.com/iotaledger/hive.go/lo v0.0.0-20240216135101-261e99d9d84a
github.com/iotaledger/hive.go/log v0.0.0-20240216135101-261e99d9d84a
github.com/iotaledger/hive.go/runtime v0.0.0-20240216135101-261e99d9d84a
github.com/iotaledger/hive.go/app v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/crypto v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/db v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/ds v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/ierrors v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/lo v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/log v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/runtime v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/hive.go/sql v0.0.0-20240223142044-12ffcb37c413
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240216141618-d7dfe94bdc1e
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240216141023-6d5f4ef12ac5
github.com/iotaledger/iota.go/v4 v4.0.0-20240216140514-c867d6524642
Expand All @@ -22,8 +24,6 @@ require (
github.com/stretchr/testify v1.8.4
go.uber.org/dig v1.17.1
golang.org/x/text v0.14.0
gorm.io/driver/postgres v1.5.6
gorm.io/driver/sqlite v1.5.5
gorm.io/gorm v1.25.7
)

Expand All @@ -49,10 +49,10 @@ require (
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/hive.go/constraints v0.0.0-20240216135101-261e99d9d84a // indirect
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20240216135101-261e99d9d84a // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240216135101-261e99d9d84a // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20240216135101-261e99d9d84a // indirect
github.com/iotaledger/hive.go/constraints v0.0.0-20240223142044-12ffcb37c413 // indirect
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20240223142044-12ffcb37c413 // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240223142044-12ffcb37c413 // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20240223142044-12ffcb37c413 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgx/v5 v5.5.3 // indirect
Expand Down Expand Up @@ -91,4 +91,6 @@ require (
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.6 // indirect
gorm.io/driver/sqlite v1.5.5 // indirect
)
52 changes: 28 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/go-ethereum v1.13.12 h1:iDr9UM2JWkngBHGovRJEQn4Kor7mT4gt9rUZqB5M29Y=
github.com/ethereum/go-ethereum v1.13.12/go.mod h1:hKL2Qcj1OvStXNSEDbucexqnEt1Wh4Cz329XsjAalZY=
github.com/ethereum/go-ethereum v1.13.13 h1:KYn9w7pEWRI9oyZOzO94OVbctSusPByHdFDPj634jII=
github.com/ethereum/go-ethereum v1.13.13/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
Expand Down Expand Up @@ -186,28 +186,32 @@ github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXei
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/iotaledger/hive.go/app v0.0.0-20240216135101-261e99d9d84a h1:o5viyYlzi6kgClLNgUW5Pay0tXMylc0FPivYgSlAc4g=
github.com/iotaledger/hive.go/app v0.0.0-20240216135101-261e99d9d84a/go.mod h1:O9agBfrnt1ykrDOzF6GXZf4ivcw+SxM9c9C86YtbxLU=
github.com/iotaledger/hive.go/constraints v0.0.0-20240216135101-261e99d9d84a h1:9xeffzciYdw9L/ebAOPg/39Bqn3p5iyOROQhQHaAEUs=
github.com/iotaledger/hive.go/constraints v0.0.0-20240216135101-261e99d9d84a/go.mod h1:JF7jjkL6tSUOXm23SWadBzBrl7eJk1DQRLc/fNoVZ+o=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20240216135101-261e99d9d84a h1:+l3NjL4v700Iv+ZF7KjPALkygFOxzkByoRIoSK9bOzc=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20240216135101-261e99d9d84a/go.mod h1:9HM/YmzOfdlWXYHVEWVjYhKQHOlgxBVMsr5Vf5yn5IE=
github.com/iotaledger/hive.go/crypto v0.0.0-20240216135101-261e99d9d84a h1:ux81+J6mcxYw6usZpEPLZjE6J+TNs3RaRcTHa9+5ERM=
github.com/iotaledger/hive.go/crypto v0.0.0-20240216135101-261e99d9d84a/go.mod h1:7kZh98nwJInQsIybiPXSABc/on/IsDdXyeiPLfaH+2I=
github.com/iotaledger/hive.go/ds v0.0.0-20240216135101-261e99d9d84a h1:7M1+k0H53jahg2ZDN10SociepCB+jymIZoiYaSenpbQ=
github.com/iotaledger/hive.go/ds v0.0.0-20240216135101-261e99d9d84a/go.mod h1:sE/HabIH9FWTvgaHioLN6o4rrxFMf4BuqRQwloxcamo=
github.com/iotaledger/hive.go/ierrors v0.0.0-20240216135101-261e99d9d84a h1:ugcQ43xbMZo5XYTfanIHOxQGKNpxhcatcz9ZXcX6W1o=
github.com/iotaledger/hive.go/ierrors v0.0.0-20240216135101-261e99d9d84a/go.mod h1:GQY0/35sjgT9Poi1Vrs9kFVvAkuKzGXfVh4j6CBXsAA=
github.com/iotaledger/hive.go/lo v0.0.0-20240216135101-261e99d9d84a h1:eUAtyEIYRlAPeZ2qhlEA+7T8DVoYK2h9eotlst/84SU=
github.com/iotaledger/hive.go/lo v0.0.0-20240216135101-261e99d9d84a/go.mod h1:0ycE1W59kkNjQ87odL6H4x5Ik9bXhbNk88wmo+mIYt0=
github.com/iotaledger/hive.go/log v0.0.0-20240216135101-261e99d9d84a h1:XzIuUsWPtDP7h9UbQPFW5/bjeqVjodcSCMRuF7zP5jk=
github.com/iotaledger/hive.go/log v0.0.0-20240216135101-261e99d9d84a/go.mod h1:JCv/LVVTAMoCPLzou534RoIif7CAezcWZlGYabrHsck=
github.com/iotaledger/hive.go/runtime v0.0.0-20240216135101-261e99d9d84a h1:qmfoYLK2XyPOXfldG21qHyCrbIf0sl7iJoFirvTrnO0=
github.com/iotaledger/hive.go/runtime v0.0.0-20240216135101-261e99d9d84a/go.mod h1:lAR3vbqE9g65M9VwWHiaXab2q+d89dBOFjhKgnDfK7c=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240216135101-261e99d9d84a h1:ahUFo0X9Th+8/aE6KSWiy7Eap5p0YFL6CDapP1o8dLo=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240216135101-261e99d9d84a/go.mod h1:yXQNGZUz++dB1T9RAHhWSresuTLzTC856ntdins9ivo=
github.com/iotaledger/hive.go/stringify v0.0.0-20240216135101-261e99d9d84a h1:xLreq/rXeSPdb86RnZNEPH3PUIWt56BQxK1+11+hM4I=
github.com/iotaledger/hive.go/stringify v0.0.0-20240216135101-261e99d9d84a/go.mod h1:O4p7UmsfoeLqtAUwrKbq0lXMxjY/MLQSpZSavvvvGig=
github.com/iotaledger/hive.go/app v0.0.0-20240223142044-12ffcb37c413 h1:+a11iU2tJrQthoU4N4UPls008IBFamfepeb7EKHjZ6E=
github.com/iotaledger/hive.go/app v0.0.0-20240223142044-12ffcb37c413/go.mod h1:EMUpj6oDb/QSiVpIe5nYwyDKSpO6ue7mdkzmK/VoBn8=
github.com/iotaledger/hive.go/constraints v0.0.0-20240223142044-12ffcb37c413 h1:WWuXcr//V/8aZNW64TJ9delPMgVzxAgcHL5aV/bi5Ko=
github.com/iotaledger/hive.go/constraints v0.0.0-20240223142044-12ffcb37c413/go.mod h1:JF7jjkL6tSUOXm23SWadBzBrl7eJk1DQRLc/fNoVZ+o=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20240223142044-12ffcb37c413 h1:iav0P4TvMmEkbG/bryl0p8GKeIebuXchdIMS4GuJufI=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20240223142044-12ffcb37c413/go.mod h1:73ODTHUJxAoGUN0InOtuQ29LVq85pDf7GckM9d0ziqo=
github.com/iotaledger/hive.go/crypto v0.0.0-20240223142044-12ffcb37c413 h1:1GR1t/N5bUCH38oN6fJD2JcRSOf8yAhiDJigqmuCcVQ=
github.com/iotaledger/hive.go/crypto v0.0.0-20240223142044-12ffcb37c413/go.mod h1:aREIB19gIhSYdY0Hl/37sg1JRH7+j3ajeJxBIQf6mig=
github.com/iotaledger/hive.go/db v0.0.0-20240223142044-12ffcb37c413 h1:Q/FcxgM1G/iCY4HYNmuXGg/MIW9Su+9akeiQwYdv2lU=
github.com/iotaledger/hive.go/db v0.0.0-20240223142044-12ffcb37c413/go.mod h1:8Y5vqE5NK5zG4Af0JV2UQeW67iLlymPLsT1KkOn4qY8=
github.com/iotaledger/hive.go/ds v0.0.0-20240223142044-12ffcb37c413 h1:cQsuww6lGaOhVDyrOngWHWMeNKiXPsKkC9fNHFm2EDE=
github.com/iotaledger/hive.go/ds v0.0.0-20240223142044-12ffcb37c413/go.mod h1:wfjeJj9B+MM/3yeUHfvT8Gj8bRsdl9utyh2dZg+1+B0=
github.com/iotaledger/hive.go/ierrors v0.0.0-20240223142044-12ffcb37c413 h1:Cf9Bfs+mEyuExJ1HwWTzbaRWQ+tEF8sTxon5/fGUUsk=
github.com/iotaledger/hive.go/ierrors v0.0.0-20240223142044-12ffcb37c413/go.mod h1:GQY0/35sjgT9Poi1Vrs9kFVvAkuKzGXfVh4j6CBXsAA=
github.com/iotaledger/hive.go/lo v0.0.0-20240223142044-12ffcb37c413 h1:uSEoXnPE3FjeV9RNZNqIZTTb8v/8EGBMw1rbaiC3x9M=
github.com/iotaledger/hive.go/lo v0.0.0-20240223142044-12ffcb37c413/go.mod h1:67oLzWYiBLGt5PN7IBVHdbt9P6oBYCx9UvMEL8ExDAc=
github.com/iotaledger/hive.go/log v0.0.0-20240223142044-12ffcb37c413 h1:4xKFtHoOy1YCnq6g8T7Dr+a3tDGG338yLDXRSichwE4=
github.com/iotaledger/hive.go/log v0.0.0-20240223142044-12ffcb37c413/go.mod h1:H5tmswUbT3o5+QiM6UPtBv7VnPf+lJtlantgpp2lzUI=
github.com/iotaledger/hive.go/runtime v0.0.0-20240223142044-12ffcb37c413 h1:7O3oSoXlwV5L3/+kt/a1MN3Kwb5oXaaSZaa+aabh7BM=
github.com/iotaledger/hive.go/runtime v0.0.0-20240223142044-12ffcb37c413/go.mod h1:pueoYXud+HmTY2x9j/S6+ZX3M5ZyENFKPDrx3EtcwWs=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240223142044-12ffcb37c413 h1:tQW0K9Ogyfgm3V0wYhRPChOYgrADGlRWF6P4gMY8Zbg=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20240223142044-12ffcb37c413/go.mod h1:NK05G4PxwZF1m4jGANJWLhAQ2hP1Nt0L8mgCTFLsSCw=
github.com/iotaledger/hive.go/sql v0.0.0-20240223142044-12ffcb37c413 h1:Bmb5/3PqvGdpWezMQQqLODukPM7DmDQHxFbrlrTuoKM=
github.com/iotaledger/hive.go/sql v0.0.0-20240223142044-12ffcb37c413/go.mod h1:O9R4vLdoSBhEO+WyEEmBHKChlD80oz9EVi7vjuxE+J8=
github.com/iotaledger/hive.go/stringify v0.0.0-20240223142044-12ffcb37c413 h1:QCidFFczZH9NEJTWm0ZzZKMaQ0XUxYyU00dpaH+skqs=
github.com/iotaledger/hive.go/stringify v0.0.0-20240223142044-12ffcb37c413/go.mod h1:O4p7UmsfoeLqtAUwrKbq0lXMxjY/MLQSpZSavvvvGig=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240216141618-d7dfe94bdc1e h1:I6KnVRg96X7mL1k/h3xovdJL3I31q8C6wPiUJanvOdY=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20240216141618-d7dfe94bdc1e/go.mod h1:rCLE9iv2S0qiL4s7TPj/2ieTLhV2m0Nor3g2JJHhu6M=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20240216141023-6d5f4ef12ac5 h1:ebh2IKHPVG/qMjTk56hIBG9DcZ0XN02pP8UJ+vB2IpM=
Expand Down
Loading
Loading