在Goland IDE中使用非标准SQL包时,对SQL查询进行语法高亮显示。

huangapple go评论75阅读模式
英文:

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结构体进行自动完成的示例:

在Goland IDE中使用非标准SQL包时,对SQL查询进行语法高亮显示。

英文:

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:

在Goland IDE中使用非标准SQL包时,对SQL查询进行语法高亮显示。

答案1

得分: 5

目前,您可以在语句之前使用//language=SQL注释来指定语言为SQL:

package main

import "fmt"

func main() {
	//language=SQL
	str := "SELECT USERNAME FROM EXAMPLE"
	fmt.Println(str)
}

有一些改进GoLand中SQL语法高亮的票可以供您参考:

  • GO-10398:自定义包/代理的SQL语法高亮。
  • GO-10011:自动将以SQL查询(SELECT、CREATE、DELETE等)开头的字符串注入为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:

  • GO-10398. SQL highlighting for custom packages/proxies.
  • GO-10011. Inject SQL automatically to strings that start with SQL queries (SELECT, CREATE, DELETE, and so on).

huangapple
  • 本文由 发表于 2021年7月21日 17:18:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/68466986.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定