diff --git a/pkg/dbsql/postgres_helpers.go b/pkg/dbsql/postgres_helpers.go index 287eae3..85ede8c 100644 --- a/pkg/dbsql/postgres_helpers.go +++ b/pkg/dbsql/postgres_helpers.go @@ -26,6 +26,19 @@ import ( "github.com/hyperledger-firefly/common/pkg/i18n" ) +// PostgreSQLMaxPlaceholders is the limit on bind parameters in one statement, set by the PostgreSQL wire protocol +const PostgreSQLMaxPlaceholders = 65535 + +// DefaultPostgreSQLProviderFeatures are the features shared by PostgreSQL providers, which can add their own on top +func DefaultPostgreSQLProviderFeatures() SQLFeatures { + features := DefaultSQLProviderFeatures() + features.PlaceholderFormat = sq.Dollar + features.MultiRowInsert = true + features.MaxPlaceholders = PostgreSQLMaxPlaceholders + features.DBOptimizedUpsertBuilder = BuildPostgreSQLOptimizedUpsert + return features +} + // BuildPostgreSQLOptimizedUpsert is a PostgreSQL helper to avoid implementing this lots of times in child packages func BuildPostgreSQLOptimizedUpsert(ctx context.Context, table string, idColumn string, insertCols, updateCols []string, returnCol string, values map[string]driver.Value) (insert sq.InsertBuilder, err error) { insertValues := make([]interface{}, 0, len(insertCols)) diff --git a/pkg/dbsql/postgres_helpers_test.go b/pkg/dbsql/postgres_helpers_test.go index 9ad857c..362bdd0 100644 --- a/pkg/dbsql/postgres_helpers_test.go +++ b/pkg/dbsql/postgres_helpers_test.go @@ -21,6 +21,7 @@ import ( "database/sql/driver" "testing" + sq "github.com/Masterminds/squirrel" "github.com/hyperledger-firefly/common/pkg/fftypes" "github.com/stretchr/testify/assert" ) @@ -60,3 +61,13 @@ func TestBuildPostgreSQLOptimizedUpsertFail(t *testing.T) { assert.Regexp(t, "FF00247", err) } + +func TestDefaultPostgreSQLProviderFeatures(t *testing.T) { + + features := DefaultPostgreSQLProviderFeatures() + assert.Equal(t, sq.Dollar, features.PlaceholderFormat) + assert.True(t, features.MultiRowInsert) + assert.Equal(t, 65535, features.MaxPlaceholders) + assert.NotNil(t, features.DBOptimizedUpsertBuilder) + +}