feat: Add delete, drop, insert, truncate, update
This commit is contained in:
@@ -1,9 +1,51 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
)
|
||||
|
||||
var (
|
||||
requiredAttributes = [2]string{"name", "type"}
|
||||
onlySupportedTypes = []string{"string", "int", "float", "bool", "date", "time", "datetime", "uuid", "json", "hash"}
|
||||
)
|
||||
|
||||
func (t *Table) Validate() error {
|
||||
func ValidateField(field *Field) error {
|
||||
if err := ValidateHashAlgorithm(field); err != nil {
|
||||
return err
|
||||
}
|
||||
return ValidateFieldType(field)
|
||||
}
|
||||
|
||||
func ValidateFieldType(field *Field) error {
|
||||
if !slices.Contains(onlySupportedTypes, field.Type) {
|
||||
return fmt.Errorf("unsupported type: %s", field.Type)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateHashAlgorithm(field *Field) error {
|
||||
if field.Type != "hash" {
|
||||
return nil
|
||||
}
|
||||
if field.Algorithm == nil {
|
||||
return fmt.Errorf("algorithm is required for hash field")
|
||||
}
|
||||
var hashAlgorithms = []string{"argon2", "bcrypt", "md5", "sha256", "sha512"}
|
||||
for _, algorithm := range hashAlgorithms {
|
||||
if *field.Algorithm == algorithm {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("unsupported hash algorithm: %s", *field.Algorithm)
|
||||
}
|
||||
|
||||
func (t *Table) Validate() error {
|
||||
for _, field := range t.Schema {
|
||||
err := ValidateField(&field)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user