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

Writing custom queries #620

Open
hasufell opened this issue Jan 25, 2022 · 2 comments
Open

Writing custom queries #620

hasufell opened this issue Jan 25, 2022 · 2 comments

Comments

@hasufell
Copy link

I read these both pages:

  1. https://hackage.haskell.org/package/beam-core-0.9.2.0/docs/Database-Beam-Query-CustomSQL.html
  2. https://haskell-beam.github.io/beam/user-guide/extensibility/#custom-expressions

And have still no idea how to write a custom query. I followed the first page, which points to the non-existent page https://haskell-beam.github.io/beam/user-guide/extensibility/extensibility. Then I followed the second page and I end up getting errors:

    • No instance for (IsCustomSqlSyntax
                         (Database.Beam.Backend.SQL.SQL92.Sql92SelectTableExpressionSyntax
                            (Database.Beam.Backend.SQL.SQL92.Sql92SelectSelectTableSyntax
                               (Database.Beam.Backend.SQL.SQL92.Sql92SelectSyntax
                                  (Database.Beam.Backend.SQL.BeamSqlBackendSyntax ctxt)))))
        arising from a use of ‘customExpr_’
    • In the expression: customExpr_ myFuncImpl
      In an equation for ‘instr_’:
          instr_
            = customExpr_ myFuncImpl
            where
                myFuncImpl :: (Monoid a, IsString a) => a -> a -> a
                myFuncImpl str needle = "instr(" <> str <> ", " <> needle <> ")"

The page says:

Your backend's syntax must implement the IsSqlCustomExpressionSyntax type class.

I don't know what that means. How to implement this? Where's an example?

@kmicklas
Copy link
Member

The instance it's complaining about is just the constraint you need to add to the declaration of instr_. It's implemented by the backend (Postgres or SQLite).

The Haddocks definitely don't make this clear enough, and we should probably have an example of this in the markdown docs too.

@kmicklas
Copy link
Member

Actually it turns out we do have an example in the docs, but it's in the context of a query with a concrete backend, so we don't demonstrate the necessary context for defining a custom combinator.

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

No branches or pull requests

2 participants