简体   繁体   English

如何让 Haskell 在编译时检查 SQL?

[英]How do you get Haskell to check SQL at compile time?

I know it can be done, but I'm having trouble getting it working.我知道它可以完成,但我无法让它工作。 I'm still finding my feet with Haskell.我仍在使用 Haskell。

I tried using postgresql-typed, but it wouldn't compile.我尝试使用 postgresql-typed,但它不会编译。 They don't enable the QuasiQuotes extension, so I don't understand how their code would ever compile.他们不启用 QuasiQuotes 扩展,所以我不明白他们的代码将如何编译。 It also fails with an error on the useTPGDatabase statement.它也因useTPGDatabase语句上的错误而失败。 I cloned the library's source code from Github, but their tests failed to compile using stack with exactly the same errors.我从 Github 克隆了库的源代码,但是他们的测试无法使用堆栈进行编译,并且出现完全相同的错误。

I considered using hasql-th, but it's not on stackage.org, which immediately puts it in the "too hard basket.".我考虑过使用 hasql-th,但它不在 stackage.org 上,它立即将其放入“太难的篮子”。 I considered switching to nix but that seems like even more effort.我考虑过改用nix,但这似乎更加努力。

Does somebody have a reliable recipe for getting an environment working that type-checks SQL at compile time in Haskell?有人有可靠的方法来让环境工作,在 Haskell 的编译时对 SQL 进行类型检查吗?

I considered using hasql-th, but it's not on stackage.org, which immediately puts it in the "too hard basket."我考虑过使用 hasql-th,但它不在 stackage.org 上,它立即将它放在“太难的篮子”中。

All you need to do is add the latest version of hasql-th to the extra-deps section of your stack.yaml file and all other deps that Stack will suggest to you when you build.您需要做的就是将最新版本的hasql-th添加到您的stack.yaml文件和 Stack 将在您构建时向您建议的所有其他 deps 部分的extra-deps部分。

In the end your stack.yaml file should look something like this:最后,您的stack.yaml文件应如下所示:

resolver: lts-17.9
extra-deps:
  - hasql-th-0.4.0.8
  - headed-megaparsec-0.1.0.4
  - postgresql-syntax-0.3.0.3

Anticipating a question in the spirit of "Why is it not listed on Stackage?"本着“为什么它没有在 Stackage 上列出?”的精神期待一个问题。 It's just that nobody has gotten to list these packages yet.只是还没有人列出这些包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM