0

I am trying to follow the examples in sqlboiler (https://github.com/volatiletech/sqlboiler). But, I can't find a way to get the table name used in the Inner join query.

users, err := models.Users(
  Select("id", "name"),
  InnerJoin("credit_cards c on c.user_id = users.id"),
  Where("age > ?", 30),
  AndIn("c.kind in ?", "visa", "mastercard"),
  Or("email like ?", `%aol.com%`),
  GroupBy("id", "name"),
  Having("count(c.id) > ?", 2),
  Limit(5),
  Offset(6),
).All(ctx, db)

In this example, if, instead of hard-coding the name (credit_cards), I could provide the table name, it'd be great.

Thanks!

Matt Mc
  • 8,882
  • 6
  • 53
  • 89
Coder
  • 1,415
  • 2
  • 23
  • 49
  • Not familiar with sqlboiler, but I know that most ORMs do not really have support for variable column or table names. However you can use string interpolation (`fmt.Sprintf`), but make sure that you are very careful about checking for valid values since this can lead to SQL injection vulnerabilities. (You can sanitize by checking that the given value is one of a select few). – Henry Woody Jun 09 '19 at 02:28

1 Answers1

2

The table names are in the TableNames struct, which is in the file boil_table_names.go

So, I think it would be something like this models.TableNames.CreditCards