package build import ( "fmt" "strings" "git.secnex.io/secnex/pgson/schema" "git.secnex.io/secnex/pgson/utils" ) func CreateSQL(s *schema.Table) (string, error) { schemaParts := make([]string, len(s.Schema)) for i, field := range s.Schema { schemaParts[i] = field.SQL() } 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 }