Skip to content

feat: implement CHECK constraints#148

Merged
RichardKnop merged 1 commit intomainfrom
feat/implement-check-constraint
May 3, 2026
Merged

feat: implement CHECK constraints#148
RichardKnop merged 1 commit intomainfrom
feat/implement-check-constraint

Conversation

@RichardKnop
Copy link
Copy Markdown
Owner

CHECK constraints are fully implemented. Here's what was added:

Parser (internal/parser/):

  • New step stepCreateTableColumnCheck inserted after stepCreateTableColumnDefaultValue in the CREATE TABLE state machine
  • "CHECK" added to reservedWords
  • stepCreateTableColumnUnique when UNIQUE is found now also flows through stepCreateTableColumnDefaultValue (allowing DEFAULT+CHECK after UNIQUE)
  • Raw expression text captured via p.sql[startPos:p.i] — stored as col.Check; parsed tree stored as col.CheckCond

Data model (internal/minisql/stmt.go):

  • Column gains Check string and CheckCond *ConditionNode
  • createTableDDL() emits check (expr) so constraints survive WAL/schema round-trips

Validation (internal/minisql/check.go):

  • validateCheckConstraints() iterates columns, calls row.CheckOneOrMore(col.CheckCond.ToDNF())
  • ErrCheckConstraintViolation{ColumnName, Expr} returned on first failure
  • Called from insert.go after row assembly and cursor.update() after updates are applied

@RichardKnop RichardKnop self-assigned this May 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Code Coverage

Total: 70.3% (threshold: 70%)

Package Coverage
github.com/RichardKnop/minisql 22.2%
github.com/RichardKnop/minisql/e2e_tests [no
github.com/RichardKnop/minisql/internal/minisql 70.8%
github.com/RichardKnop/minisql/internal/parser 84.8%
github.com/RichardKnop/minisql/pkg/bitwise 100.0%
github.com/RichardKnop/minisql/pkg/lrucache 81.7%

@RichardKnop RichardKnop merged commit d7a42e3 into main May 3, 2026
5 checks passed
@RichardKnop RichardKnop deleted the feat/implement-check-constraint branch May 3, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant