constraints.go 552 B

12345678910111213141516171819202122
  1. package storage
  2. import "fmt"
  3. // NotNullViolationError identifies the final row that violates a required column.
  4. type NotNullViolationError struct {
  5. Table string
  6. Column string
  7. }
  8. func (e *NotNullViolationError) Error() string {
  9. return fmt.Sprintf("NOT NULL constraint failed: %s.%s", e.Table, e.Column)
  10. }
  11. func validateNotNull(schema *Schema, row Row) error {
  12. for _, column := range schema.Columns {
  13. if !column.Nullable && row[column.Name] == nil {
  14. return &NotNullViolationError{Table: schema.Name, Column: column.Name}
  15. }
  16. }
  17. return nil
  18. }