| 125 | } |
| 126 | |
| 127 | func NewTable(db *sql.DB, schema, tableName string) (*Table, error) { |
| 128 | table := &Table{ |
| 129 | Schema: url.QueryEscape(schema), |
| 130 | Name: url.QueryEscape(tableName), |
| 131 | conn: db, |
| 132 | } |
| 133 | |
| 134 | var err error |
| 135 | table.Indexes, err = getIndexes(db, table.Schema, table.Name) |
| 136 | if err != nil { |
| 137 | return nil, err |
| 138 | } |
| 139 | table.Constraints, err = getConstraints(db, table.Schema, table.Name) |
| 140 | if err != nil { |
| 141 | return nil, err |
| 142 | } |
| 143 | table.Triggers, err = getTriggers(db, table.Schema, table.Name) |
| 144 | if err != nil { |
| 145 | return nil, err |
| 146 | } |
| 147 | |
| 148 | err = table.parse() |
| 149 | if err != nil { |
| 150 | return nil, err |
| 151 | } |
| 152 | table.conn = nil // to save memory since it is not going to be used again |
| 153 | return table, nil |
| 154 | } |
| 155 | |
| 156 | func (t *Table) parse() error { |
| 157 | // +--------------------------- field type |