Skip to content

Commit a4993d7

Browse files
committed
feat(sqlite): add SQLite database support with configurable path and module compilation
1 parent 5c9e949 commit a4993d7

7 files changed

Lines changed: 558 additions & 9 deletions

File tree

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,9 @@ logs
8787
test-results
8888
.routa
8989
apps/desktop/src-tauri/icons/*
90-
.next-desktop
90+
.next-desktop/
91+
92+
# SQLite database files
93+
*.db
94+
*.db-journal
95+
*.db-wal

apps/desktop/src-tauri/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,36 @@ fn start_embedded_next_server(
145145
));
146146
}
147147

148+
// Determine a writable path for the SQLite database.
149+
// Prefer ROUTA_DB_PATH env, otherwise use <app_data_dir>/routa.db.
150+
let db_path = std::env::var("ROUTA_DB_PATH").unwrap_or_else(|_| {
151+
let data_dir = app
152+
.path()
153+
.app_data_dir()
154+
.unwrap_or_else(|_| dirs::home_dir().unwrap_or_default().join(".routa"));
155+
std::fs::create_dir_all(&data_dir).ok();
156+
data_dir
157+
.join("routa.db")
158+
.to_string_lossy()
159+
.to_string()
160+
});
161+
148162
let node_bin = env_or_default("ROUTA_NODE_BIN", "node");
149163
println!(
150164
"[desktop-server] Starting embedded server: {} {}",
151165
node_bin,
152166
server_js.to_string_lossy()
153167
);
168+
println!("[desktop-server] Database path: {}", db_path);
154169

155170
let mut child = Command::new(node_bin)
156171
.arg("server.js")
157-
.current_dir(server_root)
172+
.current_dir(&server_root)
158173
.env("HOSTNAME", host)
159174
.env("PORT", port.to_string())
160175
.env("ROUTA_DESKTOP_SERVER_BUILD", "1")
176+
.env("ROUTA_DB_DRIVER", "sqlite")
177+
.env("ROUTA_DB_PATH", &db_path)
161178
.stdout(Stdio::piped())
162179
.stderr(Stdio::piped())
163180
.spawn()

next.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ const nextConfig: NextConfig = {
1717
"better-sqlite3",
1818
],
1919
...(isDesktopServerBuild ? { distDir: ".next-desktop" } : {}),
20-
...(isDesktopStandaloneBuild ? { output: "standalone" } : {}),
20+
...(isDesktopStandaloneBuild
21+
? {
22+
output: "standalone",
23+
outputFileTracingIncludes: {
24+
"/*": ["./node_modules/better-sqlite3/**/*"],
25+
},
26+
}
27+
: {}),
2128
...(isStaticBuild
2229
? {
2330
output: "export",

0 commit comments

Comments
 (0)