diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2021-03-29 00:42:48 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-29 00:42:48 -0700 |
| commit | 1ebdbad222207c858e9f1285bc7d854f7a943754 (patch) | |
| tree | 5e9f8b8ac16d2e3cb795f85b49d0352e20cffeb3 /weed/filer/postgres | |
| parent | 6b7aa9633fcffe36b29961108d1d811952ab093a (diff) | |
| parent | 96c62bd34d4d2c99dea3164a9c062abaddb4eaab (diff) | |
| download | seaweedfs-1ebdbad222207c858e9f1285bc7d854f7a943754.tar.xz seaweedfs-1ebdbad222207c858e9f1285bc7d854f7a943754.zip | |
Merge pull request #1946 from LazyDBA247-Anyvision/master
Adding Customisation - insertQuery for postgres/mysql
Diffstat (limited to 'weed/filer/postgres')
| -rw-r--r-- | weed/filer/postgres/postgres_sql_gen.go | 7 | ||||
| -rw-r--r-- | weed/filer/postgres/postgres_store.go | 4 |
2 files changed, 9 insertions, 2 deletions
diff --git a/weed/filer/postgres/postgres_sql_gen.go b/weed/filer/postgres/postgres_sql_gen.go index 0d1c343c5..21a87ef5a 100644 --- a/weed/filer/postgres/postgres_sql_gen.go +++ b/weed/filer/postgres/postgres_sql_gen.go @@ -10,6 +10,7 @@ import ( type SqlGenPostgres struct { CreateTableSqlTemplate string DropTableSqlTemplate string + InsertQueryTemplate string } var ( @@ -17,7 +18,11 @@ var ( ) func (gen *SqlGenPostgres) GetSqlInsert(tableName string) string { - return fmt.Sprintf(`INSERT INTO "%s" (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)`, tableName) + if gen.InsertQueryTemplate != "" { + return fmt.Sprintf(gen.InsertQueryTemplate, tableName) + } else { + return fmt.Sprintf(`INSERT INTO "%s" (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)`, tableName) + } } func (gen *SqlGenPostgres) GetSqlUpdate(tableName string) string { diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go index 9e4ff7c32..ea9b1c71e 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -29,6 +29,7 @@ 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+"username"), configuration.GetString(prefix+"password"), configuration.GetString(prefix+"hostname"), @@ -42,12 +43,13 @@ func (store *PostgresStore) Initialize(configuration util.Configuration, prefix ) } -func (store *PostgresStore) initialize(user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) { +func (store *PostgresStore) initialize(insertQuery, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) { store.SupportBucketTable = false store.SqlGenerator = &SqlGenPostgres{ CreateTableSqlTemplate: "", DropTableSqlTemplate: `drop table "%s"`, + InsertQueryTemplate: insertQuery, } sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) |
