我从本地项目(Go 模块)导入包失败。以下是我正在尝试的简要说明:
我创建了一个 Go 模块包,如下所示:
$ cd
$ mkdir mymodule
$ cd mymodule
$ go mod init github.com/Company/mymodule
Run Code Online (Sandbox Code Playgroud)
然后我hello.go在下面添加了mymodule一个小功能
// mymodule/hello.go
package mymodule
func sayHello() string {
return "Hello"
}
Run Code Online (Sandbox Code Playgroud)
go build那是成功的。
请注意,该模块尚未推送到 github 存储库。我想在推送到 github 之前使用(也许测试)mymodule。所以我创建了另一个包,如下所示:
$ cd
$ mkdir test
$ cd test
$ go mod init github.com/Company/test
Run Code Online (Sandbox Code Playgroud)
test.go然后,在目录下创建一个新文件test,并在其中尝试导入mymodule,如下所示:
// test/test.go
import (
"fmt"
"github.com/Company/mymodule"
)
func testMyModule() {
fmt.Println(mymodule.sayHello())
}
Run Code Online (Sandbox Code Playgroud)
但go build失败test并出现以下错误。是什么赋予了? …
请参阅此处的过滤示例:https://sqlmodel.tiangolo.com/tutorial/where/#filter-rows-using-where-with-sqlmodel,如何获取所有年龄为空的英雄。
我需要相当于:
select * from hero where age is null
Run Code Online (Sandbox Code Playgroud)
这有效:
select(Hero).where(Hero.age != None)
Run Code Online (Sandbox Code Playgroud)
但是,IDE 抱怨PEP 8: E711 comparison to None should be 'if cond is not None:'
所以我把它改为:
select(Hero).where(Hero.age is None)
Run Code Online (Sandbox Code Playgroud)
但是,它无法按预期工作,导致生成不正确的 SQL:
SELECT * FROM hero WHERE 0 = 1
Run Code Online (Sandbox Code Playgroud)
什么是正确的做法?