4 ms·
JetBrains IDEs help with this actually. When I was working with Go, all SQL longer than one or two lines went into the package level sql.go file, each query be
by sk0g 5y ago
JetBrains IDEs help with this actually.
When I was working with Go, all SQL longer than one or two lines went into the package level sql.go file, each query being a multi-line string. If you preface it with a comment like `// language=PostgreSQL`, you get syntax highlighting for PGSQL. What's more, if you have databases configured in your IDE, it tries to cross-reference the tables, columns, etc, and validates the queries for you.
I never did manage to get the latter part working 100%, but I think it's because we used multiple top-level databases, but in the DB setup we had just one connection, that we then switched around to look at things.
- earthboundkid 5y agoWith Go 1.16, you can embed SQL files into your Go app instead of using a multiline literal. I actually am curious if a SQLC competitor should be written using embed + generics once generics drop in 1.18. I haven’t totally worked on what it would look like yet, but it’s an interesting idea.
- Sadzeih 5y agoI think generics will change a lot of the ORM space for go yeah. Will be interesting to see.