SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
Adding custom insertQuery support for postgres/2 mysql/2
LazyDBA247-Anyvision4a02389eb08c
diff --git a/weed/filer/mysql/mysql_sql_gen.go b/weed/filer/mysql/mysql_sql_gen.goindex 2f86a57987..105f3e62af 100644--- a/weed/filer/mysql/mysql_sql_gen.go+++ b/weed/filer/mysql/mysql_sql_gen.go@@ -2,6 +2,7 @@ package mysqlimport ("fmt"+"github.com/chrislusf/seaweedfs/weed/filer/abstract_sql"_ "github.com/go-sql-driver/mysql")@@ -9,6 +10,7 @@ import (type SqlGenMysql struct {CreateTableSqlTemplate stringDropTableSqlTemplate string+ InsertQueryTemplate string}var (@@ -16,7 +18,11 @@ var ()func (gen *SqlGenMysql) GetSqlInsert(tableName string) string {- return fmt.Sprintf("INSERT INTO `%s` (dirhash,name,directory,meta) VALUES(?,?,?,?)", tableName)+ if gen.InsertQueryTemplate != "" {+ return fmt.Sprintf(gen.InsertQueryTemplate, tableName)+ } else {+ return fmt.Sprintf("INSERT INTO `%s` (dirhash,name,directory,meta) VALUES(?,?,?,?)", tableName)+ }}func (gen *SqlGenMysql) GetSqlUpdate(tableName string) string {diff --git a/weed/filer/mysql/mysql_store.go b/weed/filer/mysql/mysql_store.goindex 501ab1d39a..4b73faacf7 100644--- a/weed/filer/mysql/mysql_store.go+++ b/weed/filer/mysql/mysql_store.go@@ -3,9 +3,10 @@ package mysqlimport ("database/sql""fmt"- "github.com/chrislusf/seaweedfs/weed/filer""time"+ "github.com/chrislusf/seaweedfs/weed/filer"+"github.com/chrislusf/seaweedfs/weed/filer/abstract_sql""github.com/chrislusf/seaweedfs/weed/util"_ "github.com/go-sql-driver/mysql"@@ -29,6 +30,7 @@ func (store *MysqlStore) GetName() string {func (store *MysqlStore) 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"),@@ -41,13 +43,14 @@ func (store *MysqlStore) Initialize(configuration util.Configuration, prefix str)}-func (store *MysqlStore) initialize(user, password, hostname string, port int, database string, maxIdle, maxOpen,+func (store *MysqlStore) initialize(insertQuery, user, password, hostname string, port int, database string, maxIdle, maxOpen,maxLifetimeSeconds int, interpolateParams bool) (err error) {store.SupportBucketTable = falsestore.SqlGenerator = &SqlGenMysql{CreateTableSqlTemplate: "",DropTableSqlTemplate: "drop table `%s`",+ InsertQueryTemplate: insertQuery,}sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database)diff --git a/weed/filer/mysql2/mysql2_store.go b/weed/filer/mysql2/mysql2_store.goindex c796cd6aaf..3c51f93632 100644--- a/weed/filer/mysql2/mysql2_store.go+++ b/weed/filer/mysql2/mysql2_store.go@@ -32,6 +32,7 @@ func (store *MysqlStore2) GetName() string {func (store *MysqlStore2) Initialize(configuration util.Configuration, prefix string) (err error) {return store.initialize(configuration.GetString(prefix+"createTable"),+ configuration.GetString(prefix+"insertQuery"),configuration.GetString(prefix+"username"),configuration.GetString(prefix+"password"),configuration.GetString(prefix+"hostname"),@@ -44,13 +45,14 @@ func (store *MysqlStore2) Initialize(configuration util.Configuration, prefix st)}-func (store *MysqlStore2) initialize(createTable, user, password, hostname string, port int, database string, maxIdle, maxOpen,+func (store *MysqlStore2) initialize(createTable, insertQuery, user, password, hostname string, port int, database string, maxIdle, maxOpen,maxLifetimeSeconds int, interpolateParams bool) (err error) {store.SupportBucketTable = truestore.SqlGenerator = &mysql.SqlGenMysql{CreateTableSqlTemplate: createTable,DropTableSqlTemplate: "drop table `%s`",+ InsertQueryTemplate: insertQuery,}sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database)diff --git a/weed/filer/postgres/postgres_sql_gen.go b/weed/filer/postgres/postgres_sql_gen.goindex 0d1c343c56..21a87ef5a7 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 stringDropTableSqlTemplate 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.goindex 9e4ff7c328..ea9b1c71ea 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 = falsestore.SqlGenerator = &SqlGenPostgres{CreateTableSqlTemplate: "",DropTableSqlTemplate: `drop table "%s"`,+ InsertQueryTemplate: insertQuery,}sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode)diff --git a/weed/filer/postgres2/postgres2_store.go b/weed/filer/postgres2/postgres2_store.goindex 92893bf7aa..b83945db6e 100644--- a/weed/filer/postgres2/postgres2_store.go+++ b/weed/filer/postgres2/postgres2_store.go@@ -32,6 +32,7 @@ func (store *PostgresStore2) GetName() string {func (store *PostgresStore2) Initialize(configuration util.Configuration, prefix string) (err error) {return store.initialize(configuration.GetString(prefix+"createTable"),+ configuration.GetString(prefix+"insertQuery"),configuration.GetString(prefix+"username"),configuration.GetString(prefix+"password"),configuration.GetString(prefix+"hostname"),@@ -45,12 +46,13 @@ func (store *PostgresStore2) Initialize(configuration util.Configuration, prefix)}-func (store *PostgresStore2) initialize(createTable, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) {+func (store *PostgresStore2) initialize(createTable, insertQuery, user, password, hostname string, port int, database, schema, sslmode string, maxIdle, maxOpen, maxLifetimeSeconds int) (err error) {store.SupportBucketTable = truestore.SqlGenerator = &postgres.SqlGenPostgres{CreateTableSqlTemplate: createTable,DropTableSqlTemplate: `drop table "%s"`,+ InsertQueryTemplate: insertQuery,}sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode)