feat: Add delete, drop, insert, truncate, update

This commit is contained in:
Björn Benouarets
2025-11-06 00:54:41 +01:00
parent e884c77c31
commit cd757c80f5
17 changed files with 600 additions and 31 deletions

View File

@@ -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
}