MCPcopy Create free account
hub / github.com/cloudwan/gohan / GenTableDef

Method GenTableDef

db/sql/sql.go:538–554  ·  view source on GitHub ↗

GenTableDef generates create table sql

(s *schema.Schema, cascade bool)

Source from the content-addressed store, hash-verified

536
537//GenTableDef generates create table sql
538func (db *DB) GenTableDef(s *schema.Schema, cascade bool) (string, []string) {
539 cols, relations, indices := db.genTableCols(s, cascade, nil)
540
541 if s.StateVersioning() {
542 cols = append(cols, quote(configVersionColumnName)+"int not null default 1")
543 cols = append(cols, quote(stateVersionColumnName)+"int not null default 0")
544 cols = append(cols, quote(stateErrorColumnName)+"text not null default ''")
545 cols = append(cols, quote(stateColumnName)+"text not null default ''")
546 cols = append(cols, quote(stateMonitoringColumnName)+"text not null default ''")
547 }
548
549 cols = append(cols, relations...)
550 tableSQL := fmt.Sprintf("create table `%s` (%s);\n", s.GetDbTableName(), strings.Join(cols, ","))
551 log.Debug("Creating table: " + tableSQL)
552 log.Debug("Creating indices: " + strings.Join(indices, ""))
553 return tableSQL, indices
554}
555
556//RegisterTable creates table in the db
557func (db *DB) RegisterTable(s *schema.Schema, cascade, migrate bool) error {

Callers 3

RegisterTableMethod · 0.95
sql_test.goFile · 0.80

Implementers 4

DBdb/sql/sql.go
MockDBdb/mocks/db.go
MockDBMockRecorderdb/mocks/db.go
DBdb/file/file.go

Calls 6

genTableColsMethod · 0.95
StateVersioningMethod · 0.80
GetDbTableNameMethod · 0.80
JoinMethod · 0.80
quoteFunction · 0.70
DebugMethod · 0.65

Tested by

no test coverage detected