最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rust - Tauri Application Support folder not initalizing properly - Stack Overflow

programmeradmin2浏览0评论

When I start the app a migration runs and I don't see any errors from that, however when I try to read from the database I get this error:

Unhandled Promise Rejection: error returned from database: (code: 1) no such table: sys.tables

I assumed this was an issue with the SQL plugin or my migrations, but based I'm now thinking that my application is not initializing it's Application Support folder correctly.

In ~/Library/Application Support/ there is a new file that gets created when I run the app com.myproject however, unlike almost everything in Application Support it's not a folder, just a single file (roughly 111kb). If I try to open it there is an error that says "You can’t open the application “com.myproject” because it may be damaged or incomplete." Shouldn't this be a folder I can jump into?

Here is my migration code:

lib.rs

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    let migrations = vec![Migration {
        version: 1,
        description: "create connections table",
        sql: "CREATE TABLE IF NOT EXISTS connections (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                name STRING,
                info STRING,
                remember BOOLEAN
            )",
        kind: MigrationKind::Up,
    }];

    let db_url = "sqlite:dbexplorer.db";
    tauri::Builder::default()
        .plugin(
            tauri_plugin_sql::Builder::default()
                .add_migrations(db_url, migrations)
                .build(),
        )
        .plugin(tauri_plugin_shell::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}


In the frontend I have this:

 async function createConnection() {
    const dataDir = await appDataDir()
    console.log('Database should be in:', dataDir)

    const dbPath = await join(dataDir, 'com.dbexplorer.db')
    console.log('EXPECTED PATH:', dbPath)

    const db = await Database.load('sqlite:dbexplorer')
    console.log(db)

    const res = await db.execute('SELECT * from sys.tables')

    console.log(res, 'RES')
  }

  createConnection()

Those logs show an expected DB location of: Database should be in:"~/Library/Application Support/com.myproject.app" With the DB file here: EXPECTED PATH: – "~/Library/Application Support/com.myproject.app/com.myproject.db

Is the problem that com.myproject is not a proper folder that my computer can read? If so how can I fix this when running the project?

When I start the app a migration runs and I don't see any errors from that, however when I try to read from the database I get this error:

Unhandled Promise Rejection: error returned from database: (code: 1) no such table: sys.tables

I assumed this was an issue with the SQL plugin or my migrations, but based I'm now thinking that my application is not initializing it's Application Support folder correctly.

In ~/Library/Application Support/ there is a new file that gets created when I run the app com.myproject however, unlike almost everything in Application Support it's not a folder, just a single file (roughly 111kb). If I try to open it there is an error that says "You can’t open the application “com.myproject” because it may be damaged or incomplete." Shouldn't this be a folder I can jump into?

Here is my migration code:

lib.rs

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    let migrations = vec![Migration {
        version: 1,
        description: "create connections table",
        sql: "CREATE TABLE IF NOT EXISTS connections (
                id INTEGER PRIMARY KEY AUTOINCREMENT,
                name STRING,
                info STRING,
                remember BOOLEAN
            )",
        kind: MigrationKind::Up,
    }];

    let db_url = "sqlite:dbexplorer.db";
    tauri::Builder::default()
        .plugin(
            tauri_plugin_sql::Builder::default()
                .add_migrations(db_url, migrations)
                .build(),
        )
        .plugin(tauri_plugin_shell::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}


In the frontend I have this:

 async function createConnection() {
    const dataDir = await appDataDir()
    console.log('Database should be in:', dataDir)

    const dbPath = await join(dataDir, 'com.dbexplorer.db')
    console.log('EXPECTED PATH:', dbPath)

    const db = await Database.load('sqlite:dbexplorer')
    console.log(db)

    const res = await db.execute('SELECT * from sys.tables')

    console.log(res, 'RES')
  }

  createConnection()

Those logs show an expected DB location of: Database should be in:"~/Library/Application Support/com.myproject.app" With the DB file here: EXPECTED PATH: – "~/Library/Application Support/com.myproject.app/com.myproject.db

Is the problem that com.myproject is not a proper folder that my computer can read? If so how can I fix this when running the project?

Share Improve this question asked Jan 20 at 11:57 tfantinatfantina 80413 silver badges39 bronze badges 1
  • Have you tried checking if the data directory exists, and creating it if not, before trying to initialise the database? – watsom27 Commented Jan 20 at 21:44
Add a comment  | 

1 Answer 1

Reset to default 0

The problem was the identifier in tauri.conf.json.

It was com.myproject.app which Mac was treating as an executable. I changed it:

"identifier": "com.myproject",

发布评论

评论列表(0)

  1. 暂无评论