MCPcopy
hub / github.com/go-gorm/gorm / Table

Method Table

chainable_api.go:64–86  ·  view source on GitHub ↗

Table specify the table you would like to run db operations // Get a user db.Table("users").Take(&result)

(name string, args ...interface{})

Source from the content-addressed store, hash-verified

62// // Get a user
63// db.Table("users").Take(&result)
64func (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//

Callers

nothing calls this directly

Calls 3

getInstanceMethod · 0.95
ContainsMethod · 0.80
QuoteMethod · 0.80

Tested by

no test coverage detected