aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/postgres
diff options
context:
space:
mode:
Diffstat (limited to 'weed/filer/postgres')
-rw-r--r--weed/filer/postgres/postgres_sql_gen.go6
-rw-r--r--weed/filer/postgres/postgres_store.go10
2 files changed, 10 insertions, 6 deletions
diff --git a/weed/filer/postgres/postgres_sql_gen.go b/weed/filer/postgres/postgres_sql_gen.go
index 21a87ef5a..6cee3d2da 100644
--- a/weed/filer/postgres/postgres_sql_gen.go
+++ b/weed/filer/postgres/postgres_sql_gen.go
@@ -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)
}
diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go
index ea9b1c71e..498c98f65 100644
--- a/weed/filer/postgres/postgres_store.go
+++ b/weed/filer/postgres/postgres_store.go
@@ -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)