parseCreateIndex parses CREATE [UNIQUE] INDEX statement
(unique bool)
| 24 | |
| 25 | // parseCreateIndex parses CREATE [UNIQUE] INDEX statement |
| 26 | func (p *Parser) parseCreateIndex(unique bool) (*ast.CreateIndexStatement, error) { |
| 27 | stmt := &ast.CreateIndexStatement{ |
| 28 | Unique: unique, |
| 29 | } |
| 30 | |
| 31 | // Check for IF NOT EXISTS |
| 32 | if p.isType(models.TokenTypeIf) { |
| 33 | p.advance() // Consume IF |
| 34 | if !p.isType(models.TokenTypeNot) { |
| 35 | return nil, p.expectedError("NOT after IF") |
| 36 | } |
| 37 | p.advance() // Consume NOT |
| 38 | if !p.isType(models.TokenTypeExists) { |
| 39 | return nil, p.expectedError("EXISTS after NOT") |
| 40 | } |
| 41 | p.advance() // Consume EXISTS |
| 42 | stmt.IfNotExists = true |
| 43 | } |
| 44 | |
| 45 | // Parse index name (supports schema.index qualification and double-quoted identifiers) |
| 46 | indexName, err := p.parseQualifiedName() |
| 47 | if err != nil { |
| 48 | return nil, p.expectedError("index name") |
| 49 | } |
| 50 | stmt.Name = indexName |
| 51 | |
| 52 | // Expect ON |
| 53 | if !p.isType(models.TokenTypeOn) { |
| 54 | return nil, p.expectedError("ON") |
| 55 | } |
| 56 | p.advance() // Consume ON |
| 57 | |
| 58 | // Parse table name (supports schema.table qualification and double-quoted identifiers) |
| 59 | indexTableName, err := p.parseQualifiedName() |
| 60 | if err != nil { |
| 61 | return nil, p.expectedError("table name") |
| 62 | } |
| 63 | stmt.Table = indexTableName |
| 64 | |
| 65 | // Parse optional USING |
| 66 | if p.isType(models.TokenTypeUsing) { |
| 67 | p.advance() // Consume USING |
| 68 | if !p.isIdentifier() { |
| 69 | return nil, p.expectedError("index method") |
| 70 | } |
| 71 | stmt.Using = p.currentToken.Token.Value |
| 72 | p.advance() |
| 73 | } |
| 74 | |
| 75 | // Expect opening parenthesis |
| 76 | if !p.isType(models.TokenTypeLParen) { |
| 77 | return nil, p.expectedError("(") |
| 78 | } |
| 79 | p.advance() // Consume ( |
| 80 | |
| 81 | // Parse column list |
| 82 | for { |
| 83 | col := ast.IndexColumn{} |
no test coverage detected