Rahul Rawat

    Rahul Rawat

    7 months ago
    I’ve been trying to add sqldelight to my jetpack compose web’s project and it’s giving me the following error
    Module not found: Error: Can't resolve 'fs' in '/Users/rahulrawat/Desktop/Projects/web/Address/build/js/node_modules/sql.js/dist'
    Has anyone faced this and been able to resolve?
    Big Chungus

    Big Chungus

    7 months ago
    You cannot connect to db from the browser environment. It's not compose-web specific limitation. Sqldelight for kotlin js is meant to be used in nodejs server environment.
    hfhbd

    hfhbd

    7 months ago
    Thats not true, you can use sqldelight from the browser, see https://github.com/hfhbd/ComposeTodo/tree/main/web
    But its not a persistent db!
    Big Chungus

    Big Chungus

    7 months ago
    Wait what? How does it connect to db straight from the browser sandbox?
    hfhbd

    hfhbd

    7 months ago
    It is a in memory db. Yes, you dont have direct access to an external db, because there is no JDBC (or similar api), you often can't access it (eg db behind a firewall/internal network) and it is not safe to store the db credentials in JS code.
    Big Chungus

    Big Chungus

    7 months ago
    Can you point me to a line of code where sqldelight is actually used in that project? Couldn't find it myself. Also I'm still at a loss as to how is this better than LocalStorage?
    What am I missing here? 😀
    hfhbd

    hfhbd

    7 months ago
    I use sqldelight as the client db, so it is defined in clients module: https://github.com/hfhbd/ComposeTodo/tree/main/clients This allows you to use the same shared repository in each client, Android and iOS with a persistent db, web with an in memory. LocalStorage is persistent, but you need a new web based implementation.
    Rahul Rawat

    Rahul Rawat

    7 months ago
    @hfhbd What about the issue I am facing?
    Big Chungus

    Big Chungus

    7 months ago
    It's solved in the app he linked
    hfhbd

    hfhbd

    7 months ago
    Gradle:
    implementation("com.squareup.sqldelight:sqljs-driver:1.5.3")
    implementation(devNpm("copy-webpack-plugin", "9.1.0"))
    Webpack:https://github.com/hfhbd/ComposeTodo/tree/main/web/webpack.config.d
    Big Chungus

    Big Chungus

    7 months ago
    Well not solved. More like masked as he's just stubbing fs implementation so anything actually using that module will error when invoked
    Rahul Rawat

    Rahul Rawat

    7 months ago
    So should I also remove my sqljs driver from the multiplatform module? Or should I just include the aforementioned gradle dependencies in the client?
    Big Chungus

    Big Chungus

    7 months ago
    I'd avoid any sql attempts on the browser clients.
    Big Chungus

    Big Chungus

    7 months ago
    But it's not the nodejs fs module that the driver expects. Also its a sandboxed and quite restricted file system.
    hfhbd

    hfhbd

    7 months ago
    True, but it works. The question is, whether you want to implement a low level "db"/repo for your web app or share an (existing) repo for all clients, but use another frameworks/extra db 🤷
    Big Chungus

    Big Chungus

    7 months ago
    Don't get me wrong, I'm impressed how much you CAN do in the browser. All I'm saying is that generally doing sql in the browser is simply not recommended.
    Sqldelight should provide a module for browser kotlin based on IndexedDB somehow. That way you at least avoid having to pull sql wasm module each page load...
    hfhbd

    hfhbd

    7 months ago
    Do you know WebSQL? 😄 Yeah, persistence is a big problem! Sqldelight 2.0 wants to support it by using a wrapper, which persists the sqlite db file into indexedDB... so a db inside a db
    Big Chungus

    Big Chungus

    7 months ago

    https://c.tenor.com/EYPJjOVJOHYAAAAM/inception-deeper.gif

    Wasn't aware of WebSQL spec. Lucky gem!
    hfhbd

    hfhbd

    7 months ago
    It is deprecated -.-