Simpler demo

Open
#603 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
48/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
javascript, sqlite
Domain
documentation

Research direction

Open the README and find the current sample demo. Replace or revise it using the simpler JavaScript and SQL.js example in the issue, while retaining the previous-version example if it is useful. Done means the README presents the proposed browser demo accurately and its code is readable and runnable.

Written by the indexing model from the issue text.

Description

The sample demo in the readme seems intimidating...

Here's a simpler one:

<head>
    <title>Demo</title>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.12.0/sql-wasm.js"></script>
    <!-- preload sql-wasm.wasm, if you like -->
</head>

<body>
    <button id='btn'>Run query</button>

    <script type='module'>
        // Initialize SQL.js
        const SQL = await initSqlJs({
            locateFile: () => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.12.0/sql-wasm.wasm`
        })

        // Create a db with sample data
        const db = new SQL.Database()

        db.run(`CREATE TABLE test (id INTEGER, name TEXT); INSERT INTO test VALUES (1, 'Alice'), (2, 'Bob')`)

        // Run a query
        async function run() {
            const result = await db.exec("SELECT * FROM test")
            console.log(result[0].values)
        }

        btn.addEventListener('click', run)
    </script>
</body>

For previous versions:

<head>
    <title>Demo</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/0.5.0/js/sql-optimized.js"></script>
</head>

<body>
    <button id='btn'>Run query</button>

    <script type='module'>
        const db = new SQL.Database()
        db.run(`CREATE TABLE test (id INTEGER, name TEXT); INSERT INTO test VALUES (1, 'Alice'), (2, 'Bob')`)

        async function run() {
            const result = await db.exec("SELECT * FROM test")
            console.log(result[0].values)
        }

        btn.addEventListener('click', run)
    </script>
</body>
Dominant language
JavaScript
Stars
13.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sql-js/sql.js

All issues in sql-js/sql.js

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.