volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Table named "packages" #292

Closed elldritch closed 6 years ago

elldritch commented 6 years ago

I have a table named "packages". Foreseeably, generating code for this table causes problems:

$ sqlboiler postgres --wipe
Error: unable to generate test output: failed to format template

  25 func testPackagesDelete(t *testing.T) {
  26    t.Parallel()
  27 
  28    seed := randomize.NewSeed()
  29    var err error
>>>>    package := &Package{}
  31    if err = randomize.Struct(seed, package, packageDBTypes, true, packageColumnsWithDefault...); err != nil {
  32        t.Errorf("Unable to randomize Package struct: %s", err)
  33    }
  34 
  35    tx := MustTx(boil.Begin())

: 30:2: expected statement, found 'package' (and 10 more errors)

For external reasons, I can't rename the table. I've been using no-tests to get around this, but is there any way to generate tests as well?

From an interface perspective, this seems feasible: all Go keywords are lowercased, so exported identifiers will never conflict with keywords. One way to get around this is to ensure that keywords are never used as locally scoped identifiers e.g. by using row := &Package{} instead of package := Package{}.

aarondl commented 6 years ago

Yep, not a big deal. Could fix this at any time. If nothing else it'll be fixed for v3. I'll tag it appropriately to make sure it's not missed. All the effort is there currently.

The actual code doesn't use the name of the table, so I'm not sure why the tests do. In the actual code most things are just called "o" (for similar reasons).

aarondl commented 6 years ago

This is solved in v3 code. For now you'll have to avoid the generated tests but sqlboiler should still work fine. And once you move to the new code after it's released then your tests should stop failing in this way. :)