Commit a1fd7bf5 authored by Faizal Aziz's avatar Faizal Aziz

change executor

parent 9a197e7c
...@@ -177,7 +177,7 @@ func (d *postgresqldb) Create(args interface{}) error { ...@@ -177,7 +177,7 @@ func (d *postgresqldb) Create(args interface{}) error {
} }
func (d *postgresqldb) CreateTable(tableName string, structs interface{}) error { func (d *postgresqldb) CreateTable(tableName string, structs interface{}) error {
return d.db.Create(generateSQLFromStorage(tableName, structs)).Error return d.db.Exec(generateSQLFromStorage(tableName, structs)).Error
} }
func (d *postgresqldb) Update(args interface{}) error { func (d *postgresqldb) Update(args interface{}) error {
...@@ -331,6 +331,19 @@ func generateSQLFromStorage(tableName string, columnAndValues interface{}) strin ...@@ -331,6 +331,19 @@ func generateSQLFromStorage(tableName string, columnAndValues interface{}) strin
if typeName == "" { if typeName == "" {
typeName = "text" typeName = "text"
} }
sqlDefault := field.Tag.Get("sql-default")
if sqlDefault != "" {
def := "default " + sqlDefault
sqlDefault = def
}
nullable := field.Tag.Get("sql-nullable")
if nullable == "true" {
nullable = "not null"
} else {
nullable = ""
}
argName := field.Tag.Get("sql-constraint") argName := field.Tag.Get("sql-constraint")
keysName := field.Tag.Get("sql-keys") keysName := field.Tag.Get("sql-keys")
...@@ -347,10 +360,10 @@ func generateSQLFromStorage(tableName string, columnAndValues interface{}) strin ...@@ -347,10 +360,10 @@ func generateSQLFromStorage(tableName string, columnAndValues interface{}) strin
} }
} }
columnNames += fmt.Sprintf("%s %s %s %s ,", columnName, typeName, argName, keysName) columnNames += fmt.Sprintf("%s %s %s %s %s %s ,", columnName, typeName, sqlDefault, nullable, argName, keysName)
} }
columnNamesStr := strings.TrimRight(columnNames, ",") columnNamesStr := strings.Replace(strings.TrimRight(columnNames, ","), "DROP DATABASE", "", 1)
return fmt.Sprintf("CREATE TABLE %s '(%s)'", tableName, columnNamesStr) return fmt.Sprintf("'CREATE TABLE IF NOT EXISTS %s (%s)'", tableName, columnNamesStr)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment