连接 lapis 到 postgresql 数据库

我决定试着使用 lapis - https://github.com/leafo/lapis, 但是当我尝试查询数据库 (PostgreSQL) 时应用程序会崩溃,错误信息如下:

2017/07/01 16:04:26 [error] 31284#0: *8 lua entry thread aborted: runtime error: attempt to yield across C-call boundary stack traceback: coroutine 0: [C]: in function 'require' /usr/local/share/lua/5.1/lapis/init.lua:15: in function 'serve' content_by_lua(nginx.conf.compiled:22):2: in function , client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"

导致错误的代码如下:

local db = require("lapis.db")
local res = db.query("SELECT * FROM users");

config.lua:

config({ "development", "production" }, {
    postgres = {
        host = "0.0.0.0",
        port = "5432",
        user = "wars_base",
        password = "12345",
        database = "wars_base"
    }
})

数据库已在运行,表已被创建,表 1 中有一条记录。

可能的问题是什么?

决定: https://github.com/leafo/lapis/issues/556

点赞
用户448327
用户448327

你需要在 host 参数中指定正确的服务器 IP

你指定的 IP 0.0.0.0 不是有效的 IP 地址,通常它被用于指定监听地址,其意义是“所有地址”。

通常在开发过程中,你可以使用 127.0.0.1 地址。

2017-07-04 10:38:27