我正在尝试从 rusqlite 转换到 sqlx。
通过 rusqlite 打开连接会调用 SQLite::open 并创建数据库文件。以下代码可以正常运行:
use rusqlite::Connection;
Connection::open(db_filename)
然而,我正在遵循sqlx文档上的步骤(https://github.com/launchbadge/sqlx#connecting),并且它们立即引导我创建一个池:
use sqlx::sqlite::{SqlitePoolOptions};
SqlitePoolOptions::new()
.max_connections(1)
.connect(&format!("sqlite://{}", db_filename))
.await
.map_err(|err| format!("{}\nfile: {}", err.to_string(), db_filename))?;
实际上返回了Result<_, String>
的信息:
Error: "error returned from database: unable to open database file\nfile: /path/to/my.db"
我不清楚在 sqlx
中如何在第一次启动时编写那些数据库文件。
有什么建议吗?