英文:
Syntax highlight SQL queries when using non-standard SQL packages in Goland IDE
问题
在使用Goland时,根据我连接的数据源,获得SQL语法高亮和自动完成非常有用。不幸的是,这似乎只在我使用标准的Go sql包时有效,而在我使用有效地封装了sql包调用的自定义包时无效。我想知道是否有可能告诉Goland特定的函数/参数实际上是SQL查询/SQL语句。
以下是Goland允许对sql.DB结构体方法进行SQL自动完成,而不允许对自定义query.ReadOnlyDB结构体进行自动完成的示例:
英文:
When using Goland it is very useful to get SQL syntax highlight and autocompletion based on my connected datasources. Unfortunately this only seems to work when I'm using the standard Go sql package and does not work when I use custom packages that effectively wrap the sql package calls. I was wondering if it's possible to tell Goland that specific functions / parameters are actually SQL queries / SQL statements.
Here's an example of Goland allowing SQL completion for methods on sql.DB struct vs not allowing completion on custom query.ReadOnlyDB struct:
答案1
得分: 5
目前,您可以在语句之前使用//language=SQL
注释来指定语言为SQL:
package main
import "fmt"
func main() {
//language=SQL
str := "SELECT USERNAME FROM EXAMPLE"
fmt.Println(str)
}
有一些改进GoLand中SQL语法高亮的票可以供您参考:
英文:
Currently, you can specify //language=SQL
comment before the statement:
package main
import "fmt"
func main() {
//language=SQL
str := "SELECT USERNAME FROM EXAMPLE"
fmt.Println(str)
}
There are a few tickets to improve SQL highlighting in GoLand and you can follow them:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论