Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler error is misleading when migrations folder is missing. #930

Open
Willyham opened this issue Oct 30, 2023 · 0 comments
Open

Compiler error is misleading when migrations folder is missing. #930

Willyham opened this issue Oct 30, 2023 · 0 comments

Comments

@Willyham
Copy link
Contributor

Willyham commented Oct 30, 2023

I was refactoring to break out a service, and I moved my store logic into the new service. Encore then fails with this output:

  ❌ Building Encore application graph... Failed: Invalid use of sqldb package-level function
  ⠂ Analyzing service topology...

── Invalid use of sqldb package-level function ────────────────────────────[E1699]──

The package-level query function sqldb.QueryRow can only be used within Encore
services that don't use sqldb.NewDatabase.

    ╭─[ /Users/foo/backend/checks/store.go:33:9 ]
    │
 31 │         return nil, err
 32 │     }
 33 │     row := sqldb.QueryRow(ctx, query, args...)
    ⋮            ──────────────
 34 │     if row.Err() != nil {
 35 │         return nil, row.Err()
────╯

For more information about how to use databases in Encore, see
https://encore.dev/docs/primitives/databases

I spent a while trying to understand the issue around sqldb.NewDatabase. It turns out I didn't create my migrations folder in the new service yet, and then I'm guessing Encore assumes you must be using sqldb.NewDatabase (even though I don't use it anywhere).

So technically correct, but a bit misleading. It would be nice to capture the case where sqldb.QueryX functions are used, there's no sqldb.NewDatabase call and there's no migrations folder, and offer the choice to the user. E.g. "Either create a migrations folder or use a named database".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant