(n *chast.CreateQuery)
| 768 | } |
| 769 | |
| 770 | func (c *cc) convertCreateQuery(n *chast.CreateQuery) ast.Node { |
| 771 | // Handle CREATE DATABASE |
| 772 | if n.CreateDatabase { |
| 773 | return &ast.CreateSchemaStmt{ |
| 774 | Name: &n.Database, |
| 775 | IfNotExists: n.IfNotExists, |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | // Handle CREATE TABLE |
| 780 | if n.Table != "" { |
| 781 | stmt := &ast.CreateTableStmt{ |
| 782 | Name: &ast.TableName{ |
| 783 | Name: identifier(n.Table), |
| 784 | }, |
| 785 | IfNotExists: n.IfNotExists, |
| 786 | } |
| 787 | |
| 788 | if n.Database != "" { |
| 789 | stmt.Name.Schema = identifier(n.Database) |
| 790 | } |
| 791 | |
| 792 | // Convert columns |
| 793 | for _, col := range n.Columns { |
| 794 | colDef := c.convertColumnDeclaration(col) |
| 795 | stmt.Cols = append(stmt.Cols, colDef) |
| 796 | } |
| 797 | |
| 798 | // Convert AS SELECT |
| 799 | if n.AsSelect != nil { |
| 800 | // This is a CREATE TABLE ... AS SELECT |
| 801 | // The AsSelect field contains the SELECT statement |
| 802 | } |
| 803 | |
| 804 | return stmt |
| 805 | } |
| 806 | |
| 807 | // Handle CREATE VIEW |
| 808 | if n.View != "" { |
| 809 | return &ast.ViewStmt{ |
| 810 | View: &ast.RangeVar{ |
| 811 | Relname: &n.View, |
| 812 | }, |
| 813 | Query: c.convert(n.AsSelect), |
| 814 | Replace: n.OrReplace, |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | return &ast.TODO{} |
| 819 | } |
| 820 | |
| 821 | func (c *cc) convertColumnDeclaration(n *chast.ColumnDeclaration) *ast.ColumnDef { |
| 822 | colDef := &ast.ColumnDef{ |
no test coverage detected