sql.js icon indicating copy to clipboard operation
sql.js copied to clipboard

Usage with Reactjs

Open sebqq opened this issue 7 years ago • 6 comments

Hello i would like to ask you If I'm able to use this lib with react. I downloaded sql.jq file and I'm trying to import it like import {SQL} from "./sql";

but when i start development server i get into some infinite loop. I'm also not able to found some debug logs for what is happening here. The console is stucked on Compiling... message

I also tried to import it using require keyword like const SQL = require('./sql') but it didn't work either.

Many thanks for any help!

sebqq avatar Nov 29 '18 09:11 sebqq

I was able to get SQL object by injecting index.html file in public folder:

...
    <title>React App</title>
</head>
<body>
    <script src='js/sql.js'></script>
    <div id="root"></div>
...

So now I'm able to get SQL object by window.SQL. Anyway I really would like to be able to import it from my .js files, where database should be opened... Any suggestions?

sebqq avatar Nov 29 '18 09:11 sebqq

Did you tried to get it from npm using the code from readme?

jcubic avatar Jan 31 '19 21:01 jcubic

Similar problem, I have installed sql.js through yarn and started setting up a basic api. The problem is importing the api functions to use in react, where it says compiling.. until i get: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory Any idea how to incorporate sql.js with react? Or the suggested approach?

simonsankar avatar Mar 08 '19 14:03 simonsankar

@simonsankar: Your problem is caused by node running out of memory. You can avoid that by passing --max_old_space_size to node. I do that by setting an environment variable:

export NODE_OPTIONS=--max_old_space_size=4096

karlb avatar Mar 10 '19 10:03 karlb

@kaizhu256 Thanks! Very much appreciated. I was going down the rabbit hole with sqlite3 and had a similar issue importing that module. This seemed to solve it

simonsankar avatar Mar 18 '19 22:03 simonsankar

Hi all! I wrote a small library to wrap the sql.js in a React[ish] API. It is in the early development, and I wish to humbly ask for a feedback on it. I name it reactive-sql-toolkit, it is already in npm for testing (https://www.npmjs.com/package/reactive-sql-toolkit)

Any feedback would be very much appreciated. Thank you all!

PauloBarbeiro avatar Jun 02 '22 09:06 PauloBarbeiro