add enableUpsert=true

and rename config to upsertQuery
This commit is contained in:
LazyDBA247-Anyvision
2021-03-30 00:32:03 +03:00
parent 3cf84b5fae
commit 4c51e6a660
7 changed files with 46 additions and 34 deletions

View File

@@ -10,7 +10,7 @@ import (
type SqlGenPostgres struct {
CreateTableSqlTemplate string
DropTableSqlTemplate string
InsertQueryTemplate string
UpsertQueryTemplate string
}
var (
@@ -18,8 +18,8 @@ var (
)
func (gen *SqlGenPostgres) GetSqlInsert(tableName string) string {
if gen.InsertQueryTemplate != "" {
return fmt.Sprintf(gen.InsertQueryTemplate, tableName)
if gen.UpsertQueryTemplate != "" {
return fmt.Sprintf(gen.UpsertQueryTemplate, tableName)
} else {
return fmt.Sprintf(`INSERT INTO "%s" (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)`, tableName)
}

View File

@@ -29,7 +29,8 @@ func (store *PostgresStore) GetName() string {
func (store *PostgresStore) Initialize(configuration util.Configuration, prefix string) (err error) {
return store.initialize(
configuration.GetString(prefix+"insertQuery"),
configuration.GetString(prefix+"upsertQuery"),
configuration.GetString(prefix+"enableUpsert"),
configuration.GetString(prefix+"username"),
configuration.GetString(prefix+"password"),
configuration.GetString(prefix+"hostname"),
@@ -43,13 +44,16 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix
)
}
func (store *PostgresStore) initialize(insertQuery, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) {
func (store *PostgresStore) initialize(upsertQuery, enableUpsert, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) {
store.SupportBucketTable = false
if !enableUpsert {
upsertQuery = ""
}
store.SqlGenerator = &SqlGenPostgres{
CreateTableSqlTemplate: "",
DropTableSqlTemplate: `drop table "%s"`,
InsertQueryTemplate: insertQuery,
UpsertQueryTemplate: upsertQuery,
}
sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode)