Skip to content

How to build Tauri App with SQLite #5440

Answered by zhanglun
zhanglun asked this question in Q&A
Discussion options

You must be logged in to vote

hey guy, I have solved this problem. here is my solution, hope it can help someone in need 😄

The dotenv crate reads the file dynamically at runtime. So it's reasonable that this does not work in production, as there is not dotenv file. So I declared variable 'DATABASE_URL' in db.rs which value is relative to the tauri context's path.

pub fn establish_connection() -> SqliteConnection {
  let database_url = "./lettura.db";
 
  SqliteConnection::establish(&database_url)
    .expect(&format!("Error connecting to {}", database_url))
}

Then do migrations at compile time, here is the detail

#[macro_use]
extern crate diesel_migrations;

use diesel_migrations::{embed_migrations};
embed_migrations!("…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@zahrulsch
Comment options

Answer selected by zhanglun
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants