0

I'm building a desktop application using tauri, and I want to store data locally at the client using SurrealDB. I either want to store data on a specified path, or store the data in a similar way as IndexedDB stores data on the browser itself.

I would like to use the Javascript library that SurrealDB supplies, but there is no documentation regarding embedding, and instead it refers to the Javascript SDK.

I have never used databases like these before, therefore i currently lack knowledge regarding what is possible and how things are done regarding databases, but i am hoping to be able to read the database almost like a dead csv file (as there will only be one reader, the client), but with the query-language power of SurrealDB.

This is my current code, where i have issues in creating my database:

import Surreal from "surrealdb.js";

export const getSurrealClient = async () => {
    // I will figure out a better path for deployment. Or
    // the IndexedDB storing method will be used?
    const db = new Surreal('file//:C:/Programmering');

    await db.signin({
        user: 'root',
        pass: 'root'
    });

    await db.use({ns: 'namespace', db: 'mydb'});

    return db
}

I get the following error message from the const db = new Surreal(...) action:

Uncaught InvalidURLProvided: The provided string is either not a URL or is a URL but with an invalid protocol!

All in all, my general question is: How do i embed the database inside my tauri project and use the SurrealDB javascript library as the bridge between my project and database?

Ólavur Nón
  • 161
  • 1
  • 13
  • SurrealDB javascript adaptor won't work with file paths, to begin with. Also, I think there's a typo in your path: "file:///C:/blah" so the first colon goes before the slashes. – Jeremy Aug 22 '23 at 18:33

1 Answers1

1

You are trying to access the file system from the browser and that is not possible you can use the Rust client instead

  • To clarify - Tauri is split into a front-end and back-end just like a web-app, except they both run locally and the back-end part is in Rust. The front end only does the UI, while the back-end does everything else. The integrated Javascript you're referring to in SurrealDB isn't for integrating SurrealDB. Instead it's for integrating Javascript code inside your queries. To use SurrealDB with Tauri, you either have to embed it in Rust (not javascript) or run it as a separate process standalone and connect to it from Javascript or Rust. – Jeremy Aug 22 '23 at 18:30