sql-wasm.js 浏览器端数据库 js插件


sql-wasm.js 浏览器端数据库 js插件

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>BFW NEW PAGE</title>
    <script id="bfwone" type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/bfwone.js"></script>
    <script type="text/javascript">
        bready(function() {
            use(["sql-wasm"], function() {


                //Open a blank database
                var db;
                initSqlJs({
                    locateFile: filename => `/bfwrepo/${filename}`
                }).then(function (SQL) {
                    db = new SQL.Database();
                });

                document.getElementById('submit').onclick = function () {
                    var sql = document.getElementById('input').value;
                    var result = '', error = '';
                    try {
                        result = db.exec(sql);
                    }
                    catch (e) {
                        error = e;
                    }
                    document.getElementById('result').innerHTML = JSON.stringify(result, null, '  ');
                    document.getElementById('error').innerHTML = error;
                };

            });
        });
    </script>
</head>
<body>
    <input type='text' id='input' placeholder="ENTER SOME SQL" size='50'
    value="CREATE TABLE test(val);INSERT INTO test VALUES (666); SELECT * FROM test">
    <button id='submit'>Execute</button>
    <pre id='result'></pre>
    <pre id='error'></pre>
</body>
</html>


立即下载sql-wasm.js查看所有js插件

网友评论0

程序员在线工具箱