mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	feat: mysql 支持编辑表结构、索引
This commit is contained in:
		@@ -357,7 +357,8 @@ func GetDbConn(d *entity.Db, db string) (*sql.DB, error) {
 | 
			
		||||
func getDsn(d *entity.Db, db string) string {
 | 
			
		||||
	var dsn string
 | 
			
		||||
	if d.Type == entity.DbTypeMysql {
 | 
			
		||||
		dsn = fmt.Sprintf("%s:%s@%s(%s:%d)/%s?timeout=8s", d.Username, d.Password, d.Network, d.Host, d.Port, db)
 | 
			
		||||
		// 更多参数参考:https://github.com/go-sql-driver/mysql#dsn-data-source-name
 | 
			
		||||
		dsn = fmt.Sprintf("%s:%s@%s(%s:%d)/%s?timeout=8s&multiStatements=true", d.Username, d.Password, d.Network, d.Host, d.Port, db)
 | 
			
		||||
		if d.Params != "" {
 | 
			
		||||
			dsn = fmt.Sprintf("%s&%s", dsn, d.Params)
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,13 +17,13 @@ const (
 | 
			
		||||
    WHERE table_schema = (SELECT database())`
 | 
			
		||||
 | 
			
		||||
	// mysql 索引信息
 | 
			
		||||
	MYSQL_INDEX_INFO = `SELECT index_name indexName, column_name columnName, index_type indexType,
 | 
			
		||||
	MYSQL_INDEX_INFO = `SELECT index_name indexName, group_concat(column_name) columnName, index_type indexType, non_unique nonUnique, 
 | 
			
		||||
	SEQ_IN_INDEX seqInIndex, INDEX_COMMENT indexComment
 | 
			
		||||
	FROM information_schema.STATISTICS 
 | 
			
		||||
    WHERE table_schema = (SELECT database()) AND table_name = '%s'`
 | 
			
		||||
    WHERE table_schema = (SELECT database()) AND table_name = '%s' GROUP by index_name`
 | 
			
		||||
 | 
			
		||||
	// mysql 列信息元数据
 | 
			
		||||
	MYSQL_COLUMN_MA = `SELECT table_name tableName, column_name columnName, column_type columnType,
 | 
			
		||||
	MYSQL_COLUMN_MA = `SELECT table_name tableName, column_name columnName, column_type columnType, column_default columnDefault,
 | 
			
		||||
	column_comment columnComment, column_key columnKey, extra, is_nullable nullable from information_schema.columns
 | 
			
		||||
	WHERE table_schema = (SELECT database()) AND table_name in (%s) ORDER BY tableName, ordinal_position`
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user