Create table method

This commit is contained in:
Jinzhu 2013-10-26 15:47:30 +08:00
parent 1ddc8e3984
commit 70315e8fed
4 changed files with 22 additions and 1 deletions

View File

@ -79,3 +79,9 @@ func (s *DB) Exec(sql string) (orm *Orm) {
orm.Exec(sql)
return
}
func (s *DB) CreateTable(value interface{}) (orm *Orm) {
orm = s.buildORM()
orm.CreateTable(value)
return
}

4
orm.go
View File

@ -126,3 +126,7 @@ func (s *Orm) Or(querystring interface{}, args ...interface{}) *Orm {
func (s *Orm) Not(querystring interface{}, args ...interface{}) *Orm {
return s
}
func (s *Orm) CreateTable(value interface{}) *Orm {
return s
}

View File

@ -7,7 +7,7 @@ type User struct {
}
func getDB() DB {
db, _ := Open("postgres", "user=gorm dbname=gorm sslmode=disable")
db, _ := Open("postgres", "user=gorm dbname=gorm sslmode=disable")
return db
}

11
sql.go
View File

@ -17,6 +17,8 @@ func (s *Orm) explain(value interface{}, operation string) *Orm {
s.deleteSql(value)
case "Query":
s.querySql(value)
case "CreateTable":
s.createTableSql(value)
}
return s
}
@ -101,3 +103,12 @@ func (s *Orm) whereSql() (sql string) {
}
return
}
func (s *Orm) createTableSql(value interface{}) {
s.Sql = fmt.Sprintf(
"CREATE TABLE \"%v\" (%v)",
s.TableName,
"",
)
return
}