feat: Add delete, drop, insert, truncate, update
This commit is contained in:
@@ -5,13 +5,18 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.secnex.io/secnex/pgson/schema"
|
||||
"git.secnex.io/secnex/pgson/utils"
|
||||
)
|
||||
|
||||
func Create(s *schema.Table) (string, error) {
|
||||
func CreateSQL(s *schema.Table) (string, error) {
|
||||
schemaParts := make([]string, len(s.Schema))
|
||||
for i, field := range s.Schema {
|
||||
schemaParts[i] = field.SQL()
|
||||
}
|
||||
query := fmt.Sprintf("CREATE TABLE %s (%s)", s.Name, strings.Join(schemaParts, ",\n"))
|
||||
|
||||
schemaParts = append(schemaParts, "\"created_at\" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP")
|
||||
schemaParts = append(schemaParts, "\"updated_at\" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP")
|
||||
schemaParts = append(schemaParts, "\"deleted_at\" TIMESTAMP NULL")
|
||||
query := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (%s)", utils.SQLQuoteIdent(s.Name), strings.Join(schemaParts, ", "))
|
||||
return query, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user