简体   繁体   中英

How to create an offline MySQL database javascript?

I have created a sample.js file with the following code

var mysql = require('mysql');

Typically, I would connect to my online database using:

var pool = mysql.createPool({
host: 'den1.mysql5.gear.host',
user: 'myst',
password: 'hidden',
database: "myst"
});

and then do

var connection = pool.getConnection(function(err, connection) {
//do whatever like connection.query
});

How can I create a local database file and access that, instead of using server side databases?

Edit: USING ONLY MySQL! If you do not know, please do not answer. I am not looking for an alternative (since most alternatives cause node to delete packages needed by discord.js for some reason).

MySQL is quite heavy to implement database on front end as there is size and speed limitations. I'll prefer using it on back end only but if you want to use database on front-end you can use db.js . There is indexDB presently present in most of the modern browser. The db.js is a wrapper around that consumes it to implement database on front end. Here's sample provided on the documentation .

<script src='/scripts/db.js'></script>

var server;
  db.open( {
      server: 'my-app',
      version: 1,
      schema: {
          people: {
              key: { keyPath: 'id' , autoIncrement: true },
              // Optionally add indexes
              indexes: {
                  firstName: { },
                  answer: { unique: true }
              }
          }
      }
  } ).done( function ( s ) {
      server = s
  } );

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