From 70315e8fed3ec50466ee9ce15da440b33ce53803 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sat, 26 Oct 2013 15:47:30 +0800 Subject: [PATCH] Create table method --- main.go | 6 ++++++ orm.go | 4 ++++ orm_test.go | 2 +- sql.go | 11 +++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 53dcc807..f64820b4 100644 --- a/main.go +++ b/main.go @@ -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 +} diff --git a/orm.go b/orm.go index 99439d2e..98c13f1a 100644 --- a/orm.go +++ b/orm.go @@ -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 +} diff --git a/orm_test.go b/orm_test.go index 405ba0eb..350975d9 100644 --- a/orm_test.go +++ b/orm_test.go @@ -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 } diff --git a/sql.go b/sql.go index b729f6c7..fdf5ff1c 100644 --- a/sql.go +++ b/sql.go @@ -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 +}