Pārlūkot izejas kodu

add CreateIndexSql func

xormplus 8 gadi atpakaļ
vecāks
revīzija
f3dd398399
4 mainītis faili ar 27 papildinājumiem un 3 dzēšanām
  1. 9 3
      dialect_mssql.go
  2. 6 0
      dialect_mysql.go
  3. 6 0
      dialect_postgres.go
  4. 6 0
      dialect_sqlite3.go

+ 9 - 3
dialect_mssql.go

@@ -340,12 +340,12 @@ func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column
 	s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale,a.is_nullable as nullable,
 	      replace(replace(isnull(c.text,''),'(',''),')','') as vdefault,
 		  ISNULL(i.is_primary_key, 0)
-          from sys.columns a 
+          from sys.columns a
 		  left join sys.types b on a.user_type_id=b.user_type_id
           left join sys.syscomments c on a.default_object_id=c.id
-		  LEFT OUTER JOIN 
+		  LEFT OUTER JOIN
     sys.index_columns ic ON ic.object_id = a.object_id AND ic.column_id = a.column_id
-		  LEFT OUTER JOIN 
+		  LEFT OUTER JOIN
     sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
           where a.object_id=object_id('` + tableName + `')`
 	db.LogSQL(s, args)
@@ -536,6 +536,12 @@ func (db *mssql) ForUpdateSql(query string) string {
 	return query
 }
 
+func (db *mssql) CreateIndexSql(tableName string, index *core.Index) string {
+	quote := db.Quote
+	return fmt.Sprintf("CREATE INDEX %v ON %v (%v);", quote(indexName(tableName, index.Name)),
+		quote(tableName), quote(strings.Join(index.Cols, quote(","))))
+}
+
 func (db *mssql) Filters() []core.Filter {
 	return []core.Filter{&core.IdFilter{}, &core.QuoteFilter{}}
 }

+ 6 - 0
dialect_mysql.go

@@ -487,6 +487,12 @@ func (db *mysql) GetIndexes(tableName string) (map[string]*core.Index, error) {
 	return indexes, nil
 }
 
+func (db *mysql) CreateIndexSql(tableName string, index *core.Index) string {
+	quote := db.Quote
+	return fmt.Sprintf("CREATE INDEX %v ON %v (%v);", quote(indexName(tableName, index.Name)),
+		quote(tableName), quote(strings.Join(index.Cols, quote(","))))
+}
+
 func (db *mysql) Filters() []core.Filter {
 	return []core.Filter{&core.IdFilter{}}
 }

+ 6 - 0
dialect_postgres.go

@@ -889,6 +889,12 @@ func (db *postgres) ModifyColumnSql(tableName string, col *core.Column) string {
 		tableName, col.Name, db.SqlType(col))
 }
 
+func (db *postgres) CreateIndexSql(tableName string, index *core.Index) string {
+	quote := db.Quote
+	return fmt.Sprintf("CREATE INDEX %v ON %v (%v);", quote(indexName(tableName, index.Name)),
+		quote(tableName), quote(strings.Join(index.Cols, quote(","))))
+}
+
 func (db *postgres) DropIndexSql(tableName string, index *core.Index) string {
 	//var unique string
 	quote := db.Quote

+ 6 - 0
dialect_sqlite3.go

@@ -232,6 +232,12 @@ func (db *sqlite3) TableCheckSql(tableName string) (string, []interface{}) {
 	return "SELECT name FROM sqlite_master WHERE type='table' and name = ?", args
 }
 
+func (db *sqlite3) CreateIndexSql(tableName string, index *core.Index) string {
+	quote := db.Quote
+	return fmt.Sprintf("CREATE INDEX %v ON %v (%v);", quote(indexName(tableName, index.Name)),
+		quote(tableName), quote(strings.Join(index.Cols, quote(","))))
+}
+
 func (db *sqlite3) DropIndexSql(tableName string, index *core.Index) string {
 	//var unique string
 	quote := db.Quote