forked from go-gorm/gorm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialect_postgres_go1.8.go
34 lines (27 loc) · 1 KB
/
dialect_postgres_go1.8.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// +build go1.8
package gorm
import "context"
func (s postgres) HasIndex(tableName string, indexName string) bool {
var count int
s.db.QueryRowContext(context.Background(), queryPostgresHasIndex, tableName, indexName).Scan(&count)
return count > 0
}
func (s postgres) HasForeignKey(tableName string, foreignKeyName string) bool {
var count int
s.db.QueryRowContext(context.Background(), queryPostgresHasForeignKey, tableName, foreignKeyName).Scan(&count)
return count > 0
}
func (s postgres) HasTable(tableName string) bool {
var count int
s.db.QueryRowContext(context.Background(), queryPostgresHasTable, tableName).Scan(&count)
return count > 0
}
func (s postgres) HasColumn(tableName string, columnName string) bool {
var count int
s.db.QueryRowContext(context.Background(), queryPostgresHasColumn, tableName, columnName).Scan(&count)
return count > 0
}
func (s postgres) CurrentDatabase() (name string) {
s.db.QueryRowContext(context.Background(), queryPostgresCurrentDatabase).Scan(&name)
return
}