Skip to content

Commit 45c18f1

Browse files
kyleconroyclaude
andcommitted
Add graph edge CONNECTION constraint parsing with ON DELETE CASCADE
Support for parsing CONNECTION constraints in graph edge tables: - Named constraints: CONSTRAINT name CONNECTION (N1 TO N2) - Unnamed constraints: CONNECTION (N1 TO N2) - ON DELETE CASCADE clause for both named and unnamed - ALTER TABLE ADD CONSTRAINT CONNECTION with ON DELETE CASCADE Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0354255 commit 45c18f1

4 files changed

Lines changed: 86 additions & 2 deletions

File tree

parser/marshal.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5410,6 +5410,59 @@ func (p *Parser) parseCreateTableStatement() (*ast.CreateTableStatement, error)
54105410
return stmt, nil
54115411
}
54125412
stmt.Definition.Indexes = append(stmt.Definition.Indexes, indexDef)
5413+
} else if upperLit == "CONNECTION" {
5414+
// Parse unnamed CONNECTION constraint for graph edge tables
5415+
p.nextToken() // consume CONNECTION
5416+
constraint := &ast.GraphConnectionConstraintDefinition{}
5417+
if p.curTok.Type == TokenLParen {
5418+
p.nextToken() // consume (
5419+
for p.curTok.Type != TokenRParen && p.curTok.Type != TokenEOF {
5420+
conn := &ast.GraphConnectionBetweenNodes{}
5421+
// Parse FromNode
5422+
fromNode, err := p.parseSchemaObjectName()
5423+
if err != nil {
5424+
p.skipToEndOfStatement()
5425+
return stmt, nil
5426+
}
5427+
conn.FromNode = fromNode
5428+
// Expect TO
5429+
if strings.ToUpper(p.curTok.Literal) == "TO" {
5430+
p.nextToken() // consume TO
5431+
}
5432+
// Parse ToNode
5433+
toNode, err := p.parseSchemaObjectName()
5434+
if err != nil {
5435+
p.skipToEndOfStatement()
5436+
return stmt, nil
5437+
}
5438+
conn.ToNode = toNode
5439+
constraint.FromNodeToNodeList = append(constraint.FromNodeToNodeList, conn)
5440+
if p.curTok.Type == TokenComma {
5441+
p.nextToken()
5442+
} else {
5443+
break
5444+
}
5445+
}
5446+
if p.curTok.Type == TokenRParen {
5447+
p.nextToken() // consume )
5448+
}
5449+
}
5450+
// Check for ON DELETE CASCADE
5451+
if p.curTok.Type == TokenOn && strings.ToUpper(p.peekTok.Literal) == "DELETE" {
5452+
p.nextToken() // consume ON
5453+
p.nextToken() // consume DELETE
5454+
if strings.ToUpper(p.curTok.Literal) == "CASCADE" {
5455+
constraint.DeleteAction = "Cascade"
5456+
p.nextToken() // consume CASCADE
5457+
} else if strings.ToUpper(p.curTok.Literal) == "NO" {
5458+
p.nextToken() // consume NO
5459+
if strings.ToUpper(p.curTok.Literal) == "ACTION" {
5460+
constraint.DeleteAction = "NoAction"
5461+
p.nextToken() // consume ACTION
5462+
}
5463+
}
5464+
}
5465+
stmt.Definition.TableConstraints = append(stmt.Definition.TableConstraints, constraint)
54135466
} else {
54145467
// Parse column definition
54155468
colDef, err := p.parseColumnDefinition()
@@ -8168,6 +8221,22 @@ func (p *Parser) parseConnectionConstraint() (*ast.GraphConnectionConstraintDefi
81688221
}
81698222
}
81708223

8224+
// Check for ON DELETE CASCADE
8225+
if p.curTok.Type == TokenOn && strings.ToUpper(p.peekTok.Literal) == "DELETE" {
8226+
p.nextToken() // consume ON
8227+
p.nextToken() // consume DELETE
8228+
if strings.ToUpper(p.curTok.Literal) == "CASCADE" {
8229+
constraint.DeleteAction = "Cascade"
8230+
p.nextToken() // consume CASCADE
8231+
} else if strings.ToUpper(p.curTok.Literal) == "NO" {
8232+
p.nextToken() // consume NO
8233+
if strings.ToUpper(p.curTok.Literal) == "ACTION" {
8234+
constraint.DeleteAction = "NoAction"
8235+
p.nextToken() // consume ACTION
8236+
}
8237+
}
8238+
}
8239+
81718240
return constraint, nil
81728241
}
81738242

parser/parse_ddl.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6384,6 +6384,21 @@ func (p *Parser) parseAlterTableAddStatement(tableName *ast.SchemaObjectName) (*
63846384
p.nextToken() // consume )
63856385
}
63866386
}
6387+
// Check for ON DELETE CASCADE
6388+
if p.curTok.Type == TokenOn && strings.ToUpper(p.peekTok.Literal) == "DELETE" {
6389+
p.nextToken() // consume ON
6390+
p.nextToken() // consume DELETE
6391+
if strings.ToUpper(p.curTok.Literal) == "CASCADE" {
6392+
constraint.DeleteAction = "Cascade"
6393+
p.nextToken() // consume CASCADE
6394+
} else if strings.ToUpper(p.curTok.Literal) == "NO" {
6395+
p.nextToken() // consume NO
6396+
if strings.ToUpper(p.curTok.Literal) == "ACTION" {
6397+
constraint.DeleteAction = "NoAction"
6398+
p.nextToken() // consume ACTION
6399+
}
6400+
}
6401+
}
63876402
stmt.Definition.TableConstraints = append(stmt.Definition.TableConstraints, constraint)
63886403

63896404
case "DEFAULT":
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)