MCPcopy
hub / github.com/go-gorm/gorm / HasTable

Method HasTable

migrator/migrator.go:334–343  ·  view source on GitHub ↗

HasTable returns table exists or not for value, value could be a struct or string

(value interface{})

Source from the content-addressed store, hash-verified

332
333// HasTable returns table exists or not for value, value could be a struct or string
334func (m Migrator) HasTable(value interface{}) bool {
335 var count int64
336
337 m.RunWithValue(value, func(stmt *gorm.Statement) error {
338 currentDatabase := m.DB.Migrator().CurrentDatabase()
339 return m.DB.Raw("SELECT count(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ? AND table_type = ?", currentDatabase, stmt.Table, "BASE TABLE").Row().Scan(&count)
340 })
341
342 return count > 0
343}
344
345// RenameTable rename table from oldName to newName
346func (m Migrator) RenameTable(oldName, newName interface{}) error {

Callers

nothing calls this directly

Implementers 1

Migratormigrator/migrator.go

Calls 6

RunWithValueMethod · 0.95
CurrentDatabaseMethod · 0.65
MigratorMethod · 0.65
ScanMethod · 0.65
RowMethod · 0.65
RawMethod · 0.65

Tested by

no test coverage detected