Table specify the table you would like to run db operations // Get a user db.Table("users").Take(&result)
(name string, args ...interface{})
| 62 | // // Get a user |
| 63 | // db.Table("users").Take(&result) |
| 64 | func (db *DB) Table(name string, args ...interface{}) (tx *DB) { |
| 65 | tx = db.getInstance() |
| 66 | if strings.Contains(name, " ") || strings.Contains(name, "`") || len(args) > 0 { |
| 67 | tx.Statement.TableExpr = &clause.Expr{SQL: name, Vars: args} |
| 68 | if results := tableRegexp.FindStringSubmatch(name); len(results) == 3 { |
| 69 | if results[1] != "" { |
| 70 | tx.Statement.Table = results[1] |
| 71 | } else { |
| 72 | tx.Statement.Table = results[2] |
| 73 | } |
| 74 | } |
| 75 | } else if tables := strings.Split(name, "."); len(tables) == 2 { |
| 76 | tx.Statement.TableExpr = &clause.Expr{SQL: tx.Statement.Quote(name)} |
| 77 | tx.Statement.Table = tables[1] |
| 78 | } else if name != "" { |
| 79 | tx.Statement.TableExpr = &clause.Expr{SQL: tx.Statement.Quote(name)} |
| 80 | tx.Statement.Table = name |
| 81 | } else { |
| 82 | tx.Statement.TableExpr = nil |
| 83 | tx.Statement.Table = "" |
| 84 | } |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | // Distinct specify distinct fields that you want querying |
| 89 | // |
nothing calls this directly
no test coverage detected