简体   繁体   中英

How to use knex.js in browser

I hope you can help me here. I tried to use knex.js ( http://knexjs.org/#Installation-browser ) outside of node for my multiplayer game and I don't understand how to use it on client side. Im really really new to node, webpacker, browserify etc.

Can anyone give me an example? I integrate the file like

 <script src="lib/knex.js"></script>

and wont it to use like this:

 var mysql = Knex({client: 'websql', connection: { host : '127.0.0.1', user : 'root', password : '', database : 'battleground' } });

Console output: Uncaught ReferenceError: Knex is not defined

Sorry for my bad english too!

I Hope for help - Thank you.

Best regards,

Oleg

Remove connection because you can't do connection, only query.

And then you have to use Webpack v4...and do a lot of patch-package work on knex itself to make it compatible for Web, it's no longer compatible out of the box.

Just started playing with knex in the browser. This code will load knex but it won't make a database connection.

<html>
<head>
<script src="lodash.min.js" type="text/javascript"></script>
<script src="bluebird.min.js" type="text/javascript"></script>
<script src="jquery-2.2.1.min.js"></script>
<script src="knex.min.js"></script>

</head>
<body>
<script type=text/javascript>
    $(function(){
        var webSql = Knex({client: 'websql'
        });
        var sql = webSql.select('name').from('client').toString();
        console.log(sql);
    });
</script>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM